package Before; use Acme::Damn; use overload '&{}' => sub { my $f = shift(); my $ref = damn($f); return sub { print "Stuff before\n"; my @rv = $ref->(@_); bless($ref, __PACKAGE__); return @rv; }; }; 1;
Acme::Damn is one of the very few Acme modules that I would consider using in real life. I use it here to temporarily unbless the object, then de-ref and call, and then re-bless it. It's not quite the same as your code though - because I call the subroutine instead of using goto, there's an extra stack frame and so if you use caller() inside it it will behave differently.$ perl -MBefore -e 'my $foo = bless(sub { print shift()."\n" } => 'Bef +ore'); $foo->("foo"); $foo->("bar")' Stuff before foo Stuff before bar
In reply to Re: Overloading without infinite descent
by DrHyde
in thread Overloading without infinite descent (fixed by time: see Perl 5.10.1)
by JadeNB
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |