blib/lib/Tags/HTML/Table/View.pm

filter: Statementstmt 100% 90 / 90 Branchbran 100% 14 / 14 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 100% 129 / 129 CC 13 SCAR 14.6
CC
13
Cov
100%
_process
8.0
_value
6.0
BEGIN
1.0
CRAP 4.3
↑ Summary
1 package Tags::HTML::Table::View;
2  
3 7 ▶use base qw(Tags::HTML);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use Class::Utils qw(set_params split_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use List::Util 1.33 qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Tags::HTML::Element::A;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 7 our $VERSION = 0.07;
14  
15 # Constructor.
16 13 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17 13 my ($class, @params) = @_;
18  
19 # Create object.
20 13 my ($object_params_ar, $other_params_ar) = split_params(
21 ['css_table', 'header'], @params);
22 13 my $self = $class->SUPER::new(@{$other_params_ar});
23  
24 # Main CSS class.
25 13 $self->{'css_table'} = 'table';
26  
27 # Header is in first line.
28 13 $self->{'header'} = 1;
29  
30 # Process params.
31 13 set_params($self, @{$object_params_ar});
32  
33 # Object.
34 13 return $self;
35 }
36  
37 1 ▶sub _cleanup {
Subroutine _cleanup: called CC=1 SCAR=0.0
38 1 my $self = shift;
39  
40 1 delete $self->{'_data'};
41 1 delete $self->{'_no_data'};
42 1 delete $self->{'_tags_html_a'};
43  
44 1 return;
45 }
46  
47 12 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
48 12 my ($self, $data_ar, $no_data_value) = @_;
49  
50 12 $self->{'_data'} = [@{$data_ar}];
51 12 $self->{'_no_data'} = $no_data_value;
52 $self->{'_tags_html_a'} = Tags::HTML::Element::A->new(
53 'css' => $self->{'css'},
54 12 'tags' => $self->{'tags'},
55 );
56  
57 12 return;
58 }
59  
60 # Process 'Tags'.
61 11 ▶sub _process {
Subroutine _process: called CC=8 SCAR=20.8
62 11 my $self = shift;
63  
64 11 ▶ if (! exists $self->{'_data'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_data"}) 1 10 11
65 1 return;
66 }
67  
68 # Main content.
69 $self->{'tags'}->put(
70 ['b', 'table'],
71 10 ['a', 'class', $self->{'css_table'}],
72 );
73 10 my $columns_count = 0;
74 10 ▶ if ($self->{'header'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'header'}) { } 3 7 10
75 3 $self->{'tags'}->put(
76 ['b', 'tr'],
77 );
78 3 my $header_ar = shift @{$self->{'_data'}};
79 3 foreach my $value (@{$header_ar}) {
80 6 $self->{'tags'}->put(
81 ['b', 'th'],
82 ['d', $value],
83 ['e', 'th'],
84 );
85 6 $columns_count++;
86 }
87 3 $self->{'tags'}->put(
88 ['e', 'tr'],
89 );
90 } else {
91 7 $columns_count++;
92 }
93 10 foreach my $row_ar (@{$self->{'_data'}}) {
94 8 $self->{'tags'}->put(
95 ['b', 'tr'],
96 );
97 8 foreach my $value (@{$row_ar}) {
98 16 $self->{'tags'}->put(
99 ['b', 'td'],
100 );
101 16 $self->_value($value);
102 14 $self->{'tags'}->put(
103 ['e', 'td'],
104 );
105 }
106 6 $self->{'tags'}->put(
107 ['e', 'tr'],
108 );
109 }
110  
111 # No data row.
112 8 ▶ if (! @{$self->{'_data'}} && defined $self->{'_no_data'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$self->{"_data"};} and defined $self->{"_no_data"}) 1 7 8
Condition100%3/3
not @{$self->{"_data"};} and defined $self->{"_no_data"}
!ll&&!rl&&r
611
MC/DC100%2/2
not @{$self->{"_data"};} and defined $self->{"_no_data"}
not @{$self->{"_data"};} defined $self->{"_no_data"}
Truth table100%3/3
not(A) and B
A= not @{$self->{"_data"};}B= defined $self->{"_no_data"}
ABresult
0X0
100
111
113 1 $self->{'tags'}->put(
114 ['b', 'tr'],
115 ['b', 'td'],
116 ['a', 'colspan', $columns_count],
117 );
118 1 $self->_value($self->{'_no_data'});
119 1 $self->{'tags'}->put(
120 ['e', 'td'],
121 ['e', 'tr'],
122 );
123 }
124  
125 8 $self->{'tags'}->put(
126 ['e', 'table'],
127 );
128  
129 8 return;
130 }
131  
132 # Process 'CSS::Struct'.
133 1 ▶sub _process_css {
Subroutine _process_css: called CC=1 SCAR=0.0
134 1 my $self = shift;
135  
136 $self->{'css'}->put(
137 ['s', '.'.$self->{'css_table'}],
138 ['s', '.'.$self->{'css_table'}.' td'],
139 ['s', '.'.$self->{'css_table'}.' th'],
140 ['d', 'border', '1px solid #ddd'],
141 ['d', 'text-align', 'left'],
142 ['e'],
143  
144 ['s', '.'.$self->{'css_table'}],
145 ['d', 'border-collapse', 'collapse'],
146 ['d', 'width', '100%'],
147 ['e'],
148  
149 ['s', '.'.$self->{'css_table'}.' th'],
150 1 ['s', '.'.$self->{'css_table'}.' td'],
151 ['d', 'padding', '15px'],
152 ['e'],
153 );
154  
155 1 return;
156 }
157  
158 17 ▶sub _value {
Subroutine _value: called CC=6 SCAR=17.9
159 17 my ($self, $value) = @_;
160  
161 17 ▶ if (ref $value eq '') {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $value eq '') { } 12 5 17
elsif (ref $value eq 'ARRAY') { } 1 4 5
elsif (ref $value eq 'CODE') { } 1 3 4
elsif (builtin::blessed($value) and $value->isa('Data::HTML::Element::A')) { } 1 2 3
162 12 $self->{'tags'}->put(
163 ['d', $value],
164 );
165 } elsif (ref $value eq 'ARRAY') {
166 1 $self->{'tags'}->put(@{$value});
167 } elsif (ref $value eq 'CODE') {
168 1 $value->($self);
169 ▶ } elsif (blessed($value) && $value->isa('Data::HTML::Element::A')) {
Condition100%3/3
builtin::blessed($value) and $value->isa("Data::HTML::Element::A")
!ll&&!rl&&r
111
MC/DC100%2/2
builtin::blessed($value) and $value->isa("Data::HTML::Element::A")
builtin::blessed($value) $value->isa("Data::HTML::Element::A")
Truth table100%3/3
A and B
A= builtin::blessed($value)B= $value->isa("Data::HTML::Element::A")
ABresult
0X0
100
111
170 1 $self->{'_tags_html_a'}->init($value);
171 1 $self->{'_tags_html_a'}->process;
172 } else {
173 2 err 'Bad value object.';
174 }
175  
176 15 return;
177 }
178  
179 7 1;
180  
181 __END__
↑ Summary