]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/Error.pm
Move iteration code into Group
[chaz/p5-File-KDBX] / lib / File / KDBX / Error.pm
index d23837a8d3ba5018a89cdf7ae7a23a198d5e70b6..86442f3bdc306a071a2101cb462e6f3b9dbfbd2b 100644 (file)
@@ -5,7 +5,7 @@ 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 +21,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';
@@ -112,34 +119,26 @@ sub details {
 
 Get the value of C<errno> when the exception was created.
 
-=cut
-
-sub errno { $_[0]->{errno} }
-
 =attr previous
 
 Get the value of C<$@> (i.e. latest exception) at the time the exception was created.
 
-
-=cut
-
-sub previous { $_[0]->{previous} }
-
 =attr trace
 
 Get a stack trace indicating where in the code the exception was created.
 
 =cut
 
-sub trace { $_[0]->{trace} // [] }
-
 =attr type
 
 Get the exception type, if any.
 
 =cut
 
-sub type { $_[0]->details->{type} // '' }
+sub errno    { $_[0]->{errno} }
+sub previous { $_[0]->{previous} }
+sub trace    { $_[0]->{trace} // [] }
+sub type     { $_[0]->details->{type} // '' }
 
 =method to_string
 
@@ -159,7 +158,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;
This page took 0.020892 seconds and 4 git commands to generate.