Mailing List Archive

super2 package
This is the Larry's original super without the DB package.

I've added podified documentation. It should go into the
module list as

super2 RupO Call method specifically in any superclass

Should it be included in the standard distribution for 5.002?

package super2;
sub AUTOLOAD {
shift;
my $pkg = caller;
my $meth = $AUTOLOAD;
$meth =~ s/^super2/$pkg/;
local *$meth;
shift->$meth(@_);
}

1;
__END__

=head1 NAME

super2 - call a method in one of the superclasses of the current package

=head1 SYNOPSIS

Usage:

require super2;
sub a_meth {
my($self,@args) = @_;
...
super2->a_meth($self,@args);
...
super2->another_meth($self,@args);
...
}


=head1 DESCRIPTION

This module allows you to call a method so that the lookup for
the method starts at the current class's superclass.

Specifically, if you define a method (call it METH) in package FOO,
and within METH call 'super2->a_method($obj,@some_args)' then this
is translated into the call '$obj->FOO::a_method(@some_args)'
where 'a_method' is looked for in the superclasses of package FOO,
and _not_ in the package FOO. Note that $obj can be an object of
a subclass of FOO - the lookup is still done from the superclasses of
FOO, not the superclasses of $obj. If $obj is an object
which is not of type FOO or a subclass of FOO, the call will
probably fail - this is an undefined way of using super2.

Contrast this with 'super' which is the 'correct' way to
do super (that is it more closely matches the way other languages
do super). super2 requires the object to be passed as the first
argument to the super call. It is however slightly more efficient
than super, which is why its here.

=head1 POSSIBLE MISUSES

The super2 call needs to have the arguments passes explicitly,
i.e. 'super2->meth' is not the same as 'super2->meth(@_)' -
the former call gets no arguments passed to 'a_meth'.

See also L<"super">.

=head1 EXAMPLE

Call this with C<"perl -x super2.pm">

#!perl

#Example of using 'super2'.
require super2;

package A;
sub dib {print "Hello from 'dib' in package A: @_\n"}
package B;
sub dob {print "Hello from 'dob' in package B: @_\n"}
package C;
@ISA = B;
sub dob {
my($self,@args) = @_;
print "Hello from 'dob' in package C: $self @args\n";
super2->dob($self,@args); # super of this method
# super2->dib($self,@args) # Would produce an error
}
package D;
@ISA = qw(A C);
sub dib {print "Hello from 'dib' in package D: @_\n"}
sub dob {
my($self,@args) = @_;
print "Hello from 'dob' in package D: $self @args\n";
super2->dob($self,@args); # super of this method
$self->dib(@args);
super2->dib($self,@args); # super of another method

# super2->non_existent(@_); # Would produce an error
}

package E;
@ISA = D;

D->dob(25,'arg2');
E->dob(25,'arg2');
__END__

Which should produce the output

Hello from 'dob' in package D: D 25 arg2
Hello from 'dob' in package C: D 25 arg2
Hello from 'dob' in package B: D 25 arg2
Hello from 'dib' in package D: D 25 arg2
Hello from 'dib' in package A: D 25 arg2
Hello from 'dob' in package D: E 25 arg2
Hello from 'dob' in package C: E 25 arg2
Hello from 'dob' in package B: E 25 arg2
Hello from 'dib' in package D: E 25 arg2
Hello from 'dib' in package A: E 25 arg2


-- Jack Shirazi, JackS@slc.com
Re: super2 package [ In reply to ]
> From: Jack Shirazi <JackS@slc.com>
>
> This is the Larry's original super without the DB package.
>
> I've added podified documentation. It should go into the
> module list as
>
> super2 RupO Call method specifically in any superclass
>
> Should it be included in the standard distribution for 5.002?

Perhaps, but with a better name please!

Was there a problem with using the DB package trick? Efficiency?

Speaking of which has anyone measured the cost of doing a
AUTOLOAD + caller + s/// + local(*glob) per method call?

> package super2;
> sub AUTOLOAD {
> shift;
> my $pkg = caller;
> my $meth = $AUTOLOAD;
> $meth =~ s/^super2/$pkg/;
> local *$meth;
> shift->$meth(@_);
> }

