File Coverage

blib/lib/Algorithm/LatticePoints.pm
Criterion Covered Total %
statement 9 21 42.8
branch n/a
condition n/a
subroutine 3 5 60.0
pod 2 2 100.0
total 14 28 50.0


line stmt bran cond sub pod time code
1             package Algorithm::LatticePoints;
2              
3 1     1   25953 use 5.008001;
  1         4  
  1         43  
4 1     1   6 use strict;
  1         3  
  1         35  
5 1     1   5 use warnings;
  1         7  
  1         462  
6              
7             require Exporter;
8              
9             our $VERSION = sprintf "%d.%02d", q$Revision: 0.1 $ =~ /(\d+)/g;
10              
11             sub new($&){
12 0     0 1   my $class = shift;
13 0           my $coderef = shift;
14 0           bless $coderef, $class;
15             }
16              
17             sub visit{
18 0     0 1   my $self = shift;
19 0           my ( $start, $end ) = @_;
20 0           my $loop = 'LOOP';
21             $loop =~ s{LOOP}{
22 0           "for my \$i$_ (\$start->[$_]..\$end->[$_]){LOOP}"
23 0           }ex for ( 0 .. @$start - 1 );
24 0           my $args = join ",", map { '$i' . $_ } reverse( 0 .. @$start - 1 );
  0            
25 0           $loop =~ s{LOOP}{\$self->($args)};
26 0           eval $loop;
27             }
28              
29             if ( $0 eq __FILE__ ) {
30             my $al = Algorithm::LatticePoints->new(
31             sub {
32             printf "[%s]\n", join( ", ", @_ );
33             }
34             );
35             $al->visit( [ 0, 0, 0 ], [ 9, 9, 9 ] );
36             }
37              
38             1;
39             __END__