PNG/View/HTML.pm

filter: Statementstmt 28.3% 17 / 60 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 33.3% 24 / 72 SCAR 35.1
CC
8
Cov
27%
print
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 33.3
« 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.01';
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=8 SCAR=42.8
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 # Brick List
45 0 $html .= qq{<section class="brick_list">\n};
46 0 $html .= qq{<h2>Brick List</h2>\n};
47 0 $html .= qq{<p>Total Bricks - $brick_total</p>\n};
48 0 $html .= qq{<table><thead><tr><th>Brick</th><th>Quantity</th></thead><tbody>\n};
49 0 $html .= $_."\n" for @brick_list;
50 0 $html .= qq{</tbody></table>\n};
51 0 $html .= qq{</section>\n\n};
52  
53 # Picture
54 0 $html .= qq{<section class="brick_display">\n};
55 0 $html .= qq{<h2>Picture</h2>\n};
56 0 $html .= qq{<table class="picture" border="1"><tbody>\n};
57 0 $html .= qq{<tr>}; # first <tr>
58 0 my $y = 0;
59 0 for my $color (@{$args{'plan'}}) {
60 0 my ($class, $colspan, $name) = (lc($color->{'color'}), $color->{'length'}, $self->png->lego_colors->{$color->{'color'}}{'official_name'});
61 0 ▶ if($y != $color->{'meta'}{'y'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y != $color->{"meta"}{"y"}) 0 0 0
62 0 $html .= qq{</tr>\n};
63 0 $y = $color->{'meta'}{'y'};
64 }
65 0 $html .= qq[<td colspan="$colspan" title="$name $color->{'depth'}x$color->{'length'}x$color->{'height'}" class="$class length_${colspan}"></td>];
66 }
67 0 $html .= qq{</tr>\n}; # last </tr>
68 0 $html .= qq{</tbody></table>\n};
69 0 $html .= qq{</section>\n};
70  
71 0 return $html;
72 }
73  
74 =pod
75  
76 =head1 NAME
77  
78 Lego::From::PNG::View::HTML - Format data returned from Lego::From::PNG
79  
80 =head1 SYNOPSIS
81  
82 use Lego::From::PNG;
83  
84 my $object = Lego::From::PNG->new({ filename => 'my_png.png' });
85  
86 $object->process(view => 'HTML'); # Data is returned as HTML
87  
88 =head1 DESCRIPTION
89  
90 Class to returned processed data in HTML format
91  
92 =head1 USAGE
93  
94 =head2 new
95  
96 Usage : ->new()
97 Purpose : Returns Lego::From::PNG::View::HTML object
98  
99 Returns : Lego::From::PNG::View::HTML object
100 Argument :
101 Throws :
102  
103 Comment :
104 See Also :
105  
106 =head2 print
107  
108 Usage : ->print({}) or ->print(key1 => val1, key2 => val2)
109 Purpose : Returns HTML formated data (in utf8 and pretty format)
110  
111 Returns : Returns HTML formated data (in utf8 and pretty format)
112 Argument :
113 Throws :
114  
115 Comment :
116 See Also :
117  
118 =head1 BUGS
119  
120 =head1 SUPPORT
121  
122 =head1 AUTHOR
123  
124 Travis Chase
125 CPAN ID: GAUDEON
126 gaudeon@cpan.org
127 https://github.com/gaudeon/Lego-From-Png
128  
129 =head1 COPYRIGHT
130  
131 This program is free software licensed under the...
132  
133 The MIT License
134  
135 The full text of the license can be found in the
136 LICENSE file included with this module.
137  
138 =head1 SEE ALSO
139  
140 perl(1).
141  
142 =cut
143  
144 1 1;
145  
« PNG/Brick.pm ↑ Summary PNG/View.pm »