File Coverage

lib/Algorithm/MasterMind/Sequential.pm
Criterion Covered Total %
statement 36 36 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 8 8 100.0
pod 2 2 100.0
total 49 51 96.0


line stmt bran cond sub pod time code
1             package Algorithm::MasterMind::Sequential;
2              
3 1     1   880 use warnings;
  1         2  
  1         42  
4 1     1   5 use strict;
  1         2  
  1         45  
5 1     1   6 use Carp;
  1         1  
  1         71  
6              
7 1     1   15 use lib qw(../../lib);
  1         2  
  1         7  
8              
9             our $VERSION = sprintf "%d.%03d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/g;
10              
11 1     1   171 use base 'Algorithm::MasterMind';
  1         2  
  1         143  
12              
13 1     1   6 use Algorithm::Combinatorics qw(variations_with_repetition);
  1         2  
  1         337  
14              
15             sub initialize {
16 1     1 1 1 my $self = shift;
17 1   33     3 my $options = shift || croak "Need options here";
18 1         4 for my $o ( keys %$options ) {
19 2         11 $self->{"_$o"} = $options->{$o}
20             }
21 1         2 my @alphabet = @{$self->{'_alphabet'}};
  1         3  
22 1         7 $self->{'_engine'} = variations_with_repetition(\@alphabet, $options->{'length'});
23 1         46 $self->{'_range'} = $alphabet[0]."-".$alphabet[$#alphabet];
24 1         4 $self->{'_current_string'} = $alphabet[0] x $self->{'_length'};
25 1         4 $self->{'_last_string'} = $alphabet[$#alphabet]x $self->{'_length'};
26              
27             }
28              
29             sub issue_next {
30 4     4 1 5 my $self = shift;
31 4         11 my $rules = $self->number_of_rules();
32 4         7 my ($match, $string, $combination);
33              
34 4         16 while ( $combination = $self->{'_engine'}->next ) {
35 1111         14047 $string = join("", @$combination);
36 1111         2646 $match = $self->matches($string);
37 1111 100       5843 last if $match->{'matches'} == $rules;
38             }
39 4         26 return $self->{'_last'} = $string;
40             }
41              
42             "some blacks, 0 white"; # Magic true value required at end of module
43              
44             __END__