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

filter: Statementstmt 31.3% 21 / 67 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod 100% 4 / 4 totaltotal 32.6% 31 / 95 CC 7 SCAR 16.3
CC
7
Cov
27%
redeal
12.0
_input_from_string
6.0
_init
6.0
CRAP 5.1
« blib/lib/Games/Solitaire/Verify/Solution/ExpandMultiCardMoves.pm ↑ Summary blib/lib/Games/Solitaire/Verify/Solution.pm »
1 package Games::Solitaire::Verify::KlondikeTalon;
2 1 $Games::Solitaire::Verify::KlondikeTalon::VERSION = '0.2301';
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 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 __PACKAGE__->mk_acc_ref(
15 [
16 qw(
17 _max_num_redeals
18 _num_redeals_so_far
19 _undealt_cards
20 _waste
21 )
22 ]
23 );
24  
25  
26 sub _input_from_string
27 {
28 0 ▶ my $self = shift;
Subroutine _input_from_string: not called CC=2 SCAR=17.9
29 0 my $str = shift;
30  
31 0 ▶ if ( my ($cards_str) = ( $str =~ /\ATalon: (.*)\z/ms ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my($cards_str) = $str =~ /\ATalon: (.*)\z/ms) { } 0 0 0
32 {
33 $self->_undealt_cards(
34 [
35 0 map { Games::Solitaire::Verify::Card->new( { string => $_, } ) }
36 split /\s+/,
37 $cards_str
38 ]
39 );
40 }
41 else
42 {
43 0 die "Wrong format - does not start with Talon.";
44 }
45 }
46  
47 sub _init
48 {
49 0 ▶ my ( $self, $args ) = @_;
Subroutine _init: not called CC=2 SCAR=17.9
50  
51 0 $self->_max_num_redeals( $args->{max_num_redeals} );
52  
53 0 $self->_num_redeals_so_far(0);
54  
55 0 $self->_undealt_cards( [] );
56 0 $self->_waste( [] );
57  
58 0 ▶ if ( exists( $args->{string} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"string"}) 0 0 0
59 {
60 0 $self->_input_from_string( $args->{string} );
61 }
62  
63 0 return;
64 }
65  
66  
67 sub draw
68 {
69 0 ▶ my $self = shift;
Subroutine draw: not called CC=2 SCAR=17.9
Pod documented
70  
71 0 ▶ if ( !@{ $self->_undealt_cards() } )
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->_undealt_cards;}) 0 0 0
72 {
73 0 die "Cannot draw.";
74 }
75  
76 0 push @{ $self->_waste() }, shift( @{ $self->_undealt_cards() } );
77  
78 0 return;
79 }
80  
81  
82 sub extract_top
83 {
84 0 ▶ my $self = shift;
Subroutine extract_top: not called CC=2 SCAR=17.9
Pod documented
85  
86 0 ▶ if ( !@{ $self->_waste() } )
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->_waste;}) 0 0 0
87 {
88 0 die "Cannot extract_top.";
89 }
90  
91 0 return pop( @{ $self->_waste() } );
92 }
93  
94  
95 sub redeal
96 {
97 0 ▶ my $self = shift;
Subroutine redeal: not called CC=3 SCAR=24.8
Pod documented
98  
99 0 ▶ if ( @{ $self->_undealt_cards() } )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->_undealt_cards;}) 0 0 0
100 {
101 0 die "Cannot redeal while there are remaining cards.";
102 }
103  
104 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
105 {
106 0 die "Cannot redeal because maximal number exceeded.";
107 }
108  
109 0 $self->_num_redeals_so_far( $self->_num_redeals_so_far() + 1 );
110  
111 0 push @{ $self->_undealt_cards() }, @{ $self->_waste() };
112  
113 0 $self->_waste( [] );
114  
115 0 return;
116 }
117  
118  
119 sub to_string
120 {
121 0 ▶ my $self = shift;
Subroutine to_string: not called CC=1 SCAR=6.9
Pod documented
122  
123 return join( " ",
124 0 "Talon:", ( map { $_->fast_s() } reverse @{ $self->_waste() } ),
125 0 '==>', ( map { $_->fast_s() } @{ $self->_undealt_cards() } ), '<==', );
126 }
127  
128 1 1; # End of Games::Solitaire::Verify::KlondikeTalon
129  
130 __END__
« blib/lib/Games/Solitaire/Verify/Solution/ExpandMultiCardMoves.pm ↑ Summary blib/lib/Games/Solitaire/Verify/Solution.pm »