in reply to Re: how to create a "delegating" array?
in thread how to create a "delegating" array?

No, I wanted independent instances. Your code got me in the right direction. It was a little buggy, though =). Moosified version:
package Bar; use Moose; has x => ( is => 'rw', isa => 'Any' ); sub bar { print "bar", shift->x, "\n"; } package MapDelay; use Moose; use vars '$AUTOLOAD'; has elements => ( is => 'rw', isa => 'ArrayRef' ); around BUILDARGS => sub { my ($orig,$class) = @_; $class->$orig(elements => [splice @_,2]); }; sub AUTOLOAD { (my $m = $AUTOLOAD) =~ s/.*:://; map { $_->$m(@_) } @{shift->elements} }; package Foo; use Moose; sub foo { return MapDelay->new( Bar->new(x=>1), Bar->new(x=>2), Bar->new(x=> +3) ); }; package main; Foo->new->foo->bar; #prints bar1\nbar2\nbar3\n


holli

You can lead your users to water, but alas, you cannot drown them.

Replies are listed 'Best First'.
Re^3: how to create a "delegating" array?
by happy.barney (Friar) on Nov 29, 2009 at 09:44 UTC
    Bar->new(x=>1), Bar->new(x=>2), Bar->new(x=> +3
    this can be good place to use map:  map Bar->new (x => $_), 1 .. 3