QM has asked for the wisdom of the Perl Monks concerning the following question:
I've tried the local *__ANON__ = "name"; solution, but it doesn't affect svref_2object. Below is the outline of the code I want to use this in.
use B qw(svref_2object); use Foo::Bar; my $self = Foo::Bar->new; # wrap a method call in a sub my $anon = sub { $self->mumble("blah\n") }; # pass the coderef to $self->grumble($anon, qw(one two three)); # ...meanwhile in Foo::Bar... sub grumble { my $self = shift; my $anon = shift; my @args = @_; # Get the name of the sub my $anon_cv = svref_2object ( $anon ); my $anon_gv = $anon_cv->GV; my $anon_name = $anon_gv->NAME; print "About to call $anon_name...\n"; $anon->(@args); }
Update: Added a catch for $self at the beginning of grumble.
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Naming an anonymous sub for svref_2object
by rjt (Curate) on Aug 06, 2013 at 16:27 UTC | |
by QM (Parson) on Aug 07, 2013 at 10:02 UTC | |
|
Re: Naming an anonymous sub for svref_2object
by kbrannen (Beadle) on Aug 06, 2013 at 20:56 UTC | |
by QM (Parson) on Aug 07, 2013 at 10:09 UTC |