package File::KDBX::Error;
# ABSTRACT: Represents something bad that happened
+use 5.010;
use warnings;
use strict;
use Exporter qw(import);
-use Scalar::Util qw(blessed);
+use Scalar::Util qw(blessed looks_like_number);
use namespace::clean -except => 'import';
our $VERSION = '999.999'; # VERSION
else {
eval qq{package $WARNINGS_CATEGORY; use warnings::register; 1}; ## no critic ProhibitStringyEval
}
+
+ my $debug = $ENV{DEBUG};
+ $debug = looks_like_number($debug) ? (0 + $debug) : ($debug ? 1 : 0);
+ *_DEBUG = $debug == 1 ? sub() { 1 } :
+ $debug == 2 ? sub() { 2 } :
+ $debug == 3 ? sub() { 3 } :
+ $debug == 4 ? sub() { 4 } : sub() { 0 };
}
use overload '""' => 'to_string', cmp => '_cmp';
my $error = delete $args{_error};
my $e = $error;
- # $e =~ s/ at \H+ line \d+.*//g;
+ $e =~ s/ at \H+ line \d+.*//g;
my $self = bless {
details => \%args,
return $details;
}
-sub errno { $_[0]->{errno} }
+=attr errno
-sub previous { $_[0]->{previous} }
+Get the value of C<errno> when the exception was created.
+
+=attr previous
+
+Get the value of C<$@> (i.e. latest exception) at the time the exception was created.
+
+=attr trace
+
+Get a stack trace indicating where in the code the exception was created.
+
+=cut
+
+=attr type
-sub trace { $_[0]->{trace} // [] }
+Get the exception type, if any.
-sub type { $_[0]->details->{type} // '' }
+=cut
+
+sub errno { $_[0]->{errno} }
+sub previous { $_[0]->{previous} }
+sub trace { $_[0]->{trace} // [] }
+sub type { $_[0]->details->{type} // '' }
=method to_string
Stringify an error.
-This does not contain a stack trace, but you can set the C<DEBUG> environment
-variable to truthy to stringify the whole error object.
+This does not contain a stack trace, but you can set the C<DEBUG> environment variable to at least 2 to
+stringify the whole error object.
=cut
sub _cmp { "$_[0]" cmp "$_[1]" }
-sub PROPAGATE {
- 'wat';
-}
-
sub to_string {
my $self = shift;
- # return "uh oh\n";
my $msg = "$self->{trace}[0]";
- $msg .= '.' if $msg !~ /[\.\!\?]$/; # Why does this cause infinite recursion on some perls?
- # $msg .= '.' if $msg !~ /(?:\.|!|\?)$/;
- if ($ENV{DEBUG}) {
+ $msg .= '.' if $msg !~ /[\.\!\?]$/;
+ if (2 <= _DEBUG) {
require Data::Dumper;
local $Data::Dumper::Indent = 1;
local $Data::Dumper::Quotekeys = 0;