SYNOPSIS
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) = @_;
...
}
Exported Keyword
trap
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.
TODO
A way to modify the relationship between the method run and the deferment method at runtime.
AUTHOR
NOTBENH, <NOTBENH at cpan.org>
BUGS
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.
SUPPORT
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
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
Thanks again to team Moose.
COPYRIGHT & LICENSE
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.