EO::delegate - delegate responsibility for unresolved messages to another class
package Foo; use EO; our @ISA = qw( EO ); use EO::delegate; package main; my $thing = Foo->new(); $thing->delegate( SomeClass->new() ); $thing->delegate_error( 'throw' ); eval { $thing->some_method; }; if ($@) { if ($@->isa('EO::Error::Method::NotFound') { # ... handle method not found exception } else { # ... handle other exceptions } }
EO::delegate provides a simple means of setting up a delegate for the a class. By importing this package into your namespace you have two new methods available to you - the delegate method, which gets and sets the delegate, and the delegate_error method, which gets and sets the method to call on the exception if any are raised.
delegate
delegate_error
By default delegate_error will be set to 'throw', but it may be useful to set it to 'record' if you don't wish the delegate to cause your program to die.
In the case that a method that is forwarded to a delegate is not available in that delegate an EO::Error::Method::NotFound exception is thrown or recorded, depending on whether delegate_error returns throw or record.
throw
record
James A. Duncan <jduncan@fotango.com> Arthur Bergman <abergman@fotango.com>
Copyright 2003 Fotango Ltd. All Rights Reserved.
This module is released under the same terms as Perl itself.
To install EO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm EO
CPAN shell
perl -MCPAN -e shell install EO
For more information on module installation, please visit the detailed CPAN module installation guide.