Change 14488 by jhi@alpha on 2002/01/29 16:38:58
Subject: Re: [PATCH] Attribute::Handlers lexical refcount skew (was Re:
lexical with attribute, refcount high)
From: Richard Clamp <[EMAIL PROTECTED]>
Date: Mon, 28 Jan 2002 02:17:55 +0000
Message-ID: <[EMAIL PROTECTED]>
Affected files ...
.... //depot/perl/lib/Attribute/Handlers.pm#13 edit
.... //depot/perl/lib/Attribute/Handlers/t/multi.t#6 edit
Differences ...
==== //depot/perl/lib/Attribute/Handlers.pm#13 (text) ====
Index: perl/lib/Attribute/Handlers.pm
--- perl/lib/Attribute/Handlers.pm.~1~ Tue Jan 29 09:45:05 2002
+++ perl/lib/Attribute/Handlers.pm Tue Jan 29 09:45:05 2002
@@ -145,11 +145,18 @@
_apply_handler_AH_($decl,$gphase)
if $global_phases{$gphase} <= $global_phase;
}
- # if _gen_handler_AH_ is being called after CHECK it's
- # for a lexical, so we don't want to keep a reference
- # around
- push @declarations, $decl
- if $global_phase == 0;
+ if ($global_phase != 0) {
+ # if _gen_handler_AH_ is being called after
+ # CHECK it's for a lexical, so make sure
+ # it didn't want to run anything later
+
+ local $Carp::CarpLevel = 2;
+ carp "Won't be able to apply END handler"
+ if $phase{$handler}{END};
+ }
+ else {
+ push @declarations, $decl
+ }
}
$_ = undef;
}
@@ -805,6 +812,12 @@
subroutine ceased to exist between the point it was declared and the point
at which its attribute handler(s) would have been called.
+=item C<Won't be able to apply END handler>
+
+You have defined an END handler for an attribute that is being applied
+to a lexical variable. Since the variable may not be available during END
+this won't happen.
+
=back
=head1 AUTHOR
==== //depot/perl/lib/Attribute/Handlers/t/multi.t#6 (text) ====
Index: perl/lib/Attribute/Handlers/t/multi.t
--- perl/lib/Attribute/Handlers/t/multi.t.~1~ Tue Jan 29 09:45:05 2002
+++ perl/lib/Attribute/Handlers/t/multi.t Tue Jan 29 09:45:05 2002
@@ -165,3 +165,11 @@
$applied = 0;
dummy_our(); dummy_our();
ok( $applied == 0, 51 );
+
+sub UNIVERSAL::Stooge :ATTR(END) {};
+eval {
+ local $SIG{__WARN__} = sub { die @_ };
+ my $groucho : Stooge;
+};
+my $match = $@ =~ /^Won't be able to apply END handler/;
+ok( $match, 52 );
End of Patch.