in reply to Re^3: Class::InsideOut - yet another riff on inside out objects.
in thread Class::InsideOut - yet another riff on inside out objects.
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Class::InsideOut - yet another riff on inside out objects.
by Aristotle (Chancellor) on Dec 19, 2002 at 14:16 UTC | |
by adrianh (Chancellor) on Dec 19, 2002 at 17:11 UTC | |
by adrianh (Chancellor) on Dec 19, 2002 at 14:33 UTC | |
by Aristotle (Chancellor) on Dec 19, 2002 at 14:53 UTC | |
Re^5: Class::InsideOut - yet another riff on inside out objects.
by diotalevi (Canon) on Dec 19, 2002 at 12:28 UTC | |
by adrianh (Chancellor) on Dec 19, 2002 at 13:07 UTC | |
by diotalevi (Canon) on Dec 19, 2002 at 13:15 UTC | |
by adrianh (Chancellor) on Dec 19, 2002 at 13:30 UTC |