PNG/View/HTML.pm

filter: Statementstmt 22.9% 17 / 74 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 27.2% 24 / 88 SCAR 40.7
CC
10
Cov
21%
print
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 58.8
« PNG/Brick.pm ↑ Summary PNG/View.pm »
1 package Lego::From::PNG::View::HTML;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 BEGIN {
7 1 ▶ $Lego::From::PNG::VERSION = '0.03';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 }
9  
10 1 ▶use parent qw(Lego::From::PNG::View);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Lego::From::PNG::Const qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Data::Debug;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub print {
17 0 ▶ my $self = shift;
Subroutine print: not called CC=10 SCAR=47.0
Pod documented
18 0 ▶ my %args = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
19  
20 0 my @styles;
21 my @brick_list;
22  
23 0 push @styles, '.picture td { height: 1em; }';
24  
25 0 push @styles, ".length_$_ { width: ${_}em; }" for LEGO_BRICK_LENGTHS;
26  
27 0 my $brick_total = 0;
28 0 for my $color (sort { $a->{'color'}.$a->{'length'} cmp $b->{'color'}.$b->{'length'} } values %{$args{'bricks'}}) {
29 0 my $cid = $color->{'color'};
30 0 my $lego_color = $self->png->lego_colors->{$cid};
31  
32 0 push @styles, '.'.lc($cid).' { background: #'.$lego_color->{'hex_color'}.'; }';
33 0 push @brick_list, '<tr><td>'.$lego_color->{'official_name'}.' '.join('x',@{$color}{qw(depth length height)}).'</td><td>'.$color->{'quantity'}.'</td></tr>';
34 0 $brick_total += $color->{'quantity'};
35 }
36  
37 0 my $html;
38  
39 # Styles
40 0 $html .= qq{<style>\n};
41 0 $html .= $_."\n" for @styles;
42 0 $html .= qq{</style>\n\n};
43  
44 # Info
45 0 $html .= qq{<section class="info">\n};
46 0 $html .= qq{<h2>Info</h2>\n};
47 0 for my $type(qw/metric imperial/) {
48 0 ▶ if (exists $args{'info'}{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"info"}{$type}) 0 0 0
49 0 my $suffix_key = uc($type) . '_SUFFIX';
50 0 my $suffix = Lego::From::PNG::Const->$suffix_key;
51  
52 0 my ($depth, $length, $height) = @{$args{'info'}{$type}}{qw/depth length height/};
53 0 $html .= qq{<table><tbody>\n};
54 0 $html .= qq{<tr><td>Depth:</td><td>$depth $suffix</td></tr>\n};
55 0 $html .= qq{<tr><td>Length:</td><td>$length $suffix</td></tr>\n};
56 0 $html .= qq{<tr><td>Height:</td><td>$height $suffix</td></tr>\n};
57 0 $html .= qq{</tbody></table>\n};
58 }
59 }
60 0 $html .= qq{</section>\n\n};
61  
62 # Brick List
63 0 $html .= qq{<section class="brick_list">\n};
64 0 $html .= qq{<h2>Brick List</h2>\n};
65 0 $html .= qq{<p>Total Bricks - $brick_total</p>\n};
66 0 $html .= qq{<table><thead><tr><th>Brick</th><th>Quantity</th></thead><tbody>\n};
67 0 $html .= $_."\n" for @brick_list;
68 0 $html .= qq{</tbody></table>\n};
69 0 $html .= qq{</section>\n\n};
70  
71 # Picture
72 0 $html .= qq{<section class="brick_display">\n};
73 0 $html .= qq{<h2>Picture</h2>\n};
74 0 $html .= qq{<table class="picture" border="1"><tbody>\n};
75 0 $html .= qq{<tr>}; # first <tr>
76 0 my $y = 0;
77 0 for my $color (@{$args{'plan'}}) {
78 0 my ($class, $colspan, $name) = (lc($color->{'color'}), $color->{'length'}, $self->png->lego_colors->{$color->{'color'}}{'official_name'});
79 0 ▶ if($y != $color->{'meta'}{'y'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y != $color->{"meta"}{"y"}) 0 0 0
80 0 $html .= qq{</tr>\n};
81 0 $y = $color->{'meta'}{'y'};
82 }
83 0 $html .= qq[<td colspan="$colspan" title="$name $color->{'depth'}x$color->{'length'}x$color->{'height'}" class="$class length_${colspan}"></td>];
84 }
85 0 $html .= qq{</tr>\n}; # last </tr>
86 0 $html .= qq{</tbody></table>\n};
87 0 $html .= qq{</section>\n};
88  
89 0 return $html;
90 }
91  
92 =pod
93  
94 =head1 NAME
95  
96 Lego::From::PNG::View::HTML - Format data returned from Lego::From::PNG
97  
98 =head1 SYNOPSIS
99  
100 use Lego::From::PNG;
101  
102 my $object = Lego::From::PNG->new({ filename => 'my_png.png' });
103  
104 $object->process(view => 'HTML'); # Data is returned as HTML
105  
106 =head1 DESCRIPTION
107  
108 Class to returned processed data in HTML format
109  
110 =head1 USAGE
111  
112 =head2 new
113  
114 Usage : ->new()
115 Purpose : Returns Lego::From::PNG::View::HTML object
116  
117 Returns : Lego::From::PNG::View::HTML object
118 Argument :
119 Throws :
120  
121 Comment :
122 See Also :
123  
124 =head2 print
125  
126 Usage : ->print({}) or ->print(key1 => val1, key2 => val2)
127 Purpose : Returns HTML formated data (in utf8 and pretty format)
128  
129 Returns : Returns HTML formated data (in utf8 and pretty format)
130 Argument :
131 Throws :
132  
133 Comment :
134 See Also :
135  
136 =head1 BUGS
137  
138 =head1 SUPPORT
139  
140 =head1 AUTHOR
141  
142 Travis Chase
143 CPAN ID: GAUDEON
144 gaudeon@cpan.org
145 https://github.com/gaudeon/Lego-From-Png
146  
147 =head1 COPYRIGHT
148  
149 This program is free software licensed under the...
150  
151 The MIT License
152  
153 The full text of the license can be found in the
154 LICENSE file included with this module.
155  
156 =head1 SEE ALSO
157  
158 perl(1).
159  
160 =cut
161  
162 1 1;
« PNG/Brick.pm ↑ Summary PNG/View.pm »