in reply to Re: Re^2: Lexical pad / attribute confusion
in thread Lexical pad / attribute confusion
They're also declared after INIT, and you can see them from there ;-) Also, moving dump_lex after the declarations like this:
#! /usr/bin/perl use strict; use warnings; package AttrTest; use Data::Dumper; use PadWalker qw(peek_my); sub MODIFY_HASH_ATTRIBUTES { my ($package, $reference, @attributes) = @_; $package->dump_lex("setting @attributes in $package for $reference" +); return; }; INIT { AttrTest->dump_lex('init') }; { package Foo; use base qw(AttrTest); my %foo : Attr = (one => 1); }; { package Bar; use base qw(AttrTest); use attributes (); my %bar; attributes::->import(__PACKAGE__, \%bar, 'Attr'); } AttrTest->dump_lex('runtime'); sub dump_lex { my ($class, $when) = @_; print "when $when top-level pad is\n"; my $level=0; while (eval {peek_my(++$level)} && !$@) {}; my $hash = peek_my($level-1); while (my ($name, $value) = each %$hash) { my $dumped = Data::Dumper->new([\$value],[$name])->Indent(0)->D +ump; print "\t$value -> $dumped\n"; }; print "\n"; };
Still gives you this (under 5.8):
when init top-level pad is HASH(0x22e150) -> $%bar = \{}; HASH(0xb5b50) -> $%foo = \{}; when setting Attr in Foo for HASH(0xb5b50) top-level pad is when setting Attr in Bar for HASH(0x22e150) top-level pad is HASH(0x22e150) -> $%bar = \{}; when runtime top-level pad is
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re^4: Lexical pad / attribute confusion
by shotgunefx (Parson) on Dec 22, 2002 at 01:04 UTC | |
by adrianh (Chancellor) on Dec 22, 2002 at 01:19 UTC | |
by shotgunefx (Parson) on Dec 22, 2002 at 01:44 UTC | |
by adrianh (Chancellor) on Dec 22, 2002 at 11:26 UTC | |
by shotgunefx (Parson) on Dec 22, 2002 at 21:18 UTC |