in reply to Method Calls on multiple objects
No, it seems to me that what the original did, was allow all methods these object can do, on them all. In fact it sound a lot like tee — which is what I'd base the name of this module on.
Anyway, you original approach looks good to me, except I'd cache the sub, so AUTOLOAD isn't repeatedly called for each method.
That appears to work, at first sight. I'm not sure it's actually better/faster.sub AUTOLOAD { my $self = shift; if (my($method) = $AUTOLOAD =~ /::([^:]+)$/ ) { no strict 'refs'; *$AUTOLOAD = sub { my $self = shift; $_->$method(@_) for @$self; }; $self->$AUTOLOAD(@_); } }
p.s. Your original calls don't look right, it should be
Oh, and make to constructormy $obj_multi = MulitiObject->new( $obj_1, $obj_2 ); $obj_multi->foo($x, $y); # $obj_1->foo($x, $y); $obj_2->foo( +$x, $y);
I don't trust takling references to @_.sub new { my $class = shift; return bless [ @_ ], $class; }
|
|---|