Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to get the name from a reference

by repellent (Priest)
on Mar 30, 2009 at 17:12 UTC ( [id://754190]=note: print w/replies, xml ) Need Help??


in reply to How to get the name from a reference

As far as I know, we can only do it for CODE references:
# obtain CODEref name use B; sub coderef2name { my ($coderef) = @_; return unless UNIVERSAL::isa($coderef, "CODE"); my $obj = B::svref_2object($coderef); return $obj->GV->STASH->NAME . "::" . $obj->GV->NAME; }

Update: Changed to use GV->STASH->NAME instead.

Note that:
> perl -MDevel::Peek -e '$var = 123; Dump \$var; sub my_sub {}; Dump \ +&my_sub' SV = RV(0x8073260) at 0x804cc28 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x8065648 SV = IV(0x8068920) at 0x8065648 REFCNT = 2 FLAGS = (IOK,pIOK) IV = 123 SV = RV(0x8073260) at 0x804cc28 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x8064b34 SV = PVCV(0x8061538) at 0x8064b34 REFCNT = 2 FLAGS = () IV = 0 NV = 0 COMP_STASH = 0x804cb50 "main" START = 0x806d6a8 ===> 1053 ROOT = 0x806fa68 XSUB = 0x0 XSUBANY = 0 GVGV::GV = 0x8065684 "main" :: "my_sub" FILE = "-e" DEPTH = 0 FLAGS = 0x0 OUTSIDE_SEQ = 91 PADLIST = 0x8064b04 PADNAME = 0x804cce8(0x8088758) PAD = 0x8065678(0x805e5b0) OUTSIDE = 0x804cd78 (MAIN)

Replies are listed 'Best First'.
Re^2: How to get the name from a reference
by chromatic (Archbishop) on Mar 30, 2009 at 17:26 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-19 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found