From: Peter Rabbitson Date: Wed, 7 Oct 2015 06:16:10 +0000 (+0200) Subject: Switch around the preference of S::U / S::N X-Git-Tag: 0.26~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2Fnamespace-clean.git;a=commitdiff_plain;h=c0de11256e0a5d7a44676a58bc2da780aa328767 Switch around the preference of S::U / S::N This makes the code more complex, but will save on loading the rather heavy B set of modules in case Sub::Util is in fact available --- diff --git a/lib/namespace/clean/_Util.pm b/lib/namespace/clean/_Util.pm index 5c0e3f4..b1c149f 100644 --- a/lib/namespace/clean/_Util.pm +++ b/lib/namespace/clean/_Util.pm @@ -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" ;