dhosek has asked for the wisdom of the Perl Monks concerning the following question:

OK, breaking this down to its simplest form, I've found that the following code:
#!/usr/bin/perl package LoudDecl; use Attribute::Handlers; sub Loud :ATTR(ARRAY) { 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 @foo: Loud;
gives me ENTITY LEXICAL rather than foo for the name of the array that I'm applying an attribute to. Is it possible to get the name of the array with an attribute handler in Attribute::Handlers? Am I missing something simple and obvious here? Updated 3/11 Fixed a typo from working late last night.

Replies are listed 'Best First'.
Re: Getting array name with Attribute::Handlers
by Anonymous Monk on Mar 11, 2009 at 08:17 UTC
    #!/usr/bin/perl package LoudDecl; use Attribute::Handlers; sub Loud :ATTR(ARRAY) { my ($package, $symbol, $referent, $attr, $data, $phase, $filename, + $linenum) = @_; warn $symbol, ' = ', *{$symbol}{NAME}; warn join ' | ', @_; } my @foo: Loud; our @FOO: Loud; __END__ GLOB(0x185774c) = FOO at temp.pl line 8. LoudDecl | GLOB(0x185774c) | ARRAY(0x185768c) | Loud | | CHECK at tem +p.pl line 9. LEXICAL = LEXICAL at temp.pl line 8. LoudDecl | LEXICAL | ARRAY(0x182f750) | Loud | | CHECK at temp.pl lin +e 9.
Re: Getting array name with Attribute::Handlers
by Anonymous Monk on Mar 13, 2009 at 11:23 UTC
    since lexicals don't live in the symbol table (%main::), they live in the scratchpad, you could try PadWalker's var_name