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:
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; };
I tried passing extra parameter from handles (as in the example below) but its not it’s not passed to around.
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.
Regards,
Ashish

In reply to Moose | How to identify subroutine inside an 'around' in case multiple subroutine share the same 'around'? by ashish.kvarma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.