Array::Delegate - Perl extension for delegating methods calls on a ArrayRef to its elements
package Employee; sub new { my $class = shift; return bless {@_}, $class; } sub pay_salary { print "Yay, fresh money for", shift->{name}, "\n" } package Company; sub employees { return Array::Delegate->new( [Employee->new( name => 'Tim' ), Employee->new( name => 'Bob' )] ); } package SomeModule; Company->new()->employees()->pay_salary(); # pays all employees
This is just to create a bit of syntactict sugar for OO interfaces.
In a a method that normally returns an ArrayRef of Objects, you can return an instance of Array::Delegate, which is still and array, just blessed. Then, the caller can use
$results = $array->foo
Instead of
$results = [ map $_->foo, @$array ];
Simply blesses $arrayRef to be a Array::Delegate object.
Alaska Saedelere, <alaska.saedelere@googlemail.com<gt>
Copyright (C) 2009 by Alaska Saedelere
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
To install Array::Delegate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Array::Delegate
CPAN shell
perl -MCPAN -e shell install Array::Delegate
For more information on module installation, please visit the detailed CPAN module installation guide.