Bitcoin-Crypto
view release on metacpan or search on metacpan
lib/Bitcoin/Crypto/Exception.pm view on Meta::CPAN
package Bitcoin::Crypto::Exception;
$Bitcoin::Crypto::Exception::VERSION = '4.005';
use v5.14;
use warnings;
use Mooish::Base -standard;
use Feature::Compat::Try;
use Scalar::Util qw(blessed);
use overload
q{""} => "as_string",
fallback => 1;
has param 'message' => (
isa => Str,
writer => -hidden,
);
has field 'caller' => (
isa => Maybe [ArrayRef],
default => sub {
for my $call_level (1 .. 20) {
my ($package, $file, $line) = caller $call_level;
my $package_ok = defined $package && $package !~ /^(Bitcoin::Crypto|Try::Tiny|Type::Coercion)/;
my $file_ok = defined $file && $file !~ /\(eval \d+\)/;
if ($package_ok && $file_ok) {
return [$package, $file, $line];
}
}
return undef;
},
);
sub raise
{
my ($self, $error) = @_;
if (defined $error) {
$self = $self->new(message => $error);
}
die $self;
}
sub throw
{
goto \&raise;
}
sub trap_into
{
# try to be fast here. Only unpack arguments if executing the sub fails
try {
return $_[1]->();
}
catch ($ex) {
my ($class, $sub, $prefix) = @_;
if (blessed $ex) {
if ($ex->isa($class)) {
$ex->_set_message("$prefix: " . $ex->message)
if $prefix;
$ex->raise;
}
if ($ex->isa('Bitcoin::Crypto::Exception')) {
$class->raise(($prefix ? "$prefix: " : '') . $ex->message);
}
}
my $ex_string = "$ex";
chomp $ex_string; # remove \n from die_no_trace
$class->raise($prefix ? "$prefix: $ex_string" : $ex_string);
}
}
sub as_string
{
my ($self) = @_;
my $raised = $self->message;
$raised =~ s/\s+\z//;
( run in 0.572 second using v1.01-cache-2.11-cpan-39bf76dae61 )