Make sure $] checks run correctly (another thing my smokers didn't catch)
[p5sagit/namespace-clean.git] / lib / namespace / clean / _Util.pm
index 5c0e3f4..f2579a0 100644 (file)
@@ -15,8 +15,8 @@ use strict;
 use base 'Exporter';
 our @EXPORT_OK = qw( DEBUGGER_NEEDS_CV_RENAME DEBUGGER_NEEDS_CV_PIVOT );
 
-use constant DEBUGGER_NEEDS_CV_RENAME => ( ( $] > 5.008_008 ) and ( $] < 5.013_006 ) );
-use constant DEBUGGER_NEEDS_CV_PIVOT => ( ( ! DEBUGGER_NEEDS_CV_RENAME ) and ( $] < 5.015_005 ) );
+use constant DEBUGGER_NEEDS_CV_RENAME => ( ( "$]" > 5.008_008 ) and ( "$]" < 5.013_006 ) );
+use constant DEBUGGER_NEEDS_CV_PIVOT => ( ( ! DEBUGGER_NEEDS_CV_RENAME ) and ( "$]" < 5.015_005 ) );
 
 # FIXME - ideally this needs to be provided by some abstraction lib
 # but we don't have that yet
@@ -31,29 +31,42 @@ BEGIN {
   my( $sub_name_loaded, $sub_util_loaded );
 
   sub _namer_load_error {
-    my $err = '';
-
-    return $err if $sub_util_loaded or $sub_name_loaded;
+    return '' if $sub_util_loaded or $sub_name_loaded;
 
-    local $@;
-
-    # prefer Sub::Name to Sub::Util
-    # this is rather arbitrary but remember this code exists only
-    # on perls 5.8.9 ~ 5.13.5
+    # if S::N is loaded first *and* so is B - then go with that, otherwise
+    # prefer Sub::Util as S::U will provide a faster get_subname and will
+    # not need further require() calls
+    # this is rather arbitrary but remember this code exists only perls
+    # between 5.8.9 ~ 5.13.5
 
     # when changing version also change in Makefile.PL
     my $sn_ver = 0.04;
 
-    eval {
-      require Sub::Name;
-      Sub::Name->VERSION($sn_ver);
-      $sub_name_loaded = 1;
-    }
+    local $@;
+    my $err = '';
+
+    (
+      ! (
+        $INC{"B.pm"}
+          and
+        $INC{"Sub/Name.pm"}
+          and
+        eval { Sub::Name->VERSION($sn_ver) }
+      )
+        and
+      eval { require Sub::Util }
+        and
+      # see https://github.com/moose/Moo/commit/dafa5118
+      defined &Sub::Util::set_subname
+        and
+      $sub_util_loaded = 1
+    )
       or
-    eval {
-      require Sub::Util;
-      $sub_util_loaded = 1;
-    }
+    (
+      eval { require Sub::Name and Sub::Name->VERSION($sn_ver) }
+        and
+      $sub_name_loaded = 1
+    )
       or
     $err = "When running under -d on this perl $], namespace::clean requires either Sub::Name $sn_ver or Sub::Util to be installed"
     ;