From: Vincent Pit Date: Wed, 29 Dec 2010 16:30:38 +0000 (+0100) Subject: Remove the dependency on Scalar::Util X-Git-Tag: v0.02~2 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c59e95160c3ba4aa516093a85225d9824863d619;p=perl%2Fmodules%2FTest-Leaner.git Remove the dependency on Scalar::Util It will be loaded only if it is available. --- diff --git a/Makefile.PL b/Makefile.PL index 6fcb76c..63bd771 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,9 +12,8 @@ my $dist = 'Test-Leaner'; $file = "lib/$file.pm"; my %PREREQ_PM = ( - 'Exporter' => 0, - 'Scalar::Util' => 0, - 'Test::More' => 0, + 'Exporter' => 0, + 'Test::More' => 0, ); my %META = ( diff --git a/lib/Test/Leaner.pm b/lib/Test/Leaner.pm index 6f90cef..896582b 100644 --- a/lib/Test/Leaner.pm +++ b/lib/Test/Leaner.pm @@ -66,16 +66,11 @@ The tests don't output any kind of default diagnostic in case of failure ; the r C, C, C, C, C, C, C, C blocks and C are not implemented. -=item * - -L depends on L, while L does not. - =back =cut -use Exporter (); -use Scalar::Util (); +use Exporter (); BEGIN { if ($] >= 5.008 and $INC{'threads.pm'}) { @@ -582,6 +577,37 @@ See L. =cut +BEGIN { + local $@; + if (eval { require Scalar::Util; 1 }) { + *_reftype = \&Scalar::Util::reftype; + } else { + # Stolen from Scalar::Util::PP + require B; + my %tmap = qw< + B::NULL SCALAR + + B::HV HASH + B::AV ARRAY + B::CV CODE + B::IO IO + B::GV GLOB + B::REGEXP REGEXP + >; + *_reftype = sub ($) { + my $r = shift; + + return undef unless length ref $r; + + my $t = ref B::svref_2object($r); + + return exists $tmap{$t} ? $tmap{$t} + : length ref $$r ? 'REF' + : 'SCALAR' + } + } +} + sub _deep_ref_check { my ($x, $y, $ry) = @_; @@ -600,8 +626,8 @@ sub _deep_ref_check { next if not(ref $ex xor ref $ey) and $ex eq $ey; - $ry = Scalar::Util::reftype($ey); - return 0 if Scalar::Util::reftype($ex) ne $ry; + $ry = _reftype($ey); + return 0 if _reftype($ex) ne $ry; return 0 unless $ry and _deep_ref_check($ex, $ey, $ry); } @@ -621,8 +647,8 @@ sub _deep_ref_check { next if not(ref $ex xor ref $ey) and $ex eq $ey; - $ry = Scalar::Util::reftype($ey); - return 0 if Scalar::Util::reftype($ex) ne $ry; + $ry = _reftype($ey); + return 0 if _reftype($ex) ne $ry; return 0 unless $ry and _deep_ref_check($ex, $ey, $ry); } @@ -650,8 +676,8 @@ sub _deep_check { # Test::More::is_deeply happily breaks encapsulation if the objects aren't # overloaded. - my $ry = Scalar::Util::reftype($y); - return 0 if Scalar::Util::reftype($x) ne $ry; + my $ry = _reftype($y); + return 0 if _reftype($x) ne $ry; # Shortcut if $x and $y are both not references and failed the previous # $x eq $y test. @@ -813,7 +839,7 @@ In that case, it also needs a working L. L 5.6. -L, L, L. +L, L. =head1 AUTHOR