File Coverage

blib/lib/Lego/From/PNG/View/HTML.pm
Criterion Covered Total %
statement 16 59 27.1
branch 0 4 0.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 23 71 32.3


';
line stmt bran cond sub pod time code
1             package Lego::From::PNG::View::HTML;
2              
3 1     1   990 use strict;
  1         1  
  1         26  
4 1     1   3 use warnings;
  1         1  
  1         23  
5              
6             BEGIN {
7 1     1   11 $Lego::From::PNG::VERSION = '0.01';
8             }
9              
10 1     1   3 use parent qw(Lego::From::PNG::View);
  1         1  
  1         3  
11              
12 1     1   41 use Lego::From::PNG::Const qw(:all);
  1         1  
  1         740  
13              
14 1     1   4 use Data::Debug;
  1         1  
  1         382  
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             # Brick List
45 0           $html .= qq{
\n};
46 0           $html .= qq{

Brick List

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

Total Bricks - $brick_total

\n};
48 0           $html .= qq{\n};
BrickQuantity
49 0           $html .= $_."\n" for @brick_list;
50 0           $html .= qq{
\n};
51 0           $html .= qq{\n\n};
52              
53             # Picture
54 0           $html .= qq{
\n};
55 0           $html .= qq{

Picture

\n};
56 0           $html .= qq{\n}; }; # first \n}; ]; \n}; # last
57 0           $html .= qq{
58 0           my $y = 0;
59 0           for my $color (@{$args{'plan'}}) {
  0            
60 0           my ($class, $colspan, $name) = (lc($color->{'color'}), $color->{'length'}, $self->png->lego_colors->{$color->{'color'}}{'official_name'});
61 0 0         if($y != $color->{'meta'}{'y'}) {
62 0           $html .= qq{
63 0           $y = $color->{'meta'}{'y'};
64             }
65 0           $html .= qq[
66             }
67 0           $html .= qq{
68 0           $html .= qq{
\n};
69 0           $html .= qq{\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;
145