package Array;
use Tie::Array;
use strict;
use vars qw/@ISA $AUTOLOAD/;
@ISA = qw/Tie::StdArray/;
sub TIEARRAY {
my $class = shift;
return bless [], $class;
}
sub AUTOLOAD {
my $self = shift;
my $method = $AUTOLOAD;
$method =~ s/.*:://;
foreach (@$self) {
no strict 'subs';
$_->$method(@_);
}
}
####
my @array;
tie (@array, 'Array');
@array = (new Foo,new Bar,new Baz);
my $obj = tied @array;
$obj->method; # calls method on all objects in the array
####
my @array;
tie (@array, 'Array');
@array = (new Foo,new Bar,new Baz);
@array->method; # calls method on all objects in the array