Is the following possible with Moose?

I have a class which has an object of another class as an attribute:

package My::ABC has 'db_accessor' => ( is => 'rw', isa => 'My::DEF', );

Inside this DEF class there are multiple methods which are called from ABC. They throw exceptions on errors (die). However, in this special case of class ABC I don't want the script to die, I want it to continue. At the same time I don't want to put an "eval" around each method call of "db_accessor".

I already tried to use the "around" modifier of Moose, but that seems to only work for the constructor, not for the method calls on "db_accessor". I tried it like this:

around 'db_accessor => sub { my $orig = shift; my $self = shift; my $out; eval { $out = $self->$orig(@_) }; if ($@) { $self->warn("Access failed with: [$@]"); } else { return $out; } };

However, this doesn't work. An access in this form still causes the script to die: $self->db_accessor->methodA();

Any idea how to solve this with Moose? Thanks in advance!


In reply to Intercept all object method calls with Moose by elTriberium

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.