MooseX::MultiObject::Meta::Method::MultiDelegation - method that delegates to a set of objects
version 0.03
Given a class that has a set of objects:
has
my $meta = Moose::Meta::Class->create( ... ); $meta->add_attribute ( objects => ( is => 'ro', isa => 'Set', handles => ['members'], );
Make a method foo to call foo on every element of the set:
my $foo_metamethod = MooseX::MultiObject::Meta::Method::MultiDelegation->new( object_getter => 'members', delegate_to => 'foo', ); $meta->add_method( foo => $foo_metamethod );
Then you can write:
my $class = $meta->name->new( objects => [ $a, $b ] ); my @results = $class->foo;
Which is equivalent to:
my $set = set($a, $b); my @results = map { $_->foo } $set->members;
This is a Moose::Meta::Method and Class::MOP::Method::Generated that works like Moose::Meta::Method::Delegation, except it delegates to a collection of objects instead of just one.
Moose::Meta::Method
Class::MOP::Method::Generated
Moose::Meta::Method::Delegation
Jonathan Rockway <jrockway@cpan.org>
This software is copyright (c) 2011 by Jonathan Rockway.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MooseX::MultiObject, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::MultiObject
CPAN shell
perl -MCPAN -e shell install MooseX::MultiObject
For more information on module installation, please visit the detailed CPAN module installation guide.