Serious question: Has anyone pondered the effect of

local *$meth

if the following

shift->$meth(@_);

ends up running code that wants to call the original method?

It seems to me that while the super2->foo call is still
executing then the original foo has vanished and can't be called.

If that's true then this whole approach is broken. Cute, but broken.

Tim.
Re: super2 package [ In reply to ]
On Tue, 24 Oct 1995 18:10:39 -0000, Jack Shirazi wrote:
>This is the Larry's original super without the DB package.
>
>I've added podified documentation. It should go into the
>module list as
>
>super2 RupO Call method specifically in any superclass
>
>Should it be included in the standard distribution for 5.002?
>

Two suggestions:

* Change name of package to Super because 'super' now produces a
'Unquoted string "super" may clash..' warning with -w.

* I don't like 'super2' for a name. Why not combine super and super2?
Using aliases works very well. Modified Super.pm attached (minus
the pod). You will have to use 'use' instead of 'require' though,
because it relies on import().

The technique by which super works and the possibility of aliasing
packages merits documenting in perlmod(1) or somewhere.

>
>-- Jack Shirazi, JackS@slc.com
>

- Sarathy.
gsar@engin.umich.edu
-----------------------------------8<--------------------------------
package Super::slow;

sub AUTOLOAD {
shift;
package DB;
my(@ret) = caller(1);
package Super::slow;
my $pkg = caller;
my $meth = $AUTOLOAD;
$meth =~ s/^Super::slow/$pkg/;
local *$meth;
$DB::args[0]->$meth(@_);
}

package Super::fast;

sub AUTOLOAD {
shift;
my $pkg = caller;
my $meth = $AUTOLOAD;
$meth =~ s/^Super::fast/$pkg/;
local *$meth;
shift->$meth(@_);
}

package Super;

sub import {
shift;
(@_ and $_[0] eq 'fast') ?
(*Super:: = *Super::fast::) :
(*Super:: = *Super::slow::) ;
}

1;
__END__
#################### usage example 1: Default Super (but slower)

use Super;

package A;
sub dib {print "Hello from 'dib' in package A: @_\n"}
package B;
sub dob {print "Hello from 'dob' in package B: @_\n"}
package C;
@ISA = B;
sub dob {
my $self = shift;
print "Hello from 'dob' in package C: $self @_\n";
Super->dob(@_); # super of this method
# Super->dib(@_) # Would produce an error
}
package D;
@ISA = qw(A C);
sub dib {print "Hello from 'dib' in package D: @_\n"}
sub dob {
my $self = shift;
print "Hello from 'dob' in package D: $self @_\n";
Super->dob(@_); # super of this method
$self->dib(@_);
Super->dib(@_); # super of another method

# Super->non_existent(@_); # Would produce an error
}

package E;
@ISA = D;

D->dob(25,'arg2');
E->dob(25,'arg2');

#################### usage example 2: Fast Super (but more work)
use Super 'fast'; # note this

package A;
sub dib {print "Hello from 'dib' in package A: @_\n"}
package B;
sub dob {print "Hello from 'dob' in package B: @_\n"}
package C;
@ISA = B;
sub dob {
my($self,@args) = @_;
print "Hello from 'dob' in package C: $self @args\n";
Super->dob($self,@args); # super of this method
# Super->dib($self,@args) # Would produce an error
}
package D;
@ISA = qw(A C);
sub dib {print "Hello from 'dib' in package D: @_\n"}
sub dob {
my($self,@args) = @_;
print "Hello from 'dob' in package D: $self @args\n";
Super->dob($self,@args); # super of this method
$self->dib(@args);
Super->dib($self,@args); # super of another method
# Super->non_existent(@_); # Would produce an error
}

package E;
@ISA = D;

