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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.