develooper Front page | perl.perl5.porters | Postings from May 2012

[perl #47027] Documentation: BEGIN, END docs in wrong section

Thread Previous | Thread Next
Father Chrysostomos via RT
May 8, 2012 08:49
[perl #47027] Documentation: BEGIN, END docs in wrong section
Message ID:
On Tue May 08 08:21:21 2012, 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.


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" }

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.


DESTROY { warn "destroy" }
BEGIN { warn "begin 1" }

begin 1 at - line 4.
destroy at - line 3.

> If BEGIN and other named blocks are implemented as subroutines, with
> 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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About