PNG/Brick.pm

filter: Statementstmt 23.2% 17 / 73 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 37.5% 6 / 16 Podpod 100% 10 / 10 totaltotal 23.2% 33 / 142 CC 17 SCAR 36.3
CC
17
Cov
16%
new
110.0
color
12.0
identifier
6.0
CRAP 37.6
« PNG/View/HTML.pm ↑ Summary PNG/View.pm »
1 package Lego::From::PNG::Brick;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $Lego::From::PNG::Brick::VERSION = '0.04';
8 }
9  
10 2 ▶use Lego::From::PNG::Const qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Data::Debug;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod documented
15 0 my $class = shift;
16 0 ▶ my %args = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
17  
18 0 my $hash = {};
19  
20 0 $hash->{$_} = $args{$_} for(qw(color depth length height meta));
21  
22 0 ▶ die "Invalid color" if ! scalar( grep { $_ eq $hash->{'color'} } LEGO_COLORS );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar grep({$_ eq $hash->{"color"};} ("AQUA", "BLACK", "BRICK_YELLOW", "BRIGHT_BLUE", "BRIGHT_GREEN", "BRIGHT_ORANGE", "BRIGHT_PURPLE", "BRIGHT_RED", "BRIGHT_REDDISH_VIOLET", "BRIGHT_YELLOW", "BRIGHT_YELLOWISH_GREEN", "COOL_YELLOW", "DARK_AZUR", "DARK_BROWN", "DARK_GREEN", "DARK_ORANGE", "DARK_RED", "DARK_STONE_GREY", "EARTH_BLUE", "EARTH_GREEN", "FLAME_YELLOWISH_ORANGE", "LAVENDER", "LIGHT_NOUGAT", "LIGHT_PURPLE", "LIGHT_ROYAL_BLUE", "LIGHT_STONE_GREY", "MEDIUM_AZUR", "MEDIUM_BLUE", "MEDIUM_LAVENDER", "MEDIUM_LILAC", "MEDIUM_NOUGAT", "MEDIUM_STONE_GREY", "MEDIUM_YELLOWISH_GREEN", "NOUGAT", "OLIVE_GREEN", "REDDISH_BROWN", "SAND_BLUE", "SAND_GREEN", "SAND_YELLOW", "SPRING_YELLOWISH_GREEN", "WHITE", "WHITE_GLOW")) 0 0 0
23  
24 # Default any undefined dimensions to 1
25 0 ▶ $hash->{'depth'} ||= 1;
Condition0%0/2
$hash->{"depth"} ||= 1
l!l
00
MC/DC0%0/1
$hash->{"depth"} ||= 1
$hash->{"depth"}
Truth table0%0/2
A
A= $hash->{"depth"}
Aresult
11
00
26 0 ▶ $hash->{'length'} ||= 1;
Condition0%0/2
$hash->{"length"} ||= 1
l!l
00
MC/DC0%0/1
$hash->{"length"} ||= 1
$hash->{"length"}
Truth table0%0/2
A
A= $hash->{"length"}
Aresult
11
00
27 0 ▶ $hash->{'height'} ||= 1;
Condition0%0/2
$hash->{"height"} ||= 1
l!l
00
MC/DC0%0/1
$hash->{"height"} ||= 1
$hash->{"height"}
Truth table0%0/2
A
A= $hash->{"height"}
Aresult
11
00
28  
29 # Default meta to an empty hashref if it is undefined or an invalid ref
30 0 ▶ $hash->{'meta'} = (! $hash->{'meta'} || ref($hash->{'meta'}) ne 'HASH') ? {} : $hash->{'meta'};
Branch: 1 branch
BranchTrueFalseTotal
!$hash->{'meta'} || ref $hash->{'meta'} ne 'HASH' ? : 0 0 0
Condition0%0/3
not $hash->{"meta"} or ref $hash->{"meta"} ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $hash->{"meta"} or ref $hash->{"meta"} ne "HASH"
not $hash->{"meta"} ref $hash->{"meta"} ne "HASH"
Truth table0%0/3
not(A) or B
A= not $hash->{"meta"}B= ref $hash->{"meta"} ne "HASH"
ABresult
1X1
011
000
31  
32 0 ▶ my $self = bless ($hash, ref ($class) || $class);
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
33  
34 0 return $self;
35 }
36  
37 0 ▶sub id { &identifier }
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
38 0 ▶sub identifier {
Subroutine identifier: not called CC=2 SCAR=17.9
Pod documented
39 0 my $self = shift;
40  
41 0 ▶ return $self->{'id'} ||= $self->color.'_'.join('x',$self->depth,$self->length,$self->height);
Condition0%0/2
$self->{"id"} ||= $self->color . '_' . join("x", $self->depth, $self->length, $self->height)
l!l
00
MC/DC0%0/1
$self->{"id"} ||= $self->color . '_' . join("x", $self->depth, $self->length, $self->height)
$self->{"id"}
Truth table0%0/2
A
A= $self->{"id"}
Aresult
11
00
42 }
43  
44 0 ▶sub color {
Subroutine color: not called CC=3 SCAR=24.8
Pod documented
45 0 my $self = shift;
46 0 my $val = shift;
47  
48 0 ▶ if(defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
49 0 ▶ die "Invalid color" if ! scalar( grep { $_ eq $val } LEGO_COLORS );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar grep({$_ eq $val;} ("AQUA", "BLACK", "BRICK_YELLOW", "BRIGHT_BLUE", "BRIGHT_GREEN", "BRIGHT_ORANGE", "BRIGHT_PURPLE", "BRIGHT_RED", "BRIGHT_REDDISH_VIOLET", "BRIGHT_YELLOW", "BRIGHT_YELLOWISH_GREEN", "COOL_YELLOW", "DARK_AZUR", "DARK_BROWN", "DARK_GREEN", "DARK_ORANGE", "DARK_RED", "DARK_STONE_GREY", "EARTH_BLUE", "EARTH_GREEN", "FLAME_YELLOWISH_ORANGE", "LAVENDER", "LIGHT_NOUGAT", "LIGHT_PURPLE", "LIGHT_ROYAL_BLUE", "LIGHT_STONE_GREY", "MEDIUM_AZUR", "MEDIUM_BLUE", "MEDIUM_LAVENDER", "MEDIUM_LILAC", "MEDIUM_NOUGAT", "MEDIUM_STONE_GREY", "MEDIUM_YELLOWISH_GREEN", "NOUGAT", "OLIVE_GREEN", "REDDISH_BROWN", "SAND_BLUE", "SAND_GREEN", "SAND_YELLOW", "SPRING_YELLOWISH_GREEN", "WHITE", "WHITE_GLOW")) 0 0 0
50  
51 0 $self->{'color'} = $val;
52  
53 0 delete $self->{'id'}; # Clear out id
54 0 delete $self->{'color_info'}; # Clear out color info on color change
55 }
56  
57 0 return $self->{'color'};
58 }
59  
60 0 ▶sub depth {
Subroutine depth: not called CC=2 SCAR=17.9
Pod documented
61 0 my $self = shift;
62 0 my $val = shift;
63  
64 0 ▶ if(defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
65 0 $self->{'depth'} = $val * 1;
66  
67 0 delete $self->{'id'}; # Clear out id
68 }
69  
70 0 return $self->{'depth'};
71 }
72  
73 0 ▶sub length {
Subroutine length: not called CC=2 SCAR=17.9
Pod documented
74 0 my $self = shift;
75 0 my $val = shift;
76  
77 0 ▶ if(defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
78 0 $self->{'length'} = $val * 1;
79  
80 0 delete $self->{'id'}; # Clear out id
81 }
82  
83 0 return $self->{'length'};
84 }
85  
86 0 ▶sub height {
Subroutine height: not called CC=2 SCAR=17.9
Pod documented
87 0 my $self = shift;
88 0 my $val = shift;
89  
90 0 ▶ if(defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
91 0 $self->{'height'} = $val * 1;
92  
93 0 delete $self->{'id'}; # Clear out id
94 }
95  
96 0 return $self->{'height'};
97 }
98  
99 0 ▶sub meta { shift->{'meta'} }
Subroutine meta: not called CC=1 SCAR=6.9
Pod documented
100  
101 0 ▶sub color_info {
Subroutine color_info: not called CC=2 SCAR=12.6
Pod documented
102 0 my $self = shift;
103  
104 0 ▶ return $self->{'color_info'} ||= do {
Condition0%0/3
$self->{"color_info"} ||= do { my $color = $self->color; () = ($color . '_OFFICIAL_NAME', $color . '_COMMON_NAME', $color . '_HEX_COLOR', $color . '_RGB_COLOR_RED', $color . '_RGB_COLOR_GREEN', $color . '_RGB_COLOR_BLUE'); no strict 'refs'; +{"cid", $color, "official_name", "Lego::From::PNG::Const"->$on_key, "common_name", "Lego::From::PNG::Const"->$cn_key, "hex_color", "Lego::From::PNG::Const"->$hex_key, "rgb_color", ["Lego::From::PNG::Const"->$r_key, "Lego::From::PNG::Const"->$g_key, "Lego::From::PNG::Const"->$b_key]} }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"color_info"} ||= do { my $color = $self->color; () = ($color . '_OFFICIAL_NAME', $color . '_COMMON_NAME', $color . '_HEX_COLOR', $color . '_RGB_COLOR_RED', $color . '_RGB_COLOR_GREEN', $color . '_RGB_COLOR_BLUE'); no strict 'refs'; +{"cid", $color, "official_name", "Lego::From::PNG::Const"->$on_key, "common_name", "Lego::From::PNG::Const"->$cn_key, "hex_color", "Lego::From::PNG::Const"->$hex_key, "rgb_color", ["Lego::From::PNG::Const"->$r_key, "Lego::From::PNG::Const"->$g_key, "Lego::From::PNG::Const"->$b_key]} }
$self->{"color_info"} do { my $color = $self->color; () = ($color . '_OFFICIAL_NAME', $color . '_COMMON_NAME', $color . '_HEX_COLOR', $color . '_RGB_COLOR_RED', $color . '_RGB_COLOR_GREEN', $color . '_RGB_COLOR_BLUE'); no strict 'refs'; +{"cid", $color, "official_name", "Lego::From::PNG::Const"->$on_key, "common_name", "Lego::From::PNG::Const"->$cn_key, "hex_color", "Lego::From::PNG::Const"->$hex_key, "rgb_color", ["Lego::From::PNG::Const"->$r_key, "Lego::From::PNG::Const"->$g_key, "Lego::From::PNG::Const"->$b_key]} }
Truth table0%0/3
A ||= B
A= $self->{"color_info"}B= do { my $color = $self->color; () = ($color . '_OFFICIAL_NAME', $color . '_COMMON_NAME', $color . '_HEX_COLOR', $color . '_RGB_COLOR_RED', $color . '_RGB_COLOR_GREEN', $color . '_RGB_COLOR_BLUE'); no strict 'refs'; +{"cid", $color, "official_name", "Lego::From::PNG::Const"->$on_key, "common_name", "Lego::From::PNG::Const"->$cn_key, "hex_color", "Lego::From::PNG::Const"->$hex_key, "rgb_color", ["Lego::From::PNG::Const"->$r_key, "Lego::From::PNG::Const"->$g_key, "Lego::From::PNG::Const"->$b_key]} }
ABresult
1X1
011
000
105 0 my $color = $self->color;
106  
107 0 my ($on_key, $cn_key, $hex_key, $r_key, $g_key, $b_key) = (
108 $color . '_OFFICIAL_NAME',
109 $color . '_COMMON_NAME',
110 $color . '_HEX_COLOR',
111 $color . '_RGB_COLOR_RED',
112 $color . '_RGB_COLOR_GREEN',
113 $color . '_RGB_COLOR_BLUE',
114 );
115  
116 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 +{
119 0 'cid' => $color,
120 'official_name' => Lego::From::PNG::Const->$on_key,
121 'common_name' => Lego::From::PNG::Const->$cn_key,
122 'hex_color' => Lego::From::PNG::Const->$hex_key,
123 'rgb_color' => [
124 Lego::From::PNG::Const->$r_key,
125 Lego::From::PNG::Const->$g_key,
126 Lego::From::PNG::Const->$b_key,
127 ],
128 };
129 };
130 }
131  
132 0 ▶sub flatten {
Subroutine flatten: not called CC=1 SCAR=6.9
Pod documented
133 0 my $self = shift;
134  
135 0 $self->identifier; # Make sure it's generated
136  
137 0 my %hash;
138 0 my @keys = qw(id color depth length height meta);
139  
140 0 @hash{ @keys } = @{ $self }{ @keys };
141  
142 0 return \%hash;
143 }
144  
145 =pod
146  
147 =head1 NAME
148  
149 Lego::From::PNG::Brick - A simple representation of a lego brick
150  
151 =head1 SYNOPSIS
152  
153 use Lego::From::PNG::Brick;
154  
155 my ($color, $depth, $length, $height) = ('BLACK', 1, 2, 1);
156  
157 # depth x length x height
158 my $object = Lego::From::PNG::Brick->new(
159 color => $color,
160 depth => $depth,
161 length => $length,
162 height => $height,
163 meta => {} # Anything else we want to track
164 );
165  
166 # Get at the data with accessors
167  
168 =head1 DESCRIPTION
169  
170 Representation of a Lego Brick plus additional meta data about that brick
171  
172 =head1 USAGE
173  
174 =head2 new
175  
176 Usage : ->new()
177 Purpose : Returns Lego::From::PNG::Brick object
178  
179 Returns : Lego::From::PNG::Brick object
180 Argument :
181 color -> must be a valid color from L<Lego::From::PNG::Const>
182 depth -> brick depth, defaults to 1
183 length -> brick length, defaults to 1
184 height -> brick height, defaults to 1
185 meta -> a hashref of additional meta data for the instanciated brick
186 Throws : Dies if the color is invalid
187  
188 Comment : Clobbers meta if it's not a valid hashref
189 See Also :
190  
191 =head2 id
192  
193 See identifier
194  
195 =head2 identifier
196  
197 Usage : ->identifier()
198 Purpose : Returns brick id, which is based on color, depth, length and width
199  
200 Returns : the indentifier. Format: <color>_<depth>x<length>x<height>
201 Argument :
202 Throws :
203  
204 Comment : Identifiers aren't necessarily unique, more than one brick could have the same identifier and different meta for instance
205 See Also :
206  
207  
208 =head2 color
209  
210 Usage : ->color() or ->color($new_color)
211 Purpose : Returns lego color for the brick, optionally a new color may be set
212  
213 Returns : lego color value for this brick
214 Argument : Optional. Pass a scalar with a new valid color value to change the bricks color
215 Throws :
216  
217 Comment :
218 See Also :
219  
220 =head2 depth
221  
222 Usage : ->depth() or ->depth($new_number)
223 Purpose : Returns depth for the brick, optionally a new depth may be set
224  
225 Returns : depth value for this brick
226 Argument : Optional. Pass a scalar with a new valid depth value to change the bricks depth
227 Throws :
228  
229 Comment :
230 See Also :
231  
232 =head2 length
233  
234 Usage : ->length() or ->length($new_number)
235 Purpose : Returns length for the brick, optionally a new length may be set
236  
237 Returns : length value for this brick
238 Argument : Optional. Pass a scalar with a new valid length value to change the bricks length
239 Throws :
240  
241 Comment :
242 See Also :
243  
244 =head2 height
245  
246 Usage : ->height() or ->height($new_number)
247 Purpose : Returns height for the brick, optionally a new height may be set
248  
249 Returns : height value for this brick
250 Argument : Optional. Pass a scalar with a new valid height value to change the bricks height
251 Throws :
252  
253 Comment :
254 See Also :
255  
256 =head2 meta
257  
258 Usage : ->meta()
259 Purpose : Returns brick meta data
260  
261 Returns : brick meta data
262 Argument :
263 Throws :
264  
265 Comment :
266 See Also :
267  
268 =head2 color_info
269  
270 Usage : ->color_info()
271 Purpose : Returns hash of color info related to bricks current color
272  
273 Returns : hash of color info
274 Argument :
275 Throws :
276  
277 Comment :
278 See Also :
279  
280 =head2 flatten
281  
282 Usage : ->flatten()
283 Purpose : Returns an unblessed version of the data
284  
285 Returns : hashref of brick data
286 Argument :
287 Throws :
288  
289 Comment :
290 See Also :
291  
292 =head1 BUGS
293  
294 =head1 SUPPORT
295  
296 =head1 AUTHOR
297  
298 Travis Chase
299 CPAN ID: GAUDEON
300 gaudeon@cpan.org
301 https://github.com/gaudeon/Lego-From-Png
302  
303 =head1 COPYRIGHT
304  
305 This program is free software licensed under the...
306  
307 The MIT License
308  
309 The full text of the license can be found in the
310 LICENSE file included with this module.
311  
312 =head1 SEE ALSO
313  
314 perl(1).
315  
316 =cut
317  
318 2 1;
« PNG/View/HTML.pm ↑ Summary PNG/View.pm »