D->dob(25,'arg2');
E->dob(25,'arg2');
Re: super2 package [ In reply to ]
I've not seen this come back so I'm reposting it.
Re: super2 package [ In reply to ]
In <9510261927.AA21519@toad>
On Thu, 26 Oct 1995 20:27:12 +0000
Tim Bunce <Tim.Bunce@ig.co.uk> writes:
>I've not seen this come back so I'm reposting it.
>
>Speaking of which has anyone measured the cost of doing a
>AUTOLOAD + caller + s/// + local(*glob) per method call?

No, but AUTOLOAD can be expensive I agree. That is one reason
I use $widget->Inherit(...) in Tk, the other is AUTOLOAD is
already heavily abused in Tk, and potentially one of the things
I want to Inherit (aka super) is AUTOLOAD...
>
>SERIOUS QUESTION: Has anyone pondered the effect of
>
> local *$meth
>
>if the following
>
> shift->$meth(@_);
>
>ends up running code that wants to call the original method?
>
>It seems to me that while the super2->foo call is still
>executing then the original foo has vanished and can't be called.
>
>If that's true then this whole approach is broken. Cute, but broken.
>

Possibly true, bother, I really disliked all the @.*::Inherit mess.
Re: super2 package [ In reply to ]
: Perhaps you reclaim the @.*::Inherit::ISA by localizing *that*:

Before you get too carried away with UNIVERSAL::Inherit, note that
every time you create or modify an @ISA, you invalidate every class's
method cache. You want to set up the @ISA once and then leave it there.

The more we fiddle with this, the more I'm inclined to implement it as
a builtin of some sort. Syntactic options include:

$self-->method
$self->>method
$self->->method
$self-->>method
$self-------->>method :-)
$self->::method
$self->*::method
$self->BASE::method
$self->SUPER::method

The last two might have the advantage of working as

BASE::method $self
SUPER::method $self

This might actually be implemented much like your UNIVERSAL::Inherit,
because this gives the advantage of creating a package for caching the
super method. It should probably just set the super's @ISA alias up on
first reference and leave it there. You can probably do all that with a
UNIVERSAL::Inherit, but you can't unfortunately avoid the double method
lookup with a user code implementation. A builtin can directly translate
SUPER::method to My::Class::SUPER::method, and then take appropriate
initialization action if the first class lookup fails.

We probably also want to make $self->That::Other::Class::SUPER::method()
work right too. Anybody in a mood for hacking C code?

Larry
Re: super2 package [ In reply to ]
: In <9510271715.AA14205@scalpel.netlabs.com>
: On Fri, 27 Oct 95 10:15:10 -0700
: Larry Wall <lwall@scalpel.netlabs.com> writes:
: >: Perhaps you reclaim the @.*::Inherit::ISA by localizing *that*:
: >
: >Before you get too carried away with UNIVERSAL::Inherit, note that
: >every time you create or modify an @ISA, you invalidate every class's
: >method cache. You want to set up the @ISA once and then leave it there.
:
: i.e. the 1st alternative in my last mail, and they way it is (by luck)
: in Tk-b8.
:
: I assume though that to set it up
:
: *{$class::Inherit::ISA} = \@{$class::ISA};
:
: is "better" than a copy?

I would think so. It not only saves storage, but it also lets the super's
@ISA automatically reflect any changes to the sub's @ISA.

: > $self->BASE::method
: > $self->SUPER::method
: >
: >The last two might have the advantage of working as
: >
: > BASE::method $self
: > SUPER::method $self
: >
: >This might actually be implemented much like your UNIVERSAL::Inherit,
: >because this gives the advantage of creating a package for caching the
: >super method. It should probably just set the super's @ISA alias up on
: >first reference and leave it there. You can probably do all that with a
: >UNIVERSAL::Inherit, but you can't unfortunately avoid the double method
: >lookup with a user code implementation. A builtin can directly translate
: >SUPER::method to My::Class::SUPER::method, and then take appropriate
: >initialization action if the first class lookup fails.
:
: Presumably as a builtin it can avoid invalidating caches?

Aliasing doesn't invalidate the cache, as far as I can tell. An assignment
would, though.

: >We probably also want to make $self->That::Other::Class::SUPER::method()
: >work right too.
:
: Or should that be :
:
: $self->SUPER::That::Other::Class::method()

