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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |