It seems I need to explain more about the "why" of what I'm doing. Here's an example:
sub initialize {
return shift->call_super_before(\@_, sub {
my($self) = @_;
$self->die($self->get('values'), undef, 'number of elements mu
+st be even')
unless @{$self->get('values')} % 2 == 0;
return;
});
}
call_super_before uses code_ref_for_subroutine to figure out what the SUPER is from a $proto/$self and caller. I want SUPER to do something (put "values" on $self) and then I'm going to check the result. With call_super_before I don't need to know what SUPER returns or what it takes, it's all transparent to the subclass.
One suggestion was to use ->can, but this doesn't work, because it will return the subclass's method, not SUPER's method.
As to "what global lexicals" disappear, it's all of them as near as I can tell. A global lexical is one which is declared in the package scope so properly "package lexicals disappear". The difficulty is that the lexicals are undefined after they are initialized, that is,
my($_BAR) = 1;
sub foo {
return shift->call_super_before(\@_, sub {
die('gone') unless $_BAR;
return;
});
}
During the first call to foo, $_BAR is false, even though it was initialized to 1.
Here's another tidbit, which is probably related:
package T1;
sub s1 {print("T1:s1\n")}
package T2;
use base T1;
package T3;
use base T2;
sub s1 {shift->SUPER::s1}
package main;
no strict 'refs';
exists($T2::{s1}) && die('not here');
T3->s1;
exists($T2::{s1}) && die('here');
During the search for SUPER methods, $T2::{s1} is created with an empty value for *{$T2::{s1}}{CODE}. It's there, but not there. This is what I mean by semi-autovivification: the typeglob is created, but it doesn't contain anything.
Rob
|