I don't think so. That::Other::Class::SUPER will probably be an actual
class after the first call, and if we don't look for failure beforehand,
we might not have to do anything special on the second call. That
probably means that no one should define a class named SUPER though,
or SUPER::method will never get translated to My::Class::SUPER::method.

: >Anybody in a mood for hacking C code?
: >
: If you point me at right file, I will at least see if I understand it
: enough to try.

pp_method() is in pp_hot.c and gv_fetchmethod() is in gv.c. The code that
implements ClassToStartLooking::method is in gv_fetchmethod(), so that's
probably where the change goes.

Larry
Re: super2 package [ In reply to ]
: In <9510271715.AA14205@scalpel.netlabs.com>
: On Fri, 27 Oct 95 10:15:10 -0700
: Larry Wall <lwall@scalpel.netlabs.com> writes:

: >Anybody in a mood for hacking C code?
: >
: If you point me at right file, I will at least see if I understand it
: enough to try.

pp_method() is in pp_hot.c and gv_fetchmethod() is in gv.c. The code that
implements ClassToStartLooking::method is in gv_fetchmethod(), so that's
probably where the change goes.

What is C code for :

*stash::ISA = \@othestash::ISA;

Ih have the HV*'s for the two stashes, and can lookup "ISA" in RHS
stash, and get GvAV.

Presumably there is more too it than an hv_store() in the LHS
stash?
Re: super2 package [ In reply to ]
> Was there a problem with using the DB package trick? Efficiency?

This was the idea. But ...

> Speaking of which has anyone measured the cost of doing a
> AUTOLOAD + caller + s/// + local(*glob) per method call?

the whole overhead is so much that I no longer see the point in having
super2. super should suffice. However, I don't see the general
overhead mattering - this is for convenience, not performance.

I started the 'super' thread by saying that super doesn't fit into
a multiple inheritance environment, and that you should
be specifying the hierarchy lookup. So I only see super
as an added little thing for Smalltalk/Objective-C
programmers to be comfortable. I don't recommend its use
even if it were performant and bugless - with MI, the
$self->superclass2::meth call should really be used.

> SERIOUS QUESTION: Has anyone pondered the effect of
>
> local *$meth
>
> if the following
>
> shift->$meth(@_);
>
> ends up running code that wants to call the original method?
>
> It seems to me that while the super2->foo call is still
> executing then the original foo has vanished and can't be called.
>
> If that's true then this whole approach is broken. Cute, but broken.

You are correct. I can't see how to fix it, unless there is
some way of making the scope act like a 'my'. Two alterntives come
to mind: firstly, document this as a known bug, and rely on the
likelihood that 95% of code is not recursive; or use my original
super which doesn't suffer this problem, but does explicit
hierarchy lookups and possibly hits Autoloads early. I could
modify that lookup to do a method search of the hierarchy first
so that if the method is defined it would be found, and if
not, then try the per-superclass hierarchy lookup - which would
be a bit less likely to hit Autoloads early.

-- Jack Shirazi, JackS@slc.com
Re: super2 package [ In reply to ]
In <9510271317.AA01618@maildrop.exnet.com>
On Fri, 27 Oct 95 14:17:38 BST
Jack Shirazi <JackS@slc.com> writes:
>
>I started the 'super' thread by saying that super doesn't fit into
>a multiple inheritance environment, and that you should
>be specifying the hierarchy lookup. So I only see super
>as an added little thing for Smalltalk/Objective-C
>programmers to be comfortable. I don't recommend its use
>even if it were performant and bugless - with MI, the
>$self->superclass2::meth call should really be used.
>

Tk uses 'Inherit' (my name for 'super') so that derived classes can do
whatever their super class would have done as well as adding their own
functionality. It is mainly at initialization time.
The problem with $self->superclass::meth is that you have to go
and change them all if you change the inheritance. As Tk has been
evolving this has happened rather a lot. Typicaly I have discovered
that several classes are doing same overrides, so I create a new
intermediate level class and then inherit from that. Thus at one
point lots of $self->Tk::Widget::meth became $self->Tk::Composite::meth
then they became $self->Tk::Frame::meth.


