As 5.002 has SUPER:: in it I started looking at using it in Tk.
I have discovered that it does not work as I expected.
If you inherit from a class which has used $obj->SUPER::method somewhere
things get out of hand.
Sorry :-(
The degenerate case $class->SUPER::method is using
the 'object' class as the place to SUPER from rather than the
calling package.
Thus this script recurses infinitely.
#!/usr/local/bin/perl -w
package base;
sub amethod
{
print "base::amethod(",join(',',@_),")\n";
}
package derived;
@ISA = 'base';
sub amethod
{
print "derived::amethod(",join(',',@_),")\n";
shift->SUPER::amethod;
}
package moreso;
@ISA = 'derived';
package main;
moreso->amethod;
__END__
My patch to gv.c (and hence 5.002) has :
if (strEQ(origname,"SUPER")) {
/* Degenerate case ->SUPER::method should really lookup in original stash */
SV *tmpstr = sv_2mortal(newSVpv(HvNAME(stash),0));
^^^^^^^^^^^^^
sv_catpvn(tmpstr, "::SUPER", 7);
stash = gv_stashpv(SvPV(tmpstr,na),TRUE);
*nsplit = ch;
DEBUG_o( deb("Treating %s as %s::%s\n",origname,HvNAME(stash),name) );
I think 1st HvNAME(stash) should really be caller's package name,
but I don't know how to get that from C (yet) ...
I have discovered that it does not work as I expected.
If you inherit from a class which has used $obj->SUPER::method somewhere
things get out of hand.
Sorry :-(
The degenerate case $class->SUPER::method is using
the 'object' class as the place to SUPER from rather than the
calling package.
Thus this script recurses infinitely.
#!/usr/local/bin/perl -w
package base;
sub amethod
{
print "base::amethod(",join(',',@_),")\n";
}
package derived;
@ISA = 'base';
sub amethod
{
print "derived::amethod(",join(',',@_),")\n";
shift->SUPER::amethod;
}
package moreso;
@ISA = 'derived';
package main;
moreso->amethod;
__END__
My patch to gv.c (and hence 5.002) has :
if (strEQ(origname,"SUPER")) {
/* Degenerate case ->SUPER::method should really lookup in original stash */
SV *tmpstr = sv_2mortal(newSVpv(HvNAME(stash),0));
^^^^^^^^^^^^^
sv_catpvn(tmpstr, "::SUPER", 7);
stash = gv_stashpv(SvPV(tmpstr,na),TRUE);
*nsplit = ch;
DEBUG_o( deb("Treating %s as %s::%s\n",origname,HvNAME(stash),name) );
I think 1st HvNAME(stash) should really be caller's package name,
but I don't know how to get that from C (yet) ...