X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FFile%2FKDBX%2FError.pm;h=4aee5fe995512a2c5a97cdbd8ac53ca78579da58;hb=a4c5d05556ecd450acce5e20fcab7af5f282af2f;hp=d12d0806588e35ae67bddfe1148847fc504055c8;hpb=37b09e0f2832514b33de4499a83f22d5ffe7c0a3;p=chaz%2Fp5-File-KDBX diff --git a/lib/File/KDBX/Error.pm b/lib/File/KDBX/Error.pm index d12d080..4aee5fe 100644 --- a/lib/File/KDBX/Error.pm +++ b/lib/File/KDBX/Error.pm @@ -1,11 +1,12 @@ 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 @@ -21,6 +22,13 @@ BEGIN { 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'; @@ -140,8 +148,8 @@ sub type { $_[0]->details->{type} // '' } Stringify an error. -This does not contain a stack trace, but you can set the C environment -variable to truthy to stringify the whole error object. +This does not contain a stack trace, but you can set the C environment variable to at least 2 to +stringify the whole error object. =cut @@ -151,7 +159,7 @@ sub to_string { my $self = shift; my $msg = "$self->{trace}[0]"; $msg .= '.' if $msg !~ /[\.\!\?]$/; - if ($ENV{DEBUG}) { + if (2 <= _DEBUG) { require Data::Dumper; local $Data::Dumper::Indent = 1; local $Data::Dumper::Quotekeys = 0;