Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Using caller to determine the namespace of an anonymous subroutine

by stvn (Monsignor)
on Feb 24, 2006 at 18:41 UTC ( [id://532618]=note: print w/replies, xml ) Need Help??


in reply to Using caller to determine the namespace of an anonymous subroutine

As an alternate to what chromatic said, I have found the Sub::Name module to be very helpful in these kinds of situations (I used it in my module Class::MOP, whenever I am adding a method to a class). Again, it needs to be within the code for Creator::create, but IMO it is much less "magical".

my $full_name = $caller."::".$field; *{$fullname} = Sub::Name::subname $full_name => sub { ... }
After this, not only will the sub show up correctly in the output of caller(), but is also shows up correctly when you poke at it with any of the B modules too. This is because Sub::Name will actually set the STASH and NAME attributes for the CV itself using XS.

-stvn

Replies are listed 'Best First'.
Re^2: Using caller to determine the namespace of an anonymous subroutine
by rrwo (Friar) on Feb 26, 2006 at 12:08 UTC

    Sub::Name might be a better solution, since I don't need access to the innards of the coderef. Though I'm not sure I'd call it less magical, since I still need to assign the subroutine name to the coderef.

    Thanks again!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://532618]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2025-06-19 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.