>> If that's true then this whole approach is broken. Cute, but broken.
>
>You are correct. I can't see how to fix it, unless there is
>some way of making the scope act like a 'my'. Two alterntives come
>to mind: firstly, document this as a known bug, and rely on the
>likelihood that 95% of code is not recursive; or use my original
>super which doesn't suffer this problem, but does explicit
>hierarchy lookups and possibly hits Autoloads early.

Before I changed it to use the local trick (I guess I *may* have to go
back) Tk's scheme was:

sub Inherit
{
my $self = shift;
my $method = shift;
my $what = (caller(1))[3];
my ($class) = $what =~ /^(.*)::[^:]+$/;
unless (defined @{$class.'::Inherit::ISA'})
{
@{$class.'::Inherit::ISA'} = @{$class.'::ISA'};
}
$class .= '::Inherit::';
$class .= $method;
return $self->$class(@_);
}

As I have said before this is typically called:

sub Whatever
{
my $self = shift;
...
$self->Inherit('Whatever',@_);
...
}

Above is an automation of the 'trick' in perlbot. I believe
the same idea - building an @ISA for an ::Inherit 'pseudo-class'
should work for your 'super' calling sequence as well.
Like the local *{$meth} scheme, it avoids explicit searching of @ISA yourself,
and I believe it avoids the early Autoload issue as well.

Perhaps you reclaim the @.*::Inherit::ISA by localizing *that*:

sub UNIVERSAL::Inherit
{
my $self = shift;
my $method = shift;
my $what = (caller(1))[3];
my ($class) = $what =~ /^(.*)::[^:]+$/;
local @{$class.'::Inherit::ISA'} = @{$class.'::ISA'};
$class .= '::Inherit::';
$class .= $method;
$self->$class(@_);
}

Perhaps even (with globs on the brain):

*{$class.'::Inherit::ISA'} = \@{$class.'::ISA'};

And avoid replicating/copying it!

>I could
>modify that lookup to do a method search of the hierarchy first
>so that if the method is defined it would be found, and if
>not, then try the per-superclass hierarchy lookup - which would
>be a bit less likely to hit Autoloads early.

Footnote - if we are going to create a 'Super' package
and use AUTOLOAD anyway why not use calling sequence:

$object->Super::method(@args);
Re: super2 package [ In reply to ]
In <9510271715.AA14205@scalpel.netlabs.com>
On Fri, 27 Oct 95 10:15:10 -0700
Larry Wall <lwall@scalpel.netlabs.com> writes:
>: Perhaps you reclaim the @.*::Inherit::ISA by localizing *that*:
>
>Before you get too carried away with UNIVERSAL::Inherit, note that
>every time you create or modify an @ISA, you invalidate every class's
>method cache. You want to set up the @ISA once and then leave it there.

i.e. the 1st alternative in my last mail, and they way it is (by luck)
in Tk-b8.

I assume though that to set it up

*{$class::Inherit::ISA} = \@{$class::ISA};

is "better" than a copy?

> $self->BASE::method
> $self->SUPER::method
>
>The last two might have the advantage of working as
>
> BASE::method $self
> SUPER::method $self
>
>This might actually be implemented much like your UNIVERSAL::Inherit,
>because this gives the advantage of creating a package for caching the
>super method. It should probably just set the super's @ISA alias up on
>first reference and leave it there. You can probably do all that with a
>UNIVERSAL::Inherit, but you can't unfortunately avoid the double method
>lookup with a user code implementation. A builtin can directly translate
>SUPER::method to My::Class::SUPER::method, and then take appropriate
>initialization action if the first class lookup fails.

Presumably as a builtin it can avoid invalidating caches?

>
>We probably also want to make $self->That::Other::Class::SUPER::method()
>work right too.

Or should that be :

$self->SUPER::That::Other::Class::method()

