]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/Error.pm
Declare perl 5.10.0 prereq
[chaz/p5-File-KDBX] / lib / File / KDBX / Error.pm
index d12d0806588e35ae67bddfe1148847fc504055c8..4aee5fe995512a2c5a97cdbd8ac53ca78579da58 100644 (file)
@@ -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<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
 
@@ -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;
This page took 0.021971 seconds and 4 git commands to generate.