File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ use strict;
1717 };
1818 sub new { # # no critic (RequireArgUnpacking)
1919 my $class = shift ;
20+ return bless odometer_gray(@_ ), $class ;
21+ }
22+ sub odometer_gray { # # no critic (RequireArgUnpacking)
2023 croak " no wheels specified" unless @_ ;
2124 my @w = @_ ;
2225 croak " all wheels must have at least two positions"
@@ -25,7 +28,7 @@ use strict;
2528 my @f = 0 .. @w ;
2629 my @o = (1) x @w ;
2730 my $done ;
28- return bless sub {
31+ return sub {
2932 if ($done ) { @c = (0) x @w ; @f = 0 .. @w ; @o = (1) x @w ; $done =0; return }
3033 my @cur = map {$w [$_ ][$c [$_ ]]} 0..$#w ;
3134 if ($f [0]==@w ) { $done =1 }
@@ -39,7 +42,7 @@ use strict;
3942 }
4043 }
4144 return wantarray ? @cur : join ' ' , map {defined ()?$_ :' ' } @cur ;
42- }, $class ;
45+ };
4346 }
4447}
4548
Original file line number Diff line number Diff line change @@ -17,10 +17,13 @@ use strict;
1717 };
1818 sub new { # # no critic (RequireArgUnpacking)
1919 my $class = shift ;
20+ return bless odometer(@_ ), $class ;
21+ }
22+ sub odometer { # # no critic (RequireArgUnpacking)
2023 croak " no wheels specified" unless @_ ;
2124 my @w = map { [ 1, ref eq ' ARRAY' ? @$_ : $_ ] } @_ ;
2225 my $done ;
23- return bless sub {
26+ return sub {
2427 if ($done ) { $done =0; return }
2528 my @cur = map {$$_ [$$_ [0]]} @w ;
2629 for (my $i =$#w ;$i >=0;$i --) {
@@ -29,7 +32,7 @@ use strict;
2932 $done =1 unless $i ;
3033 }
3134 return wantarray ? @cur : join ' ' , map {defined ()?$_ :' ' } @cur ;
32- }, $class ;
35+ };
3336 }
3437}
3538
@@ -74,6 +77,11 @@ operator in list context will return all of the (remaining) values in
7477the sequence as strings. In scalar context, the iterator will return
7578C<undef > once, and then start the sequence from the beginning.
7679
80+ This class is named C<::Tiny > because the code for the odometer fits
81+ on a single page, and if you look at the source, you'll see a
82+ C<sub odometer > that you can copy out of the source code if you wish
83+ (if you're not using L<Carp|Carp> , just replace C<croak > with C<die > ).
84+
7785=head2 Example
7886
7987The following wheels:
You can’t perform that action at this time.
0 commit comments