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
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