As I understand it the %hash isn't actually in scope when the ATTR handler is called, so there is no way to get at it with PadWalker...
Demonstration.
#! /usr/bin/perl use strict; use warnings; package Foo; use Attribute::Handlers; use PadWalker qw(peek_my); use Data::Dumper; sub Field : ATTR(HASH) { my ($class, $symbol, $hash) = @_; if ($symbol eq 'LEXICAL') { my $level=0; while (eval {peek_my($level+1)} && !$@) {$level++}; print Dumper(peek_my($level)); } else { print "got %", *{$symbol}{NAME}, " from symbol table\n"; }; }; package FooBar; use base qw(Foo); my %just_to_prove_we_are_in_the_right_scope; print "about to call ATTR with \\%foo\n"; my %foo : Field; print "about to call ATTR with \\%bar\n"; my %bar : Field;
produces
about to call ATTR with \%foo $VAR1 = { '%just_to_prove_we_are_in_the_right_scope' => {} }; about to call ATTR with \%bar $VAR1 = { '%just_to_prove_we_are_in_the_right_scope' => {}, '%foo' => {} };
Unless I'm missing something (entirely possible) I don't see how Devel::Caller can help here? There isn't a way that (in the above example) you can get at the name 'foo' at the time the %foo hash reference is passed to the ATTR handler.
In reply to Re^4: Class::InsideOut - yet another riff on inside out objects.
by adrianh
in thread Class::InsideOut - yet another riff on inside out objects.
by adrianh
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |