blib/lib/Games/Solitaire/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 SCAR 13.9
CC
4
Cov
98%
_init
3.1
_from_string
2.0
BEGIN
1.0
CRAP 4.0
« blib/lib/Games/Solitaire/Verify/Solution/Base.pm ↑ Summary blib/lib/Games/Solitaire/Verify/VariantsMap.pm »
1 package Games::Solitaire::Verify::Column;
2 23 $Games::Solitaire::Verify::Column::VERSION = '0.2402';
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 {
24 2237 ▶ my ( $self, $str ) = @_;
Subroutine _from_string: called CC=2 SCAR=6.9
25  
26 2237 ▶ if ( $str !~ s{\A:(?: )?}{} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($str =~ s/\A:(?: )?//) 2 2235 2237
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 2235 my @cards = split( / +/, $str );
34  
35 $self->_cards(
36 [
37 2235 map { Games::Solitaire::Verify::Card->new( { string => $_ } ) }
38 @cards
39 ]
40 );
41  
42 2235 $self->_recalc;
43  
44 2235 return;
45 }
46  
47 sub _init
48 {
49 2311 ▶ my ( $self, $args ) = @_;
Subroutine _init: called CC=3 SCAR=11.2
50  
51 2311 ▶ if ( exists( $args->{string} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args->{'string'}) { } 2237 74 2311
elsif (exists $args->{'cards'}) { } 74 0 74
52 {
53 2237 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 {
71 9847 ▶ my $self = shift;
Subroutine len: called CC=1 SCAR=0.0
Pod documented
72  
73 9847 return scalar( @{ $self->_cards() } );
74 }
75  
76  
77 sub pos
78 {
79 6014 ▶ my $self = shift;
Subroutine pos: called CC=1 SCAR=0.0
Pod documented
80 6014 my $idx = shift;
81  
82 6014 return $self->_cards->[$idx];
83 }
84  
85  
86 sub top
87 {
88 3272 ▶ my $self = shift;
Subroutine top: called CC=1 SCAR=0.0
Pod documented
89  
90 3272 return $self->pos(-1);
91 }
92  
93  
94 sub clone
95 {
96 58 ▶ my $self = shift;
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
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 {
110 613 ▶ my ( $S, $c ) = @_;
Subroutine append_cards: called CC=1 SCAR=0.0
Pod documented
111 613 push @{ $S->_cards() }, @$c;
112 613 $S->_recalc;
113 613 return;
114 }
115  
116  
117 sub append
118 {
119 1 ▶ my ( $self, $more_cards ) = @_;
Subroutine append: called CC=1 SCAR=0.0
Pod documented
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 {
129 466 ▶ my ( $self, $card ) = @_;
Subroutine push: called CC=1 SCAR=0.0
Pod documented
130  
131 466 push @{ $self->_cards() }, $card;
132  
133 466 $self->_recalc;
134  
135 466 return;
136 }
137  
138  
139 sub pop
140 {
141 1508 ▶ my $self = shift;
Subroutine pop: called CC=1 SCAR=0.0
Pod documented
142  
143 1508 my $card = pop( @{ $self->_cards() } );
144  
145 1508 $self->_recalc;
146  
147 1508 return $card;
148 }
149  
150  
151 sub popN
152 {
153 612 ▶ my ( $S, $c ) = @_;
Subroutine popN: called CC=1 SCAR=0.0
Pod documented
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 {
165 5508 ▶ my $self = shift;
Subroutine _recalc: called CC=1 SCAR=0.0
166  
167 $self->_s(
168 5508 join( ' ', ':', ( map { $_->fast_s() } @{ $self->_cards() } ) ) );
169  
170 5508 return;
171 }
172  
173 sub to_string
174 {
175 18170 ▶ return shift->_s;
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
176 }
177  
178 23 1; # End of Games::Solitaire::Verify::Column
179  
180 __END__
« blib/lib/Games/Solitaire/Verify/Solution/Base.pm ↑ Summary blib/lib/Games/Solitaire/Verify/VariantsMap.pm »