From 383f7c131722213b9c3224313995343bb63313ad Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 18 Jan 2008 15:17:29 +0000 Subject: - modify before_leaving() to be compatible with perl 5.10.0 more precisely, rewrite add_f4before_leaving in a different way so that DESTROY is correctly called when it should --- NEWS | 2 ++ lib/MDK/Common/Func.pm | 20 ++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index 256c739..0fc1591 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +- modify before_leaving() to be compatible with perl 5.10.0 + Version 1.2.9 - 11 September 2007, by Thierry Vignaud - fix including the doc of sub-modules diff --git a/lib/MDK/Common/Func.pm b/lib/MDK/Common/Func.pm index 82811bb..cccaadc 100644 --- a/lib/MDK/Common/Func.pm +++ b/lib/MDK/Common/Func.pm @@ -286,20 +286,16 @@ sub partition(&@) { sub add_f4before_leaving { my ($f, $b, $name) = @_; - unless ($MDK::Common::Func::before_leaving::{$name}) { + $MDK::Common::Func::before_leaving::_list->{$b}{$name} = $f; + if (!$MDK::Common::Func::before_leaving::_added{$name}) { + $MDK::Common::Func::before_leaving::_added{$name} = 1; no strict 'refs'; - ${"MDK::Common::Func::before_leaving::$name"} = 1; - ${"MDK::Common::Func::before_leaving::list"} = 1; + *{"MDK::Common::Func::before_leaving::$name"} = sub { + my $f = $MDK::Common::Func::before_leaving::_list->{$_[0]}{$name} or die ''; + $name eq 'DESTROY' and delete $MDK::Common::Func::before_leaving::_list->{$_[0]}; + &$f; + }; } - local *N = *{$MDK::Common::Func::before_leaving::{$name}}; - my $list = *MDK::Common::Func::before_leaving::list; - $list->{$b}{$name} = $f; - *N = sub { - my $f = $list->{$_[0]}{$name} or die ''; - $name eq 'DESTROY' and delete $list->{$_[0]}; - &$f; - } if !defined &{*N}; - } #- ! the functions are not called in the order wanted, in case of multiple before_leaving :( -- cgit v1.2.1