Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

By "initially" I meant the name "foo" assigned by sub foo {...} rather than any aliases assigned at a later point.

But as you point out, it definitely does seems to be a "when" issue. My new toy Devel::Peek::Dump(...) also reports the subroutine name correctly if it is called after the sub is compiled, but not when the subroutine's attributes are being processed via MODIFY_CODE_ATTRIBUTES (during the compilation of the subroutine definition).

This is illustrated by the following small script:

use strict; use warnings; use Devel::Peek(); sub MODIFY_CODE_ATTRIBUTES { my $sPackage = shift @_; my $crSub = shift @_; print STDERR "Dumping $crSub in MODIFY_CODE_ATTRIBUTES:\n"; Devel::Peek::Dump($crSub); return (); } BEGIN { sub bar : Lion { print "pling.\n"; } print STDERR "\nDumping " . \&bar . " after compilation.\n"; Devel::Peek::Dump(\&bar); }

which reports GVGV:GV = 0x0 when called within the MODIFY_CODE_ATTRIBUTES method but GVGV::GV = 0x819ba28    "main" :: "bar" when called after bar(...) is compiled, as the captured output below shows:

Dumping CODE(0x818a994) in MODIFY_CODE_ATTRIBUTES: SV = RV(0x819e958) at 0x8197600 REFCNT = 1 FLAGS = (PADBUSY,PADMY,ROK) RV = 0x818a994 SV = PVCV(0x818ddb8) at 0x818a994 REFCNT = 5 FLAGS = () IV = 0 NV = 0 COMP_STASH = 0x0 ROOT = 0x0 XSUB = 0x0 XSUBANY = 0 GVGV::GV = 0x0 FILE = "(null)" DEPTH = 0 FLAGS = 0x0 OUTSIDE_SEQ = 208 PADLIST = 0x818a97c PADNAME = 0x8184450(0x0) PAD = 0x818aa00(0x81a5830) OUTSIDE = 0x8183288 (UNIQUE) Dumping CODE(0x818a994) after compilation. SV = RV(0x819e940) at 0x819bb48 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x818a994 SV = PVCV(0x818ddb8) at 0x818a994 REFCNT = 2 FLAGS = () IV = 0 NV = 0 COMP_STASH = 0x814eb50 "main" START = 0x816e678 ===> 2993 ROOT = 0x81afbc0 XSUB = 0x0 XSUBANY = 0 GVGV::GV = 0x818ab44 "main" :: "bar" FILE = "Monks/Snippet.pm" DEPTH = 0 FLAGS = 0x0 OUTSIDE_SEQ = 208 PADLIST = 0x818a97c PADNAME = 0x8184450(0x819caf8) PAD = 0x818aa00(0x81a5830) OUTSIDE = 0x8183288 (UNIQUE)

Best, beth

Update: replaced original example with script illustrating different outputs from within MODIFY_CODE_ATTRIBUTES and after compilation; added explanation of what I meant by "initially".


In reply to Re^2: Is there a way to access the name under which a subroutine was first defined? by ELISHEVA
in thread Is there a way to access the name under which a subroutine was first defined? by ELISHEVA

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found