Venus::Role::Catchable - Catchable Role
Catchable Role for Perl 5
package Example; use Venus::Class; use Venus 'error'; with 'Venus::Role::Tryable'; with 'Venus::Role::Catchable'; sub pass { true; } sub fail { error; } package main; my $example = Example->new; # my $error = $example->catch('fail');
This package modifies the consuming package and provides methods for trapping errors thrown from dispatched method calls.
This package provides the following methods:
catch(Str $method, Any @args) (Any)
The catch method traps any errors raised by executing the dispatched method call and returns the error string or error object. This method can return a list of values in list-context. This method supports dispatching, i.e. providing a method name and arguments whose return value will be acted on by this method.
Since 0.01
0.01
package main; my $example = Example->new; my $catch = $example->catch('fail'); # bless({...}, "Venus::Error")
package main; my $example = Example->new; my $catch = $example->catch('pass'); # undef
package main; my $example = Example->new; my ($catch, $result) = $example->catch('pass'); # (undef, 1)
package main; my $example = Example->new; my ($catch, $result) = $example->catch('fail'); # (bless({...}, "Venus::Error"), undef)
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.