summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2008-01-18 15:17:29 +0000
committerPascal Rigaux <pixel@mandriva.com>2008-01-18 15:17:29 +0000
commit383f7c131722213b9c3224313995343bb63313ad (patch)
tree49f8ea55e7dcc9d0ae228ef14f01bb5b69ba20ef
parent6a88a12be1cc446745577716f9cfedcfebd15e43 (diff)
downloadperl-MDK-Common-383f7c131722213b9c3224313995343bb63313ad.tar
perl-MDK-Common-383f7c131722213b9c3224313995343bb63313ad.tar.gz
perl-MDK-Common-383f7c131722213b9c3224313995343bb63313ad.tar.bz2
perl-MDK-Common-383f7c131722213b9c3224313995343bb63313ad.tar.xz
perl-MDK-Common-383f7c131722213b9c3224313995343bb63313ad.zip
- 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
-rw-r--r--NEWS2
-rw-r--r--lib/MDK/Common/Func.pm20
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 :(