Open toddr opened 4 years ago
I've often wanted a LEAVE { ... }
in perl5; perl6raku's version of it looks fine enough. Far less useful to have an ENTER
but for symmetry, why not? I also like the idea that BEGIN
et.al. can yield a value - that would be excellent for those one-time constants and other fun things that turn up.
Another phaser I've always wanted is something like END
but that only runs if its line of code was actually reached at runtime. What I often do in the main foo.pl
script is something like:
my $thing = Some::Thing->new( shift @ARGV ) or die "Can't get a thing";
$thing->start;
END { $thing->stop }
and then inevitably it crashes at runtime if the or die
path is executed, because during that END
block the code is still run even though $thing
was never set. What I wanted was
END { $thing and $thing->stop }
and it starts to get messy. an END-IF-REACHED { ... }
would be nice - though with a better name, obviously :)
Attach blocks to just about anything.