File Coverage

blib/lib/Test/RandomCheck/Types.pm
Criterion Covered Total %
statement 27 29 93.1
branch 6 8 75.0
condition n/a
subroutine 7 9 77.7
pod 0 3 0.0
total 40 49 81.6


line stmt bran cond sub pod time code
1             package Test::RandomCheck::Types;
2 4     4   867 use strict;
  4         4  
  4         83  
3 4     4   12 use warnings;
  4         5  
  4         67  
4 4     4   1535 use UNIVERSAL::require;
  4         3482  
  4         27  
5 4     4   1700 use Class::Accessor::Lite (new => 1);
  4         3083  
  4         20  
6 4     4   1427 use Test::RandomCheck::PRNG;
  4         6  
  4         31  
7              
8 0     0 0 0 sub arbitrary { die "You should implement " . (ref $_[0]) . "::arbitrary" }
9 0     0 0 0 sub memoize_key { die "You should implement " . (ref $_[0]) . "::memoize_key" }
10              
11             sub sample {
12 1     1 0 16 my $self = shift;
13 1         3 my $rand = Test::RandomCheck::PRNG->new;
14 1         3 map { [$self->arbitrary->pick($rand, $_)] } 0 .. 19;
  20         28  
15             }
16              
17             sub import {
18 16     16   18 my ($class) = @_;
19 16 100       497 return if $class ne __PACKAGE__; # Only export when Types used directly
20              
21             # Load all subclasses
22 4         16 (my $relative_path = __PACKAGE__ . '.pm') =~ s!::!/!g;
23 4         18 (my $dir = $INC{$relative_path}) =~ s/\.pm$//;
24 4 50       151 opendir my $h, $dir or die "Can't open $dir: $!";
25 4         63 while (my $name = readdir $h) {
26 52 100       2775 $name =~ /^(.+)\.pm$/ or next;
27 44 50       316 (__PACKAGE__ . "::$1")->require or die $@;
28             }
29             }
30              
31             1;