>Anybody in a mood for hacking C code?
>
If you point me at right file, I will at least see if I understand it
enough to try.
Re: super2 package [ In reply to ]
Quoting Larry Wall:
:Before you get too carried away with UNIVERSAL::Inherit, note that
:every time you create or modify an @ISA, you invalidate every class's
:method cache. You want to set up the @ISA once and then leave it there.

Let me reiterate my old wish: please interpolate @ISA constant assignments
at parsing time. I have a real need for:

BEGIN { @ISA = qw(...); };

in my code, and having that automatically done if the assigned object is
a constant (which it is 99% of the time) would be a great improvement.

It allows class implementation code to be anywhere in the script, instead
of having it precede the class client code as we have to do now, unless
we resort to the disgusting BEGIN {} hack.

Please!

Raphael
Re: super2 package [ In reply to ]
That's SUPER. :-)

Larry
Re: super2 package [ In reply to ]
> From: Raphael Manfredi <ram@hptnos02.grenoble.hp.com>
>
> Quoting Larry Wall:
> :Before you get too carried away with UNIVERSAL::Inherit, note that
> :every time you create or modify an @ISA, you invalidate every class's
> :method cache. You want to set up the @ISA once and then leave it there.
>
> Let me reiterate my old wish: please interpolate @ISA constant assignments
> at parsing time. I have a real need for:
>
> BEGIN { @ISA = qw(...); };
>
> in my code, and having that automatically done if the assigned object is
> a constant (which it is 99% of the time) would be a great improvement.
>
> It allows class implementation code to be anywhere in the script, instead
> of having it precede the class client code as we have to do now, unless
> we resort to the disgusting BEGIN {} hack.
>
> Please!

Umm,

use ISA qw(...);

use from qw(...);

use parents qw(...);

Just a thought.

Tim.
Re: super2 package [ In reply to ]
In <9510271920.AA15346@scalpel.netlabs.com>
On Fri, 27 Oct 95 12:20:45 -0700
Larry Wall <lwall@scalpel.netlabs.com> writes:
>: In <9510271715.AA14205@scalpel.netlabs.com>
>: On Fri, 27 Oct 95 10:15:10 -0700
>: Larry Wall <lwall@scalpel.netlabs.com> writes:
>
>: >Anybody in a mood for hacking C code?
>: >
>: If you point me at right file, I will at least see if I understand it
>: enough to try.
>
>pp_method() is in pp_hot.c and gv_fetchmethod() is in gv.c. The code that
>implements ClassToStartLooking::method is in gv_fetchmethod(), so that's
>probably where the change goes.
>
With this trivial example:
package base;

sub whatever
{
print "base(",join(',',@_),")\n";
return "base";
}

sub new
{
my ($class,@array) = @_;
return bless \@array,$class;
}

package derived;
@ISA = 'base';
sub whatever
{
print "derived(",join(',',@_),")\n";
my $self = shift;
$self->SUPER::whatever(@_);
return "derived";
}

package main;

$obj = derived->new;

derived->whatever;
$obj->whatever;


The following patch seems to build a miniperl that behaves thus:

ned patch
pluto 164% miniperl -Do super

EXECUTING...

(super:27) Looking for method new in package derived
(super:27) Looking for method new in package base
(super:29) Looking for method whatever in package derived
derived(derived)
(super:21) Treating SUPER::whatever as derived::SUPER::whatever
(super:21) Looking for method whatever in package derived::SUPER
(super:21) Looking for method whatever in package derived::SUPER
(super:21) Looking for method whatever in package base
base(derived)
(super:30) Looking for method whatever in package derived
derived(derived=ARRAY(0x917b0))
(super:21) Treating SUPER::whatever as derived::SUPER::whatever
(super:21) Looking for method whatever in package derived::SUPER
base(derived=ARRAY(0x917b0))
(super:0) Looking for method DESTROY in package derived
(super:0) Looking for method DESTROY in package base
(super:0) Looking for method AUTOLOAD in package derived
(super:0) Looking for method AUTOLOAD in package base



