Verify/Column.pm

filter: Statementstmt 98.6% 74 / 75 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 18 / 18 Podpod 100% 10 / 10 totaltotal 98.1% 107 / 109 CC 4 SCAR 3.3
CC
4
Cov
98%
_init
3.1
_from_string
2.0
BEGIN
1.0
CRAP 1.4
« Verify/Solution/ExpandMultiCardMoves/Lax.pm ↑ Summary Verify/App/Golf.pm »
1 package Games::Solitaire::Verify::Column;
2 23 $Games::Solitaire::Verify::Column::VERSION = '0.2601';
3 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 23 ▶use parent 'Games::Solitaire::Verify::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 ▶use Games::Solitaire::Verify::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 23 ▶use Games::Solitaire::Verify::Card ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 23 __PACKAGE__->mk_acc_ref(
13 [
14 qw(
15 _cards
16 _s
17 )
18 ]
19 );
20  
21  
22 sub _from_string
23 2254 ▶{
Subroutine _from_string: called CC=2 SCAR=6.9
24 2254 my ( $self, $str ) = @_;
25  
26 2254 ▶ if ( $str !~ s{\A:(?: )?}{} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($str =~ s/\A:(?: )?//) 2 2252 2254
27 {
28 2 Games::Solitaire::Verify::Exception::Parse::Column::Prefix->throw(
29 error => "String does not start with \": \"", );
30 }
31  
32 # Ignore trailing whitespace, so we don't have -1.
33 2252 my @cards = split( / +/, $str );
34  
35 $self->_cards(
36 [
37 2252 map { Games::Solitaire::Verify::Card->new( { string => $_ } ) }
38 @cards
39 ]
40 );
41  
42 2252 $self->_recalc;
43  
44 2252 return ();
45 }
46  
47 sub _init
48 2328 ▶{
Subroutine _init: called CC=3 SCAR=11.2
49 2328 my ( $self, $args ) = @_;
50  
51 2328 ▶ if ( exists( $args->{string} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args->{'string'}) { } 2254 74 2328
elsif (exists $args->{'cards'}) { } 74 0 74
52 {
53 2254 return $self->_from_string( $args->{string} );
54 }
55 elsif ( exists( $args->{cards} ) )
56 {
57 74 $self->_cards( $args->{cards} );
58  
59 74 $self->_recalc;
60 74 return ();
61 }
62 else
63 {
64 0 die "Cannot init - no 'string' or 'cards' specified.";
65 }
66 }
67  
68  
69 sub len
70 9864 ▶{
Subroutine len: called CC=1 SCAR=0.0
Pod documented
71 9864 my $self = shift;
72  
73 9864 return scalar( @{ $self->_cards() } );
74 }
75  
76  
77 sub pos
78 6116 ▶{
Subroutine pos: called CC=1 SCAR=0.0
Pod documented
79 6116 my $self = shift;
80 6116 my $idx = shift;
81  
82 6116 return $self->_cards->[$idx];
83 }
84  
85  
86 sub top
87 3374 ▶{
Subroutine top: called CC=1 SCAR=0.0
Pod documented
88 3374 my $self = shift;
89  
90 3374 return $self->pos(-1);
91 }
92  
93  
94 sub clone
95 58 ▶{
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
96 58 my $self = shift;
97  
98 my $new_col = Games::Solitaire::Verify::Column->new(
99 {
100 58 cards => [ map { $_->clone() } @{ $self->_cards() } ],
101 }
102 );
103  
104 58 return $new_col;
105 }
106  
107  
108 sub append_cards
109 613 ▶{
Subroutine append_cards: called CC=1 SCAR=0.0
Pod documented
110 613 my ( $S, $c ) = @_;
111 613 push @{ $S->_cards() }, @$c;
112 613 $S->_recalc;
113 613 return ();
114 }
115  
116  
117 sub append
118 1 ▶{
Subroutine append: called CC=1 SCAR=0.0
Pod documented
119 1 my ( $self, $more_cards ) = @_;
120  
121 1 my $more_copy = $more_cards->clone();
122  
123 1 return $self->append_cards( $more_copy->_cards );
124 }
125  
126  
127 sub push
128 466 ▶{
Subroutine push: called CC=1 SCAR=0.0
Pod documented
129 466 my ( $self, $card ) = @_;
130  
131 466 push @{ $self->_cards() }, $card;
132  
133 466 $self->_recalc;
134  
135 466 return ();
136 }
137  
138  
139 sub pop
140 1610 ▶{
Subroutine pop: called CC=1 SCAR=0.0
Pod documented
141 1610 my $self = shift;
142  
143 1610 my $card = pop( @{ $self->_cards() } );
144  
145 1610 $self->_recalc;
146  
147 1610 return $card;
148 }
149  
150  
151 sub popN
152 612 ▶{
Subroutine popN: called CC=1 SCAR=0.0
Pod documented
153 612 my ( $S, $c ) = @_;
154  
155 612 my @r = splice( @{ $S->_cards() }, -$c );
156  
157 612 $S->_recalc;
158  
159 612 return \@r;
160 }
161  
162  
163 sub _recalc
164 5627 ▶{
Subroutine _recalc: called CC=1 SCAR=0.0
165 5627 my $self = shift;
166  
167 $self->_s(
168 5627 join( ' ', ':', ( map { $_->fast_s() } @{ $self->_cards() } ) ) );
169  
170 5627 return ();
171 }
172  
173 sub to_string
174 19904 ▶{
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
175 19904 return shift->_s;
176 }
177  
178 23 1; # End of Games::Solitaire::Verify::Column
179  
180 __END__
« Verify/Solution/ExpandMultiCardMoves/Lax.pm ↑ Summary Verify/App/Golf.pm »