ashish.kvarma has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I am a novice to Moose and am stuck to a code which might be very trivial.
I am using handles to delegate few subroutines but I do want to have a common code for exception handling around them. My problem is that I want to throw different exceptions for different subroutines.
Please refer the code below:I tried passing extra parameter from handles (as in the example below) but its not it’s not passed to around.has 'usr_manager' => ( is => 'rw', isa => 'UserManager', lazy_build => 1, handles => { list_users => 'list', load_user => 'load', }, ); has 'prod_manager' => ( is => 'rw', isa => 'ProductManager', lazy_build => 1, handles => { list_prods => 'list', load_prod => 'load', }, ); around qw(list_users load_user list_prods load_prod) => sub { my $orig = shift; my $self = shift; my $return_data; eval { $return_data = $self->$orig(@_); }; if (my $E = Exception::Class->caught('MyExeption')) { $E->rethrow(); } if ($@) { my $message = $self->truncate_err_msg($@); #Throw exception based on subroutine. } return $return_data; };
has 'prod_manager' => ( is => 'rw', isa => 'ProductManager', lazy_build => 1, handles => { list_prods => ['list' => 'Execption1'], load_prod => ['load' => 'Execption2'], }, );
I can handle the exception inside the delegated subroutine but would like to do it at this one place as it changes will be at only one place.
Thanks in advance for any information/help you can provide.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose | How to identify subroutine inside an 'around' in case multiple subroutine share the same 'around'?
by ikegami (Patriarch) on Aug 09, 2010 at 14:40 UTC | |
|
Re: Moose | How to identify subroutine inside an 'around' in case multiple subroutine share the same 'around'?
by Anonymous Monk on Aug 09, 2010 at 13:07 UTC | |
by ashish.kvarma (Monk) on Aug 09, 2010 at 13:55 UTC | |
by locked_user sundialsvc4 (Abbot) on Aug 10, 2010 at 03:32 UTC | |
|
Re: Moose | How to identify subroutine inside an 'around' in case multiple subroutine share the same 'around'?
by ashish.kvarma (Monk) on Aug 09, 2010 at 14:08 UTC |