*** ../perl5.001/gv.c Wed Jun 7 09:17:26 1995
--- gv.c Mon Oct 30 18:43:01 1995
***************
*** 223,232 ****
if (*nsplit == ':')
--nsplit;
*nsplit = '\0';
! stash = gv_stashpv(origname,TRUE);
! *nsplit = ch;
}
gv = gv_fetchmeth(stash, name, nend - name, 0);
if (!gv) {
CV* cv;

--- 223,277 ----
if (*nsplit == ':')
--nsplit;
*nsplit = '\0';
! 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) );
! } else {
! stash = gv_stashpv(origname,TRUE);
! *nsplit = ch;
! }
}
gv = gv_fetchmeth(stash, name, nend - name, 0);
+
+ if (!gv) {
+ /* Failed obvious case - look for SUPER as last element of stash's name */
+ char *packname = HvNAME(stash);
+ STRLEN len = strlen(packname);
+ if (len >= 7 && strEQ(packname+len-7,"::SUPER")) {
+ /* Now look for @.*::SUPER::ISA */
+ GV** gvp = (GV**)hv_fetch(stash,"ISA",3,FALSE);
+ if (!gvp || (gv = *gvp) == (GV*)&sv_undef || !GvAV(gv)) {
+ /* No @ISA in package ending in ::SUPER - drop suffix
+ and see if there is an @ISA there
+ */
+ HV *basestash;
+ char ch = packname[len-7];
+ AV *av;
+ packname[len-7] = '\0';
+ basestash = gv_stashpv(packname, TRUE);
+ packname[len-7] = ch;
+ gvp = (GV**)hv_fetch(basestash,"ISA",3,FALSE);
+ if (gvp && (gv = *gvp) != (GV*)&sv_undef && (av = GvAV(gv))) {
+ /* Okay found @ISA after dropping the SUPER, alias it */
+ SV *tmpstr = sv_2mortal(newSVpv(HvNAME(stash),0));
+ sv_catpvn(tmpstr, "::ISA", 5);
+ gv = gv_fetchpv(SvPV(tmpstr,na),TRUE,SVt_PVGV);
+ if (gv) {
+ GvAV(gv) = SvREFCNT_inc(av);
+ /* ... and re-try lookup */
+ gv = gv_fetchmeth(stash, name, nend - name, 0);
+ } else {
+ croak("Cannot create %s::ISA",HvNAME(stash));
+ }
+ }
+ }
+ }
+ }
+
if (!gv) {
CV* cv;



Now home to feed the cats ...
Re: super2 package [ In reply to ]
Something to go over Nick's patch for gv.c.

Dean


*** gv.c Tue Oct 31 11:00:08 1995
--- ../patches/gv.c Tue Oct 31 10:58:50 1995
***************
*** 261,267 ****
sv_catpvn(tmpstr, "::ISA", 5);
gv = gv_fetchpv(SvPV(tmpstr,na),TRUE,SVt_PVGV);
if (gv) {
! GvAV(gv) = SvREFCNT_inc(av);
/* ... and re-try lookup */
gv = gv_fetchmeth(stash, name, nend - name, 0);
} else {
--- 261,267 ----
sv_catpvn(tmpstr, "::ISA", 5);
gv = gv_fetchpv(SvPV(tmpstr,na),TRUE,SVt_PVGV);
if (gv) {
! GvAV(gv) = (AV*)SvREFCNT_inc(av);
/* ... and re-try lookup */
gv = gv_fetchmeth(stash, name, nend - name, 0);
} else {
Re: super2 package [ In reply to ]
According to Tim Bunce:
> use ISA qw(...);
> use from qw(...);
> use parents qw(...);

use base qw(...)
use super qw(...);

--
Chip Salzenberg, aka <chs@nando.net>
"Hey, it's the Miss Alternate Universe Pageant!"
-- Crow T. Robot, MST3K: "Stranded In Space"
Re: super2 package [ In reply to ]
> From: Chip Salzenberg <chs@nando.net>
>
> According to Tim Bunce:
> > use ISA qw(...);
> > use from qw(...);
> > use parents qw(...);
>
> use base qw(...)
> use super qw(...);

Yes, super has a handy consistency about it.

Anyone who actually wants this is very welcome to provide one :-)

Tim.