File Coverage

blib/lib/Games/Solitaire/Verify/KlondikeTalon.pm
Criterion Covered Total %
statement 15 61 24.5
branch 0 12 0.0
condition n/a
subroutine 5 11 45.4
pod 4 4 100.0
total 24 88 27.2


line stmt bran cond sub pod time code
1             package Games::Solitaire::Verify::KlondikeTalon;
2             $Games::Solitaire::Verify::KlondikeTalon::VERSION = '0.2601';
3 1     1   250742 use warnings;
  1         2  
  1         78  
4 1     1   5 use strict;
  1         1  
  1         27  
5              
6              
7 1     1   8 use parent 'Games::Solitaire::Verify::Base';
  1         1  
  1         8  
8              
9 1     1   464 use Games::Solitaire::Verify::Exception ();
  1         4  
  1         23  
10 1     1   534 use Games::Solitaire::Verify::Card ();
  1         3  
  1         587  
11              
12             __PACKAGE__->mk_acc_ref(
13             [
14             qw(
15             _max_num_redeals
16             _num_redeals_so_far
17             _undealt_cards
18             _waste
19             )
20             ]
21             );
22              
23              
24             sub _input_from_string
25             {
26 0     0     my $self = shift;
27 0           my $str = shift;
28              
29 0 0         if ( my ($cards_str) = ( $str =~ /\ATalon: (.*)\z/ms ) )
30             {
31             $self->_undealt_cards(
32             [
33 0           map { Games::Solitaire::Verify::Card->new( { string => $_, } ) }
  0            
34             split /\s+/,
35             $cards_str
36             ]
37             );
38             }
39             else
40             {
41 0           die "Wrong format - does not start with Talon.";
42             }
43             }
44              
45             sub _init
46             {
47 0     0     my ( $self, $args ) = @_;
48              
49 0           $self->_max_num_redeals( $args->{max_num_redeals} );
50              
51 0           $self->_num_redeals_so_far(0);
52              
53 0           $self->_undealt_cards( [] );
54 0           $self->_waste( [] );
55              
56 0 0         if ( exists( $args->{string} ) )
57             {
58 0           $self->_input_from_string( $args->{string} );
59             }
60              
61 0           return;
62             }
63              
64              
65             sub draw
66             {
67 0     0 1   my $self = shift;
68              
69 0 0         if ( !@{ $self->_undealt_cards() } )
  0            
70             {
71 0           die "Cannot draw.";
72             }
73              
74 0           push @{ $self->_waste() }, shift( @{ $self->_undealt_cards() } );
  0            
  0            
75              
76 0           return;
77             }
78              
79              
80             sub extract_top
81             {
82 0     0 1   my $self = shift;
83              
84 0 0         if ( !@{ $self->_waste() } )
  0            
85             {
86 0           die "Cannot extract_top.";
87             }
88              
89 0           return pop( @{ $self->_waste() } );
  0            
90             }
91              
92              
93             sub redeal
94             {
95 0     0 1   my $self = shift;
96              
97 0 0         if ( @{ $self->_undealt_cards() } )
  0            
98             {
99 0           die "Cannot redeal while there are remaining cards.";
100             }
101              
102 0 0         if ( $self->_num_redeals_so_far() == $self->_max_num_redeals() )
103             {
104 0           die "Cannot redeal because maximal number exceeded.";
105             }
106              
107 0           $self->_num_redeals_so_far( $self->_num_redeals_so_far() + 1 );
108              
109 0           push @{ $self->_undealt_cards() }, @{ $self->_waste() };
  0            
  0            
110              
111 0           $self->_waste( [] );
112              
113 0           return;
114             }
115              
116              
117             sub to_string
118             {
119 0     0 1   my $self = shift;
120              
121             return join( " ",
122 0           "Talon:", ( map { $_->fast_s() } reverse @{ $self->_waste() } ),
  0            
123 0           '==>', ( map { $_->fast_s() } @{ $self->_undealt_cards() } ), '<==', );
  0            
  0            
124             }
125              
126             1; # End of Games::Solitaire::Verify::KlondikeTalon
127              
128             __END__