in reply to Re: Is there a way to access the name under which a subroutine was first defined?
in thread Is there a way to access the name under which a subroutine was first defined?
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".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Is there a way to access the name under which a subroutine was first defined?
by shmem (Chancellor) on Feb 16, 2009 at 10:56 UTC | |
by ELISHEVA (Prior) on Feb 16, 2009 at 11:13 UTC | |
by shmem (Chancellor) on Feb 16, 2009 at 13:31 UTC | |
by ELISHEVA (Prior) on Feb 16, 2009 at 14:20 UTC |