Domino/Tile.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 8 / 8 Conditioncond 100% 21 / 21 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 96.7% 90 / 93 CC 12 SCAR 19.9
CC
12
Cov
100%
__ANON__
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.3
« Domino.pm ↑ Summary Domino/Params.pm »
1 package Games::Domino::Tile;
2  
3 4 $Games::Domino::Tile::VERSION = '0.22';
4 4 $Games::Domino::Tile::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Games::Domino::Tile - Represents the tile of the Domino game.
9  
10 =head1 VERSION
11  
12 Version 0.22
13  
14 =cut
15  
16 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use Games::Domino::Params qw($ZeroOrOne $ZeroToSix);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 4 ▶use overload ('""' => \&as_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 4 has 'left' => (is => 'rw', isa => $ZeroToSix, required => 1);
26 4 has 'right' => (is => 'rw', isa => $ZeroToSix, required => 1);
27 4 has 'double' => (is => 'ro', isa => $ZeroOrOne, required => 1);
28 4 has 'top' => (is => 'rw', isa => $ZeroToSix);
29 4 has 'bottom' => (is => 'rw', isa => $ZeroToSix);
30 34 ▶has 'color' => (is => 'rw', default => sub { 'blue' });
Subroutine __ANON__: called CC=1 SCAR=0.0
31  
32 =head1 DESCRIPTION
33  
34 It is used internally by L<Games::Domino>.
35  
36 =cut
37  
38 around BUILDARGS => sub {
39 39 ▶ my $orig = shift;
Subroutine __ANON__: called CC=12 SCAR=24.8
40 39 my $class = shift;
41  
42 39 ▶ unless (exists $_[0]->{double}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $_[0]{"double"}) 8 31 39
43 8 ▶ if (defined($_[0]->{left})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]{'left'} and defined $_[0]{'right'} and $_[0]{'left'} == $_[0]{'right'}) { } 1 7 8
Condition100%6/6
defined $_[0]{"left"} and defined $_[0]{"right"} and $_[0]{"left"} == $_[0]{"right"}
!ll&&!rl&&r
251
defined $_[0]{"left"} and defined $_[0]{"right"}
!ll&&!rl&&r
116
MC/DC100%3/3
defined $_[0]{"left"} and defined $_[0]{"right"} and $_[0]{"left"} == $_[0]{"right"}
defined $_[0]{"left"} defined $_[0]{"right"} $_[0]{"left"} == $_[0]{"right"}
Truth table100%4/4
A and B and C
A= defined $_[0]{"left"}B= defined $_[0]{"right"}C= $_[0]{"left"} == $_[0]{"right"}
ABCresult
0XX0
10X0
1100
1111
44 && defined($_[0]->{right}) && ($_[0]->{left} == $_[0]->{right})) {
45 1 $_[0]->{double} = 1;
46 1 $_[0]->{top} = $_[0]->{bottom} = $_[0]->{left};
47 }
48 else {
49 7 $_[0]->{double} = 0;
50 }
51 }
52  
53 die("ERROR: Invalid double attribute for the tile.\n")
54 if (defined($_[0]->{left})
55 && defined($_[0]->{right})
56 && ( (($_[0]->{left} == $_[0]->{right}) && ($_[0]->{double} != 1))
57 ||
58 39 ▶ (($_[0]->{left} != $_[0]->{right}) && ($_[0]->{double} != 0))
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]{"left"} and defined $_[0]{"right"} and $_[0]{"left"} == $_[0]{"right"} && $_[0]{"double"} != 1 || $_[0]{"left"} != $_[0]{"right"} && $_[0]{"double"} != 0 3 36 39
Condition100%15/15
defined $_[0]{"left"} and defined $_[0]{"right"} and $_[0]{"left"} == $_[0]{"right"} && $_[0]{"double"} != 1 || $_[0]{"left"} != $_[0]{"right"} && $_[0]{"double"} != 0
!ll&&!rl&&r
2343
defined $_[0]{"left"} and defined $_[0]{"right"}
!ll&&!rl&&r
1137
$_[0]{"left"} == $_[0]{"right"} and $_[0]{"double"} != 1 or $_[0]{"left"} != $_[0]{"right"} and $_[0]{"double"} != 0
l!l&&r!l&&!r
1234
$_[0]{"left"} == $_[0]{"right"} and $_[0]{"double"} != 1
!ll&&!rl&&r
2881
$_[0]{"left"} != $_[0]{"right"} and $_[0]{"double"} != 0
!ll&&!rl&&r
8262
MC/DC50%3/6
defined $_[0]{"left"} and defined $_[0]{"right"} and $_[0]{"left"} == $_[0]{"right"} && $_[0]{"double"} != 1 || $_[0]{"left"} != $_[0]{"right"} && $_[0]{"double"} != 0
defined $_[0]{"left"} defined $_[0]{"right"} $_[0]{"left"} == $_[0]{"right"} $_[0]{"double"} != 1 $_[0]{"left"} != $_[0]{"right"} $_[0]{"double"} != 0
Truth table55%5/9
A and B and C and D or E and F
A= defined $_[0]{"left"}B= defined $_[0]{"right"}C= $_[0]{"left"} == $_[0]{"right"}D= $_[0]{"double"} != 1E= $_[0]{"left"} != $_[0]{"right"}F= $_[0]{"double"} != 0
ABCDEFresult
0XXXXX0
10XXXX0
110X0X0
110X100
11100X0
1110100
1111XX1
110X111
1110111
59 )
60 );
61  
62 36 ▶ if ($_[0]->{double} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"double"} == 1) 8 28 36
63 8 $_[0]->{top} = $_[0]->{bottom} = $_[0]->{left};
64 }
65  
66 36 return $class->$orig(@_);
67 4 };
68  
69 =head1 METHODS
70  
71 =head2 value()
72  
73 Returns the value of the tile i.e. sum of left and right bips.
74  
75 use strict; use warnings;
76 use Games::Domino::Tile;
77  
78 my $tile = Games::Domino::Tile->new({ left => 1, right => 4 });
79 print "Value of the tile is [" . $tile->value . "].\n";
80  
81 =cut
82  
83 sub value {
84 11 ▶ my ($self) = @_;
Subroutine value: called CC=1 SCAR=0.0
Pod documented
85  
86 11 return ($self->{left} + $self->{right});
87 }
88  
89 =head2 as_string()
90  
91 Returns the tile object as string. This method is overloaded as string context.So
92 if we print the object then this method gets called. You can explictly call this
93 method as well. Suppose the tile has 3 left pips and 6 right pips then this would
94 return it as [3 | 6].
95  
96 use strict; use warnings;
97 use Games::Domino::Tile;
98  
99 my $tile = Games::Domino::Tile->new({ left => 1, right => 4 });
100 print "The tile is $tile\n";
101 # same as above
102 print "The tile is " . $tile->as_string() . "\n";
103  
104 =cut
105  
106 sub as_string {
107 18 ▶ my ($self) = @_;
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
108  
109 18 return sprintf("[%d | %d]", $self->left, $self->right);
110 }
111  
112 =head1 AUTHOR
113  
114 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
115  
116 =head1 REPOSITORY
117  
118 L<https://github.com/manwar/Games-Domino>
119  
120 =head1 BUGS
121  
122 Please report any bugs or feature requests to C<bug-games-domino at rt.cpan.org>,
123 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Domino>.
124 I will be notified, and then you'll automatically be notified of progress on your
125 bug as I make changes.
126  
127 =head1 SUPPORT
128  
129 You can find documentation for this module with the perldoc command.
130  
131 perldoc Games::Domino::Tile
132  
133 You can also look for information at:
134  
135 =over 4
136  
137 =item * RT: CPAN's request tracker (report bugs here)
138  
139 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Domino>
140  
141 =item * AnnoCPAN: Annotated CPAN documentation
142  
143 L<http://annocpan.org/dist/Games-Domino>
144  
145 =item * CPAN Ratings
146  
147 L<http://cpanratings.perl.org/d/Games-Domino>
148  
149 =item * Search CPAN
150  
151 L<http://search.cpan.org/dist/Games-Domino/>
152  
153 =back
154  
155 =head1 LICENSE AND COPYRIGHT
156  
157 Copyright 2012 - 2015 Mohammad S Anwar.
158  
159 This program is free software; you can redistribute it and / or modify it under
160 the terms of the the Artistic License (2.0). You may obtain a copy of the full
161 license at:
162  
163 L<http://www.perlfoundation.org/artistic_license_2_0>
164  
165 Any use, modification, and distribution of the Standard or Modified Versions is
166 governed by this Artistic License.By using, modifying or distributing the Package,
167 you accept this license. Do not use, modify, or distribute the Package, if you do
168 not accept this license.
169  
170 If your Modified Version has been derived from a Modified Version made by someone
171 other than you,you are nevertheless required to ensure that your Modified Version
172 complies with the requirements of this license.
173  
174 This license does not grant you the right to use any trademark, service mark,
175 tradename, or logo of the Copyright Holder.
176  
177 This license includes the non-exclusive, worldwide, free-of-charge patent license
178 to make, have made, use, offer to sell, sell, import and otherwise transfer the
179 Package with respect to any patent claims licensable by the Copyright Holder that
180 are necessarily infringed by the Package. If you institute patent litigation
181 (including a cross-claim or counterclaim) against any party alleging that the
182 Package constitutes direct or contributory patent infringement,then this Artistic
183 License to you shall terminate on the date that such litigation is filed.
184  
185 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
186 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
187 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
188 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
189 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
190 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
191 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
192  
193 =cut
194  
195 4 1; # End of Games::Domino::Tile
« Domino.pm ↑ Summary Domino/Params.pm »