Pair/Card.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 91.6% 11 / 12 Conditioncond 83.3% 20 / 24 MC/DCmcdc 63.6% 7 / 11 Subroutinesub 100% 10 / 10 Podpod 66.6% 2 / 3 totaltotal 88.7% 87 / 98 CC 15 SCAR 17.6
CC
15
Cov
92%
equal
10.3
BUILDARGS
5.0
as_string
2.3
CRAP 5.8
↑ Summary Pair.pm »
1 package Games::Cards::Pair::Card;
2  
3 5 $Games::Cards::Pair::Card::VERSION = '0.19';
4 5 $Games::Cards::Pair::Card::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Games::Cards::Pair::Card - Object representation of a card.
9  
10 =head1 VERSION
11  
12 Version 0.19
13  
14 =cut
15  
16 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Types::Standard qw(Int);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Games::Cards::Pair::Params qw(Value Suit);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 5 ▶use overload ( '""' => \&as_string );
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 5 has 'index' => (is => 'rw', isa => Int );
27 5 has 'suit' => (is => 'ro', isa => Suit);
28 5 has 'value' => (is => 'ro', isa => Value, required => 1);
29  
30 =head1 DESCRIPTION
31  
32 Only for internal use of Games::Cards::Pair class. Avoid using it directly.
33  
34 =cut
35  
36 sub BUILDARGS {
37 42 ▶ my ($class, $args) = @_;
Subroutine BUILDARGS: called CC=5 SCAR=16.1
Pod undocumented
38  
39 42 ▶ if (defined($args->{'value'}) && ($args->{'value'} =~ /Joker/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'value'} and $args->{'value'} =~ /Joker/i) { } 7 35 42
Condition100%3/3
defined $args->{"value"} and $args->{"value"} =~ /Joker/i
!ll&&!rl&&r
2337
MC/DC100%2/2
defined $args->{"value"} and $args->{"value"} =~ /Joker/i
defined $args->{"value"} $args->{"value"} =~ /Joker/i
Truth table100%3/3
A and B
A= defined $args->{"value"}B= $args->{"value"} =~ /Joker/i
ABresult
0X0
100
111
40 7 ▶ die("Attribute (suit) is NOT required for Joker.") if defined $args->{'suit'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"suit"} 1 6 7
41 }
42 else {
43 35 ▶ die("Attribute (suit) is required.") unless defined $args->{'suit'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"suit"} 2 33 35
44 }
45  
46 39 return $args;
47 };
48  
49 =head1 METHODS
50  
51 =head2 equal()
52  
53 Returns 1 or 0 depending whether the two cards are same in value or one of them is a Joker.
54  
55 use strict; use warnings;
56 use Games::Cards::Pair::Card;
57  
58 my ($card1, $card2);
59 $card1 = Games::Cards::Pair::Card->new({ suit => 'Clubs', value => '2' });
60 $card2 = Games::Cards::Pair::Card->new({ suit => 'Diamonds', value => '2' });
61 print "Card are the same.\n" if $card1->equal($card2);
62  
63 $card2 = Games::Cards::Pair::Card->new({ value => 'Joker' });
64 print "Card are the same.\n" if $card1->equal($card2);
65  
66 =cut
67  
68 sub equal {
69 7 ▶ my ($self, $other) = @_;
Subroutine equal: called CC=10 SCAR=23.3
Pod documented
70  
71 7 ▶ return 0 unless (defined($other) && (ref($other) eq 'Games::Cards::Pair::Card'));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other and ref $other eq "Games::Cards::Pair::Card" 2 5 7
Condition100%3/3
defined $other and ref $other eq "Games::Cards::Pair::Card"
!ll&&!rl&&r
115
MC/DC100%2/2
defined $other and ref $other eq "Games::Cards::Pair::Card"
defined $other ref $other eq "Games::Cards::Pair::Card"
Truth table100%3/3
A and B
A= defined $otherB= ref $other eq "Games::Cards::Pair::Card"
ABresult
0X0
100
111
72  
73 return 1
74 if ((defined($self->{value}) && ($self->{value} =~ /Joker/i))
75 ||
76 (defined($other->{value}) && ($other->{value} =~ /Joker/i))
77 ||
78 5 ▶ (defined($self->{value}) && (defined($other->{value}) && (lc($self->{value}) eq lc($other->{value})))));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"value"} and $self->{"value"} =~ /Joker/i or defined $other->{"value"} and $other->{"value"} =~ /Joker/i or defined $self->{"value"} and (defined $other->{"value"} and lc $self->{"value"} eq lc $other->{"value"}) 3 1 4
Condition77%14/18
defined $self->{"value"} and $self->{"value"} =~ /Joker/i or defined $other->{"value"} and $other->{"value"} =~ /Joker/i or defined $self->{"value"} and (defined $other->{"value"} and lc $self->{"value"} eq lc $other->{"value"})
l!l&&r!l&&!r
311
defined $self->{"value"} and $self->{"value"} =~ /Joker/i or defined $other->{"value"} and $other->{"value"} =~ /Joker/i
l!l&&r!l&&!r
122
defined $self->{"value"} and $self->{"value"} =~ /Joker/i
!ll&&!rl&&r
041
defined $other->{"value"} and $other->{"value"} =~ /Joker/i
!ll&&!rl&&r
022
defined $self->{"value"} and (defined $other->{"value"} and lc $self->{"value"} eq lc $other->{"value"})
!ll&&!rl&&r
011
defined $other->{"value"} and lc $self->{"value"} eq lc $other->{"value"}
!ll&&!rl&&r
011
MC/DC42%3/7
defined $self->{"value"} and $self->{"value"} =~ /Joker/i or defined $other->{"value"} and $other->{"value"} =~ /Joker/i or defined $self->{"value"} and (defined $other->{"value"} and lc $self->{"value"} eq lc $other->{"value"})
defined $self->{"value"} $self->{"value"} =~ /Joker/i defined $other->{"value"} $other->{"value"} =~ /Joker/i defined $self->{"value"} defined $other->{"value"} lc $self->{"value"} eq lc $other->{"value"}
Truth table21%4/19
A and B or C and D or E and F and G
A= defined $self->{"value"}B= $self->{"value"} =~ /Joker/iC= defined $other->{"value"}D= $other->{"value"} =~ /Joker/iE= defined $self->{"value"}F= defined $other->{"value"}G= lc $self->{"value"} eq lc $other->{"value"}
ABCDEFGresult
11XXXXX1
0X11XXX1
1011XXX1
0X0X1111
0X101111
100X1111
10101111
0X0X0XX0
0X0X10X0
0X0X1100
0X100XX0
0X1010X0
0X101100
100X0XX0
100X10X0
100X1100
10100XX0
101010X0
10101100
79  
80 1 return 0;
81 }
82  
83 =head2 as_string()
84  
85 Returns the card object in readable format. This is overloaded as string context for printing.
86  
87 use strict; use warnings;
88 use Games::Cards::Pair::Card;
89  
90 my $card = Games::Cards::Pair::Card->new({ suit => 'Clubs', value => '2' });
91 print "Card: $card\n";
92 # or
93 print "Card: " . $card->as_string() . "\n";
94  
95 =cut
96  
97 sub as_string {
98 10 ▶ my ($self) = @_;
Subroutine as_string: called CC=2 SCAR=8.1
Pod documented
99  
100 10 ▶ return sprintf("%4s%s", $self->value, $self->suit) if defined $self->suit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->suit 10 0 10
101  
102 0 return sprintf("%5s", $self->value);
103 }
104  
105 =head1 AUTHOR
106  
107 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
108  
109 =head1 REPOSITORY
110  
111 L<https://github.com/manwar/Games-Cards-Pair>
112  
113 =head1 BUGS
114  
115 Please report any bugs / feature requests to C<bug-games-cards-pair at rt.cpan.org>,or through
116 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Cards-Pair>.I will
117 be notified, & then you'll automatically be notified of progress on your bug as I make changes.
118  
119 =head1 SUPPORT
120  
121 You can find documentation for this module with the perldoc command.
122  
123 perldoc Games::Cards::Pair::Card
124  
125 You can also look for information at:
126  
127 =over 4
128  
129 =item * RT: CPAN's request tracker (report bugs here)
130  
131 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Cards-Pair>
132  
133 =item * AnnoCPAN: Annotated CPAN documentation
134  
135 L<http://annocpan.org/dist/Games-Cards-Pair>
136  
137 =item * CPAN Ratings
138  
139 L<http://cpanratings.perl.org/d/Games-Cards-Pair>
140  
141 =item * Search CPAN
142  
143 L<http://search.cpan.org/dist/Games-Cards-Pair/>
144  
145 =back
146  
147 =head1 LICENSE AND COPYRIGHT
148  
149 Copyright (C) 2012 - 2016 Mohammad S Anwar.
150  
151 This program is free software; you can redistribute it and / or modify it under
152 the terms of the the Artistic License (2.0). You may obtain a copy of the full
153 license at:
154  
155 L<http://www.perlfoundation.org/artistic_license_2_0>
156  
157 Any use, modification, and distribution of the Standard or Modified Versions is
158 governed by this Artistic License.By using, modifying or distributing the Package,
159 you accept this license. Do not use, modify, or distribute the Package, if you do
160 not accept this license.
161  
162 If your Modified Version has been derived from a Modified Version made by someone
163 other than you,you are nevertheless required to ensure that your Modified Version
164 complies with the requirements of this license.
165  
166 This license does not grant you the right to use any trademark, service mark,
167 tradename, or logo of the Copyright Holder.
168  
169 This license includes the non-exclusive, worldwide, free-of-charge patent license
170 to make, have made, use, offer to sell, sell, import and otherwise transfer the
171 Package with respect to any patent claims licensable by the Copyright Holder that
172 are necessarily infringed by the Package. If you institute patent litigation
173 (including a cross-claim or counterclaim) against any party alleging that the
174 Package constitutes direct or contributory patent infringement,then this Artistic
175 License to you shall terminate on the date that such litigation is filed.
176  
177 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
178 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
179 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
180 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
181 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
182 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
183 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
184  
185 =cut
186  
187 5 1; # End of Games::Cards::Pair::Card
↑ Summary Pair.pm »