blib/lib/Games/Solitaire/Verify/KlondikeTalon.pm

filter: Statementstmt 28.1% 18 / 64 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 45.4% 5 / 11 Podpod 100% 4 / 4 totaltotal 29.6% 27 / 91 SCAR 33.6
CC
7
Cov
24%
redeal
12.0
_input_from_string
6.0
_init
6.0
CRAP 28.8
« blib/lib/Games/Solitaire/Verify/Solution/ExpandMultiCardMoves.pm ↑ Summary blib/lib/Games/Solitaire/Verify/FromOtherSolversBase.pm »
1 package Games::Solitaire::Verify::KlondikeTalon;
2 1 $Games::Solitaire::Verify::KlondikeTalon::VERSION = '0.2402';
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 1 ▶use parent 'Games::Solitaire::Verify::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Games::Solitaire::Verify::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Games::Solitaire::Verify::Card ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 __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 ▶ my $self = shift;
Subroutine _input_from_string: not called CC=2 SCAR=17.9
27 0 my $str = shift;
28  
29 0 ▶ if ( my ($cards_str) = ( $str =~ /\ATalon: (.*)\z/ms ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my($cards_str) = $str =~ /\ATalon: (.*)\z/ms) { } 0 0 0
30 {
31 $self->_undealt_cards(
32 [
33 0 map { Games::Solitaire::Verify::Card->new( { string => $_, } ) }
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 ▶ my ( $self, $args ) = @_;
Subroutine _init: not called CC=2 SCAR=17.9
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 ▶ if ( exists( $args->{string} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"string"}) 0 0 0
57 {
58 0 $self->_input_from_string( $args->{string} );
59 }
60  
61 0 return;
62 }
63  
64  
65 sub draw
66 {
67 0 ▶ my $self = shift;
Subroutine draw: not called CC=2 SCAR=17.9
Pod documented
68  
69 0 ▶ if ( !@{ $self->_undealt_cards() } )
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->_undealt_cards;}) 0 0 0
70 {
71 0 die "Cannot draw.";
72 }
73  
74 0 push @{ $self->_waste() }, shift( @{ $self->_undealt_cards() } );
75  
76 0 return;
77 }
78  
79  
80 sub extract_top
81 {
82 0 ▶ my $self = shift;
Subroutine extract_top: not called CC=2 SCAR=17.9
Pod documented
83  
84 0 ▶ if ( !@{ $self->_waste() } )
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->_waste;}) 0 0 0
85 {
86 0 die "Cannot extract_top.";
87 }
88  
89 0 return pop( @{ $self->_waste() } );
90 }
91  
92  
93 sub redeal
94 {
95 0 ▶ my $self = shift;
Subroutine redeal: not called CC=3 SCAR=24.8
Pod documented
96  
97 0 ▶ if ( @{ $self->_undealt_cards() } )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->_undealt_cards;}) 0 0 0
98 {
99 0 die "Cannot redeal while there are remaining cards.";
100 }
101  
102 0 ▶ if ( $self->_num_redeals_so_far() == $self->_max_num_redeals() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_num_redeals_so_far == $self->_max_num_redeals) 0 0 0
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() };
110  
111 0 $self->_waste( [] );
112  
113 0 return;
114 }
115  
116  
117 sub to_string
118 {
119 0 ▶ my $self = shift;
Subroutine to_string: not called CC=1 SCAR=6.9
Pod documented
120  
121 return join( " ",
122 0 "Talon:", ( map { $_->fast_s() } reverse @{ $self->_waste() } ),
123 0 '==>', ( map { $_->fast_s() } @{ $self->_undealt_cards() } ), '<==', );
124 }
125  
126 1 1; # End of Games::Solitaire::Verify::KlondikeTalon
127  
128 __END__
« blib/lib/Games/Solitaire/Verify/Solution/ExpandMultiCardMoves.pm ↑ Summary blib/lib/Games/Solitaire/Verify/FromOtherSolversBase.pm »