File Coverage

blib/lib/Lego/From/PNG/View/HTML.pm
Criterion Covered Total %
statement 16 73 21.9
branch 0 6 0.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 23 87 26.4


';
line stmt bran cond sub pod time code
1             package Lego::From::PNG::View::HTML;
2              
3 1     1   983 use strict;
  1         2  
  1         35  
4 1     1   4 use warnings;
  1         1  
  1         37  
5              
6             BEGIN {
7 1     1   14 $Lego::From::PNG::VERSION = '0.03';
8             }
9              
10 1     1   4 use parent qw(Lego::From::PNG::View);
  1         1  
  1         6  
11              
12 1     1   52 use Lego::From::PNG::Const qw(:all);
  1         1  
  1         1145  
13              
14 1     1   10 use Data::Debug;
  1         2  
  1         830  
15              
16             sub print {
17 0     0 1   my $self = shift;
18 0 0         my %args = ref $_[0] eq 'HASH' ? %{$_[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'}}) {
  0            
  0            
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, '
'.$lego_color->{'official_name'}.' '.join('x',@{$color}{qw(depth length height)}).''.$color->{'quantity'}.'
  0            
34 0           $brick_total += $color->{'quantity'};
35             }
36              
37 0           my $html;
38              
39             # Styles
40 0           $html .= qq{\n\n};
43              
44             # Info
45 0           $html .= qq{
\n};
46 0           $html .= qq{

Info

\n};
47 0           for my $type(qw/metric imperial/) {
48 0 0         if (exists $args{'info'}{$type}) {
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/};
  0            
53 0           $html .= qq{\n}; \n}; \n}; \n};
54 0           $html .= qq{
Depth:$depth $suffix
55 0           $html .= qq{
Length:$length $suffix
56 0           $html .= qq{
Height:$height $suffix
57 0           $html .= qq{
\n};
58             }
59             }
60 0           $html .= qq{\n\n};
61              
62             # Brick List
63 0           $html .= qq{
\n};
64 0           $html .= qq{

Brick List

\n};
65 0           $html .= qq{

Total Bricks - $brick_total

\n};
66 0           $html .= qq{\n};
BrickQuantity
67 0           $html .= $_."\n" for @brick_list;
68 0           $html .= qq{
\n};
69 0           $html .= qq{\n\n};
70              
71             # Picture
72 0           $html .= qq{
\n};
73 0           $html .= qq{

Picture

\n};
74 0           $html .= qq{\n}; }; # first \n}; ]; \n}; # last
75 0           $html .= qq{
76 0           my $y = 0;
77 0           for my $color (@{$args{'plan'}}) {
  0            
78 0           my ($class, $colspan, $name) = (lc($color->{'color'}), $color->{'length'}, $self->png->lego_colors->{$color->{'color'}}{'official_name'});
79 0 0         if($y != $color->{'meta'}{'y'}) {
80 0           $html .= qq{
81 0           $y = $color->{'meta'}{'y'};
82             }
83 0           $html .= qq[
84             }
85 0           $html .= qq{
86 0           $html .= qq{
\n};
87 0           $html .= qq{\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;