|go ahead... be a heretic|
Lexical pad / attribute confusionby adrianh (Chancellor)
|on Dec 21, 2002 at 22:38 UTC||Need Help??|
adrianh has asked for the
wisdom of the Perl Monks concerning the following question:
Due too some of the discussion on Class::InsideOut I have discovered that I am missing some of the subtleties of perl's lexical pads, and their interaction with package-specific attributes.
Basically, lexical pads don't seem to be as localised as I thought they would be - and attribute subroutines seem to be being called in an odd context.
(Background: I am largely unfamiliar with the perl internals. I've skimmed perlguts and related docs but can't find anything obvious that answers my questions. However, I've worked on compilers for other languages and am familiar with the basic concepts.)
My naive concept of perl's lexical pads that there would be one associated with each lexical scope something like this.
and from my reading of attributes in perl 5.8 doing.
should be the same as
However, some experiments with PadWalker show my understanding is in error:
Under perl 5.6 this produces
Under perl 5.8 this produces
Both examples used the same version of PadWalker (v0.08). I am also aware of the change in 5.8 that means attributes declared with my are now applied at runtime.
This output confuses me for a couple of reasons:
I realise that package-specific attributes are still considered experimental - so I'm not particularly worried about the different behaviour - but I would like to understand what's going on :-)
Can any perl internals guru's explain to this poor confused soul?