On Tue May 08 08:21:21 2012, dcmertens.perl@gmail.com wrote:
> I can have arbitrarily many BEGIN blocks in the same package, and they are
> called in the order that they are declared. I can only have one DESTROY
> subroutine in a given package, and only the last executed definition is
> used when I call it.
#!perl
use 5.15.9;
sub MODIFY_CODE_ATTRIBUTES { $_[1](); undef *DESTROY; () }
warn "run time";
sub DESTROY :foo { warn "hello" }
sub DESTROY :bar { warn "good bye" }
sub DESTROY :baz { warn "hello again" }
__END__
hello at - line 9.
good bye at - line 10.
hello again at - line 11.
run time at - line 7.
> This makes named blocks just that: blocks, not
> subroutines.
They might be special, but they are still subroutines. You can goto&
out of them. You can return from them.
#!perl
DESTROY { warn "destroy" }
BEGIN { warn "begin 1" }
BEGIN { goto &DESTROY }
__END__
begin 1 at - line 4.
destroy at - line 3.
>
> If BEGIN and other named blocks are implemented as subroutines, with
sundry
> ramifications on @_ and other things (caller?), that is an implementation
> detail, or even an implementation wart. These warts (if so deemed) should
> definitely be made clear in the docs, or done away with if possible.
>
> FWIW, I have round tuits, maybe even enough to write docs for said wart,
> but not nearly enough to modify Perl's handling of these blocks.
I don’t consider them warts, but I wouldn’t mind better documentation,
including the fact that DESTROY and AUTOLOAD are also special, in that
‘sub’ can be omitted.
--
Father Chrysostomos
---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47027
Thread Previous
|
Thread Next