Lose yet another dep (Data::Dumper::Concise)
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / _Util.pm
index 846920d..60a4815 100644 (file)
@@ -23,12 +23,6 @@ BEGIN {
 
     UNSTABLE_DOLLARAT => ( "$]" < 5.013002 ) ? 1 : 0,
 
-    DBICTEST => $INC{"DBICTest/Util.pm"} ? 1 : 0,
-
-    # During 5.13 dev cycle HELEMs started to leak on copy
-    # add an escape for these perls ON SMOKERS - a user will still get death
-    PEEPEENESS => ( eval { DBICTest::RunMode->is_smoker } && ( "$]" >= 5.013005 and "$]" <= 5.013006) ),
-
     ( map
       #
       # the "DBIC_" prefix below is crucial - this is what makes CI pick up
@@ -81,8 +75,8 @@ our @EXPORT_OK = qw(
   refdesc refcount hrefaddr
   scope_guard detected_reinvoked_destructor
   is_exception dbic_internal_try
-  quote_sub qsub perlstring serialize deep_clone
-  parent_dir
+  quote_sub qsub perlstring serialize deep_clone dump_value
+  parent_dir mkdir_p
   UNRESOLVABLE_CONDITION
 );
 
@@ -127,6 +121,42 @@ sub serialize ($) {
   nfreeze($_[0]);
 }
 
+my ($dd_obj, $dump_str);
+sub dump_value ($) {
+  local $Data::Dumper::Indent = 1
+    unless defined $Data::Dumper::Indent;
+
+  $dump_str = (
+    $dd_obj
+      ||=
+    do {
+      require Data::Dumper;
+      my $d = Data::Dumper->new([])
+        ->Purity(0)
+        ->Pad('')
+        ->Useqq(1)
+        ->Terse(1)
+        ->Freezer('')
+        ->Quotekeys(0)
+        ->Bless('bless')
+        ->Pair(' => ')
+        ->Sortkeys(1)
+        ->Deparse(1)
+      ;
+
+      $d->Sparseseen(1) if modver_gt_or_eq (
+        'Data::Dumper', '2.136'
+      );
+
+      $d;
+    }
+  )->Values([$_[0]])->Dump;
+
+  $dd_obj->Reset->Values([]);
+
+  $dump_str;
+}
+
 sub scope_guard (&) {
   croak 'Calling scope_guard() in void context makes no sense'
     if ! defined wantarray;
@@ -167,6 +197,7 @@ sub is_exception ($) {
 
   my ($not_blank, $suberror);
   {
+    local $SIG{__DIE__} if $SIG{__DIE__};
     local $@;
     eval {
       # The ne() here is deliberate - a plain length($e), or worse "$e" ne
@@ -276,9 +307,7 @@ sub is_exception ($) {
         unless $callstack_state->{in_internal_try};
 
       # always unset - someone may have snuck it in
-      local $SIG{__DIE__}
-        if $SIG{__DIE__};
-
+      local $SIG{__DIE__} if $SIG{__DIE__};
 
       if( $wantarray ) {
         @ret = $try_cref->();
@@ -389,8 +418,8 @@ sub modver_gt_or_eq ($$) {
     local $SIG{__WARN__} = sigwarn_silencer( qr/\Qisn't numeric in subroutine entry/ )
       if SPURIOUS_VERSION_CHECK_WARNINGS;
 
+    local $SIG{__DIE__} if $SIG{__DIE__};
     local $@;
-    local $SIG{__DIE__};
     eval { $mod->VERSION($ver) } ? 1 : 0;
   };
 
@@ -451,6 +480,12 @@ sub parent_dir ($) {
   ;
 }
 
+sub mkdir_p ($) {
+  require File::Path;
+  # do not ask for a recent version, use 1.x API calls
+  File::Path::mkpath([ "$_[0]" ]);  # File::Path does not like objects
+}
+
 
 {
   my $list_ctx_ok_stack_marker;