[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [FWP] Collection.pm
On Mon, 19 Feb 2001 at 08:29:48 -0500, Kevin Reid wrote:
> I wrote this object class for a program of mine. Just thought it might
> be interesting.
>
> package Collection;
How about this, to allow a collection to be returned from the operation,
and a couple more generalisations and simplifications:
package Collection;
use strict;
use vars qw($AUTOLOAD);
sub new {
my $class = shift;
bless [@_], ref $class || $class;
}
sub AUTOLOAD {
my $self = shift;
my ($method) = $AUTOLOAD =~ /([^:]+)$/;
bless [ map { $_->$method(@_) } @$self ], ref $self;
}
sub DESTROY {};
1;
Or for more efficiency on repeated calls (but not with 'strict'):
sub AUTOLOAD {
my $self = shift;
my ($method) = $AUTOLOAD =~ /([^:]+)$/;
*$method = sub{ bless [ map { $_->$method(@_) } @$self ], ref $self; }
goto &method;
}
==== Want to unsubscribe from Fun With Perl? Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
==== unsubscribe