File Coverage

blib/lib/Algorithm/Odometer/Tiny.pm
Criterion Covered Total %
statement 36 36 100.0
branch 16 16 100.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 59 60 98.3


line stmt bran cond sub pod time code
1             #!perl
2 1     1   84088 use warnings;
  1         2  
  1         28  
3 1     1   17 use strict;
  1         1  
  1         50  
4              
5             # SEE THE END OF THIS FILE FOR AUTHOR, COPYRIGHT AND LICENSE INFORMATION
6              
7             { package Algorithm::Odometer::Tiny;
8             our $VERSION = "0.02";
9 1     1   5 use Carp;
  1         2  
  1         108  
10             use overload '<>' => sub {
11 1123     1123   3660 my $self = shift;
12 1123 100       1857 return $self->() unless wantarray;
13 1         2 my @all;
14 1         3 while (defined( my $x = $self->() ))
15 6         14 { push @all, $x }
16 1         9 return @all;
17 1     1   1005 };
  1         773  
  1         7  
18             sub new { ## no critic (RequireArgUnpacking)
19 9     9 0 22701 my $class = shift;
20 9 100       190 croak "no wheels specified" unless @_;
21 8 100       18 my @w = map { [ 1, ref eq 'ARRAY' ? @$_ : $_ ] } @_;
  22         76  
22 8         14 my $done;
23             return bless sub {
24 1152 100   1152   2336 if ($done) { $done=0; return }
  8         12  
  8         19  
25 1144         1367 my @cur = map {$$_[$$_[0]]} @w;
  3518         5150  
26 1144         1883 for(my $i=$#w;$i>=0;$i--) {
27 1281 100       1486 last if ++$w[$i][0]<@{$w[$i]};
  1281         1917  
28 145         182 $w[$i][0]=1;
29 145 100       278 $done=1 unless $i;
30             }
31 1144 100       1704 return wantarray ? @cur : join '', map {defined()?$_:''} @cur;
  3484 100       6452  
32 8         46 }, $class;
33             }
34             }
35              
36             # Possible To-Do for Later: Generate regexes based on the wheels?
37              
38             1;
39             __END__