|
Posted by Mumia W. on January 11, 2008, 6:22 am
Please log in for more thread options On 01/09/2008 03:29 PM, Steve Roscio wrote:
> Howdy -
>
> Is this something worth posting to CPAN? See the POD about two dozen
> lines down. It's like a simpler, faster but dumber flavor of NEXT.
>
> Thanx,
> - Steve
>
> package DUPER;
> use strict;
> use warnings;
> our $VERSION = '0.07';
> use vars qw($AUTOLOAD);
>
> sub AUTOLOAD
> {
> my $func = $AUTOLOAD; $func =~ s/^DUPER:://o;
> my $base = shift;
> my $name = (caller(1))[3]; $name =~ s/^(.+?)::\w+$/$1/io;
> no strict 'refs';
> my $ret = undef;
> foreach (@)
> {
> my $f = $_."::$func";
> $ret = $base->$f(@_);
> }
> return $ret;
> }
>
> 1;
>
> __END__
>
> =head1 NAME
>
> DUPER.pm - Works like SUPER but dispatches to each parent.
>
> =head1 SYNOPSIS
>
> use DUPER;
> $this->SUPER::MyFunc(@_); # Only dispatches to first @ISA parent
> $this->DUPER::MyFunc(@_); # Dispatches to *all* @ISA parents
>
> =head1 DESCRIPTION
>
> The DUPER pseudo-class works like the SUPER pseudo-class, but
> instead of dispatching to the first of the @ISA parent classes,
> it dispatches to each of the @ISA parent classes.
>
> DUPER only useful if your class does multiple inheritance --
> if you have more than one thing in your @ISA array.
> Otherwise you should just use SUPER.
>
> This class was designed to be small and fast. As such,
> it doesn't do much! It DOES NOT handle the diamond-inheritance
> situation, so if that is a problem for your class, then you
> probably want to use NEXT instead of DUPER. In fact, NEXT
> is a very good class that you probably should be using anyway,
> except that NEXT is a bit slow.
>
> But if you don't care about the diamond problem,
> then DUPER is just fine.
>
> =head2 Return Value
>
> What about the return value from the call -- which
> value is returned? Just the last one.
>
> =head2 HUH?
>
> Why the name DUPER? The name has nothing to do with
> duplication; I chose it because of the closeness to the SUPER
> name, and it's super-duper!
>
> If that's just too stupid a name, then I'll consider renaming
> this class to "EACH", since it calls *each* member of @ISA.
> Lemme know.
>
> =head1 COPYRIGHT
>
> Copyright (c)2007 by Steve Roscio. All rights reserved.
> This module is free software. It may be used, redistributed
> and/or modified under the same terms as Perl itself.
This is potentially useful, but what happens if someone attempts to
invoke methods that do not exist?
$this->DUPER::nowhere();
$this->another_nonmethod();
I think DUPER is better than EACH, but try to find a better package
namespace such as Class::DUPER.
|