]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blobdiff - lib/Test/Leaner.pm
This is 0.02
[perl/modules/Test-Leaner.git] / lib / Test / Leaner.pm
index 6f90cef1ae4663704ee01802d81ea66c00693396..33650067115fab72c5794ab57a78455d6d4213a1 100644 (file)
@@ -10,11 +10,11 @@ Test::Leaner - A slimmer Test::More for when you favor performance over complete
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 SYNOPSIS
 
@@ -66,18 +66,17 @@ The tests don't output any kind of default diagnostic in case of failure ; the r
 
 C<use_ok>, C<require_ok>, C<can_ok>, C<isa_ok>, C<new_ok>, C<subtest>, C<explain>, C<TODO> blocks and C<todo_skip> are not implemented.
 
-=item *
-
-L<Test::Leaner> depends on L<Scalar::Util>, while L<Test::More> does not.
-
 =back
 
 =cut
 
-use Exporter     ();
-use Scalar::Util ();
+use Exporter ();
+
+my $main_process;
 
 BEGIN {
+ $main_process = $$;
+
  if ($] >= 5.008 and $INC{'threads.pm'}) {
   my $use_ithreads = do {
    require Config;
@@ -582,6 +581,37 @@ See L<Test::More/is_deeply>.
 
 =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 +630,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 +651,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 +680,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.
@@ -733,7 +763,7 @@ sub BAIL_OUT {
 }
 
 END {
unless ($?) {
if ($main_process == $$ and not $?) {
   lock $plan if THREADSAFE;
 
   if (defined $plan) {
@@ -813,7 +843,7 @@ In that case, it also needs a working L<threads::shared>.
 
 L<perl> 5.6.
 
-L<Exporter>, L<Scalar::Util>, L<Test::More>.
+L<Exporter>, L<Test::More>.
 
 =head1 AUTHOR