| 1 |
package my::autodie; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
use parent qw(autodie); |
| 6 |
use autodie::exception; |
| 7 |
use autodie::hints; |
| 8 |
|
| 9 |
autodie::hints->set_hints_for( |
| 10 |
'Some::Module::some_sub' => { |
| 11 |
scalar => sub { 1 }, # No calling in scalar/void context |
| 12 |
list => sub { @_ == 2 and not defined $_[0] } |
| 13 |
}, |
| 14 |
); |
| 15 |
|
| 16 |
autodie::exception->register( |
| 17 |
'Some::Module::some_sub' => sub { |
| 18 |
my ($E) = @_; |
| 19 |
|
| 20 |
if ($E->context eq "scalar") { |
| 21 |
return "some_sub() can't be called in scalar context"; |
| 22 |
} |
| 23 |
|
| 24 |
my $error = $E->return->[1]; |
| 25 |
|
| 26 |
return "some_sub() failed: $error"; |
| 27 |
} |
| 28 |
); |
| 29 |
|
| 30 |
1; |