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

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