Allows you to wrap any method in an eval and specify a dispatch method if the eval trips.
package My::Test; use Moose; use MooseX::Error::Trap; trap 'some_method', 'what_to_do'; sub some_method { ... } sub what_to_do { my ($self, $error) = @_; ... }
trap 'wrapped_method', 'trap';
Will wrap any calls to 'wrapped_method' in an eval, and if that eval fails then 'trap' is run.
Currently 'trap' can be either a string or a CodeRef. The case for a code ref is simple if triped execute the code ref, passing $self and $@. When 'trap' is a string things are a bit more complicated. If 'trap' is the name of an attribute of $self we check to see what the type constraint is on that attr, if it's 'CodeRef' then we grab the value and proceede like a CodeRef. For any other type constraint we return the value of that attr. Lastly if 'trap' is the name of a method ($self->can($trap)) then we execute it passing $@ as the only param.
In any other case we just die with $@ as though the eval was not there.
A way to modify the relationship between the method run and the deferment method at runtime.
NOTBENH, <NOTBENH at cpan.org>
<NOTBENH at cpan.org>
Please report any bugs or feature requests to bug-moosex-error-trap at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Error-Trap. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-moosex-error-trap at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc MooseX::Error::Trap
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Error-Trap
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/MooseX-Error-Trap
CPAN Ratings
http://cpanratings.perl.org/d/MooseX-Error-Trap
Search CPAN
http://search.cpan.org/dist/MooseX-Error-Trap/
Thanks again to team Moose.
Copyright 2009 NOTBENH, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MooseX::Error::Trap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Error::Trap
CPAN shell
perl -MCPAN -e shell install MooseX::Error::Trap
For more information on module installation, please visit the detailed CPAN module installation guide.