in reply to how to create a "delegating" array?
with minimal changes(blue parts) to your initial code
package Bar; use Data::Dumper; use Moose; sub bar { my $arg = shift;
if(ref($arg) eq 'ARRAY') { return map { $_->bar; } @{ $arg }; }
print "bar\n"; } package Foo; use Moose; sub foo { return [(Bar->new)x3]; # what magic do i need to apply here? } package main;
use autobox ARRAY => 'Bar';
Foo->new->foo->bar; #no more "Can't call method "bar" on unblessed reference" #because now ->bar is a native method of ARRAYREFs. #actually all the methods of Bar are native methods on ARRAYREFs now.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to create a "delegating" array?
by holli (Abbot) on Nov 29, 2009 at 16:48 UTC | |
by spx2 (Deacon) on Nov 29, 2009 at 20:00 UTC | |
by holli (Abbot) on Nov 29, 2009 at 23:03 UTC |