John Porter writes:
> > If you wanted to make that parsable, pretend that BEGIN and END are
> > the names of functions with prototype (&) which register callbacks.
>
> I agree ... except that, in perl5 at least, you'd need a terminating
> semicolon if that analogy were 100% accurate.
I realized that after I sent it :)
I'm chewing over an RFC on giving you more control over the
compile-time and run-time nature of functions. One possibility is to
define an attribute for subroutines that means they're BEGIN-like:
sub CLEANUP :immediate :blockish (&) {
push(@cleanup_handlers, @_);
}
END {
print "Starting cleanup\n";
foreach (@cleanup_handlers) {
&$;
}
}
CLEANUP { unlink $tempfile }
CLEANUP { close SOCKET }
C<cleanup> would:
- be called at compile-time (:immediate)
- not need a semicolon (:blockish)
I'm just not sure whether this is an itch that needs to be scratched.
Nat