LanX has asked for the wisdom of the Perl Monks concerning the following question:
But with source in multiple files, modules and packages this becomes hairy.
Thats why I extended this example code from Attribute::Handlers to access DATA when CHECKing and print the line of the sub foo1() declaration:
package LoudDecl; use Attribute::Handlers; no warnings; sub Loud :ATTR { my ($package, $symbol, $referent, $attr, $data, $phase, $filename , $linenum) = @_; print STDERR ref($referent), " ", *{$symbol}{NAME}, " ", "($referent) ", "was just declared ", "and ascribed the ${attr} attribute ", "with data ($data)\n", "in phase $phase\n", "in file $filename at line $linenum\n"; my $tell=tell DATA; seek DATA,0,0; while (<DATA>) {print "> $_" if $.==$linenum }; seek DATA,$tell,0; } sub foo1 :Loud {print "HAHA"}; __DATA__ huhu
OUTPUT
CODE foo1 (CODE(0x8eba020)) was just declared and ascribed the Loud a +ttribute with data () in phase CHECK in file /home/lanx/perl/exp/tell.pl at line 23 > sub foo1 :Loud {print "HAHA"}; Can't use an undefined value as an ARRAY reference at /usr/share/perl/ +5.10/Attribute/Handlers.pm line 185, <DATA> line 31. INIT failed--call queue aborted, <DATA> line 31. Can't use an undefined value as an ARRAY reference at /usr/share/perl/ +5.10/Attribute/Handlers.pm line 185, <DATA> line 31. END failed--call queue aborted, <DATA> line 31.
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading sourcecode at parsing/compilation (CHECK) time? ($_)
by tye (Sage) on Apr 04, 2010 at 03:34 UTC | |
by LanX (Saint) on Apr 04, 2010 at 10:51 UTC | |
by LanX (Saint) on Apr 04, 2010 at 13:14 UTC | |
by Anonymous Monk on Apr 05, 2010 at 14:26 UTC | |
by LanX (Saint) on Apr 05, 2010 at 14:48 UTC | |
|
Re: Reading sourcecode at parsing/compilation (CHECK) time?
by LanX (Saint) on Apr 03, 2010 at 14:59 UTC | |
|
Re: Reading sourcecode at parsing/compilation (CHECK) time?
by LanX (Saint) on Apr 04, 2010 at 00:21 UTC |