File Coverage

blib/lib/Games/Solitaire/Verify/Move.pm
Criterion Covered Total %
statement 47 48 97.9
branch 13 14 92.8
condition n/a
subroutine 6 6 100.0
pod n/a
total 66 68 97.0


line stmt bran cond sub pod time code
1             package Games::Solitaire::Verify::Move;
2             $Games::Solitaire::Verify::Move::VERSION = '0.2601';
3 20     20   505946 use warnings;
  20         39  
  20         1220  
4 20     20   126 use strict;
  20         66  
  20         601  
5              
6              
7 20     20   932 use parent 'Games::Solitaire::Verify::Base';
  20         678  
  20         126  
8              
9 20     20   2893 use Games::Solitaire::Verify::Exception ();
  20         68  
  20         13602  
10              
11             __PACKAGE__->mk_acc_ref(
12             [
13             qw(
14             source_type
15             dest_type
16             source
17             dest
18             num_cards
19             _game
20             )
21             ]
22             );
23              
24              
25             sub _from_fcs_string
26             {
27 2551     2551   4714 my ( $self, $str ) = @_;
28              
29 2551 100       15060 if ( $str =~ m{\AMove a card from stack ([0-9]+) to the foundations\z} )
    100          
    100          
    100          
    100          
    100          
30             {
31 659         1605 my $source = $1;
32              
33 659         1414 $self->source_type("stack");
34 659         1212 $self->dest_type("foundation");
35              
36 659         1975 $self->source($source);
37             }
38             elsif (
39             $str =~ m{\AMove a card from freecell ([0-9]+) to the foundations\z} )
40             {
41 116         285 my $source = $1;
42              
43 116         271 $self->source_type("freecell");
44 116         255 $self->dest_type("foundation");
45              
46 116         348 $self->source($source);
47             }
48             elsif (
49             $str =~ m{\AMove a card from freecell ([0-9]+) to stack ([0-9]+)\z} )
50             {
51 475         1903 my ( $source, $dest ) = ( $1, $2 );
52              
53 475         1229 $self->source_type("freecell");
54 475         1011 $self->dest_type("stack");
55              
56 475         1034 $self->source($source);
57 475         1666 $self->dest($dest);
58             }
59             elsif (
60             $str =~ m{\AMove a card from stack ([0-9]+) to freecell ([0-9]+)\z} )
61             {
62 591         2003 my ( $source, $dest ) = ( $1, $2 );
63              
64 591         1445 $self->source_type("stack");
65 591         1230 $self->dest_type("freecell");
66              
67 591         1248 $self->source($source);
68 591         1880 $self->dest($dest);
69             }
70             elsif ( $str =~
71             m{\AMove ([0-9]+) cards from stack ([0-9]+) to stack ([0-9]+)\z} )
72             {
73 702         3073 my ( $num_cards, $source, $dest ) = ( $1, $2, $3 );
74              
75 702         1725 $self->source_type("stack");
76 702         1440 $self->dest_type("stack");
77              
78 702         1437 $self->source($source);
79 702         1435 $self->dest($dest);
80 702         2703 $self->num_cards($num_cards);
81             }
82             elsif ( $str =~
83             m{\AMove the sequence on top of Stack ([0-9]+) to the foundations\z} )
84             {
85 7         20 my $source = $1;
86              
87 7         22 $self->source_type("stack_seq");
88 7         17 $self->dest_type("foundation");
89              
90 7         25 $self->source($source);
91             }
92             else
93             {
94 1         60 Games::Solitaire::Verify::Exception::Parse::FCS->throw(
95             error => "Cannot parse 'FCS' String", );
96             }
97             }
98              
99             sub _init
100             {
101 2551     2551   4881 my ( $self, $args ) = @_;
102              
103 2551         7382 $self->_game( $args->{game} );
104              
105 2551 50       5903 if ( exists( $args->{fcs_string} ) )
106             {
107 2551         5426 return $self->_from_fcs_string( $args->{fcs_string} );
108             }
109 0           return ();
110             }
111              
112              
113             1; # End of Games::Solitaire::Verify::Move
114              
115             __END__