in reply to how to create a "delegating" array?

hi holli,

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
    This requires the "consuming" code to know about the internals of 'Bar' (by using autobox). That is clumsy and not what I want.


    holli

    You can lead your users to water, but alas, you cannot drown them.
      you can write code completely independent of 'Bar' if you use monkeypatching combined with autobox, is that what you mean ?
        maybe, i have no idea how i should "monkeypatch" a class.


        holli

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