blib/lib/HTML/EditableTable/Horizontal.pm

filter: Statementstmt 10.0% 12 / 119 Branchbran 0.0% 0 / 68 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 60.0% 3 / 5 Podpod 50.0% 1 / 2 totaltotal 7.0% 16 / 228 CC 48 SCAR 66.2
CC
48
Cov
6%
makeTable
1056.0
staticTableHeader
306.0
BEGIN
1.0
CRAP 749.9
↑ Summary blib/lib/HTML/EditableTable/Vertical.pm »
1 package HTML::EditableTable::Horizontal;
2  
3 1 @ISA = qw(HTML::EditableTable);
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 HTML::EditableTable::Horizontal
12  
13 =head1 VERSION
14  
15 Version 0.21
16  
17 =cut
18  
19 1 our $VERSION = '0.21';
20  
21 =head2 'Protected' Virtual Methods
22  
23 =cut
24  
25 # makeTable is the 'abstract virtual' method that must be implemented by a derivative of HTML::EditableTable
26  
27 0 ▶sub makeTable {
Subroutine makeTable: not called CC=32 SCAR=69.6
Pod documented
28  
29 0 my $self = shift @_;
30  
31 0 my $data = $self->{'data'};
32 0 my $spec = $self->{'tableFields'};
33 0 my $mode = $self->{'editMode'};
34
35 0 my $sortHeader = undef;
36
37 0 ▶ if (exists $self->{'sortHeader'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"sortHeader"}) 0 0 0
38 0 $sortHeader = $self->{'sortHeader'};
39 }
40  
41 0 ▶ if (!$data || !$spec || !$mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data and $spec and $mode) 0 0 0
Condition0%0/6
$data and $spec and $mode
!ll&&!rl&&r
000
$data and $spec
!ll&&!rl&&r
000
MC/DC0%0/3
$data and $spec and $mode
$data $spec $mode
Truth table0%0/4
A and B and C
A= $dataB= $specC= $mode
ABCresult
0XX0
10X0
1100
1111
42 0 confess("Missing requirement for table, throwing exception");
43 }
44
45 0 my $tableAttributes = $self->getTableTagAttributes();
46 0 print "\n<table $tableAttributes>\n";
47
48 0 ▶ unless (exists $self->{'noheader'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"noheader"}) 0 0 0
49 0 $self->staticTableHeader($spec, $mode, $sortHeader);
50 }
51
52 0 print "\n";
53
54 0 ▶ if (ref($data) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'ARRAY') { } 0 0 0
elsif (ref $data eq 'HASH') { } 0 0 0
55
56 # autodetermine rowspan drivers and call setRowspanDriver() from the first row of data
57 0 ▶ if(scalar(@$data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$data) 0 0 0
58 0 foreach my $dbfield (keys %{$data->[0]}) {
59 0 ▶ if (ref($data->[0]->{$dbfield}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data->[0]{$dbfield} eq "ARRAY") 0 0 0
60 0 push @{$self->{variableRowspanDriver}}, $dbfield;
61 }
62 }
63 }
64
65 0 foreach my $row (@$data) {
66
67 0 ▶ if (exists $self->{variableRowspanDriver}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'variableRowspanDriver'}) { } 0 0 0
68
69 0 my $maxRowspanSubcount = 0;
70
71 0 ▶ for (my $j = 0; $j < scalar(@{$self->{variableRowspanDriver}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$self->{"variableRowspanDriver"};}) 0 0 0
72 0 ▶ if (ref($row->{$self->{variableRowspanDriver}->[$j]}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$row{$self->{"variableRowspanDriver"}[$j]} eq "ARRAY") 0 0 0
73 0 my $nextRowspanSubcount = scalar(@{$row->{$self->{variableRowspanDriver}->[$j]}});
74  
75 0 ▶ if ($nextRowspanSubcount > $maxRowspanSubcount) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nextRowspanSubcount > $maxRowspanSubcount) 0 0 0
76 0 $maxRowspanSubcount = $nextRowspanSubcount;
77 }
78 }
79 }
80
81 0 ▶ for (my $i = 0; $i < $maxRowspanSubcount; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $maxRowspanSubcount) 0 0 0
82 0 print "<tr>";
83 0 $self->staticTableRow($row, $spec, $maxRowspanSubcount, $i);
84 0 print "</tr>\n\n";
85 }
86 }
87 else {
88 0 print "<tr>";
89 0 $self->staticTableRow($row, $spec);
90 0 print "</tr>\n\n";
91 }
92 }
93 }
94 elsif (ref($data) eq 'HASH') {
95
96 # autodetermine rowspan drivers and call setRowspanDriver() from the first row of data
97
98 0 my ($key, $row) = each %$data;
99
100 0 ▶ if($row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row) 0 0 0
101 0 foreach my $dbfield (keys %$row) {
102 0 ▶ if (ref($row->{$dbfield}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $row->{$dbfield} eq "ARRAY") 0 0 0
103 0 push @{$self->{variableRowspanDriver}}, $dbfield;
104 }
105 }
106 }
107
108 0 ▶ if ( my $so = $self->{'sortOrder'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $so = $self->{'sortOrder'}) { } 0 0 0
109
110 0 ▶ foreach my $rowKey (sort { my $aPos; my $bPos; for ($aPos = 0; $aPos < scalar(@$so); $aPos++) { if ($so->[$aPos] eq $a) { last; } } for ($bPos = 0; $bPos < scalar(@$so); $bPos++) { if ($so->[$bPos] eq $b) { last; } } $aPos <=> $bPos; } keys %$data) {
Branch: 4 branches
BranchTrueFalseTotal
if ($aPos < scalar @$so) 0 0 0
if ($so->[$aPos] eq $a) 0 0 0
if ($bPos < scalar @$so) 0 0 0
if ($so->[$bPos] eq $b) 0 0 0
111  
112 0 my $row = $data->{$rowKey};
113
114 0 ▶ if (exists $self->{variableRowspanDriver}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'variableRowspanDriver'}) { } 0 0 0
115
116 0 my $maxRowspanSubcount = 0;
117
118 0 ▶ for (my $j = 0; $j < scalar(@{$self->{variableRowspanDriver}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$self->{"variableRowspanDriver"};}) 0 0 0
119 0 ▶ if (ref($row->{$self->{variableRowspanDriver}->[$j]}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$row{$self->{"variableRowspanDriver"}[$j]} eq "ARRAY") 0 0 0
120 0 my $nextRowspanSubcount = scalar(@{$row->{$self->{variableRowspanDriver}->[$j]}});
121
122 0 ▶ if ($nextRowspanSubcount > $maxRowspanSubcount) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nextRowspanSubcount > $maxRowspanSubcount) 0 0 0
123 0 $maxRowspanSubcount = $nextRowspanSubcount;
124 }
125 }
126 }
127
128 0 ▶ for (my $i = 0; $i < $maxRowspanSubcount; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $maxRowspanSubcount) 0 0 0
129 0 print "<tr>";
130 0 $self->staticTableRow($row, $spec, $maxRowspanSubcount, $i);
131 0 print "</tr>\n\n";
132 }
133 }
134 else {
135 0 print "<tr>";
136 0 $self->staticTableRow($row, $spec);
137 0 print "</tr>\n\n";
138 }
139 }
140 }
141 else {
142 0 foreach my $rowKey (sort keys %$data) {
143 0 print "<tr>";
144 0 $self->staticTableRow($data->{$rowKey}, $spec);
145 0 print "</tr>\n";
146 }
147 }
148 }
149
150 else {
151 0 confess "data must by a hash or array reference, not a " . ref($data);
152 }
153
154 0 print "</table>\n";
155 }
156  
157 0 ▶sub staticTableHeader {
Subroutine staticTableHeader: not called CC=17 SCAR=57.2
Pod undocumented
158
159 0 my $self = shift @_;
160  
161 0 my $spec = $self->{'tableFields'};
162 0 my $mode = $self->{'editMode'};
163  
164 0 my $sortHeader = undef;
165 0 my $orderBy = undef;
166
167 0 ▶ if (exists $self->{'sortHeader'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"sortHeader"}) 0 0 0
168  
169 # each click causes sort to revserse
170
171 0 $orderBy = 'orderByAsc';
172
173 0 ▶ if (CGI::param('orderByAsc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (CGI::param("orderByAsc")) 0 0 0
174 0 $orderBy = 'orderByDesc';
175 }
176
177 0 $sortHeader = $self->{'sortHeader'};
178 }
179  
180 0 print "<tr>";
181  
182 0 foreach my $colSpec (@$spec) {
183
184 0 ▶ next if (exists $colSpec->{'viewOnly'} && $mode eq 'edit');
Branch: 1 branch
BranchTrueFalseTotal
if exists $colSpec->{"viewOnly"} and $mode eq "edit" 0 0 0
Condition0%0/3
exists $colSpec->{"viewOnly"} and $mode eq "edit"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $colSpec->{"viewOnly"} and $mode eq "edit"
exists $colSpec->{"viewOnly"} $mode eq "edit"
Truth table0%0/3
A and B
A= exists $colSpec->{"viewOnly"}B= $mode eq "edit"
ABresult
0X0
100
111
185 0 ▶ next if (exists $colSpec->{'editOnly'} && $mode eq 'view');
Branch: 1 branch
BranchTrueFalseTotal
if exists $colSpec->{"editOnly"} and $mode eq "view" 0 0 0
Condition0%0/3
exists $colSpec->{"editOnly"} and $mode eq "view"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $colSpec->{"editOnly"} and $mode eq "view"
exists $colSpec->{"editOnly"} $mode eq "view"
Truth table0%0/3
A and B
A= exists $colSpec->{"editOnly"}B= $mode eq "view"
ABresult
0X0
100
111
186
187 0 ▶ if ($colSpec->{'formElement'} && ($colSpec->{'formElement'} eq 'deleteRowButton')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($colSpec->{'formElement'} and $colSpec->{'formElement'} eq 'deleteRowButton') { } 0 0 0
elsif (not exists $colSpec->{'label'}) { } 0 0 0
Condition0%0/3
$colSpec->{"formElement"} and $colSpec->{"formElement"} eq "deleteRowButton"
!ll&&!rl&&r
000
MC/DC0%0/2
$colSpec->{"formElement"} and $colSpec->{"formElement"} eq "deleteRowButton"
$colSpec->{"formElement"} $colSpec->{"formElement"} eq "deleteRowButton"
Truth table0%0/3
A and B
A= $colSpec->{"formElement"}B= $colSpec->{"formElement"} eq "deleteRowButton"
ABresult
0X0
100
111
188 0 print "<th>" . "<input type=button value='add row' onClick=\"addData()\">" . "</th>";
189 }
190 elsif (!exists($colSpec->{'label'})) {
191 0 print "<th>" . "<i>label missing</i>" . "</th>";
192 }
193 else {
194 0 ▶ if ($sortHeader && exists $colSpec->{'dbfield'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sortHeader and exists $colSpec->{'dbfield'}) { } 0 0 0
Condition0%0/3
$sortHeader and exists $colSpec->{"dbfield"}
!ll&&!rl&&r
000
MC/DC0%0/2
$sortHeader and exists $colSpec->{"dbfield"}
$sortHeader exists $colSpec->{"dbfield"}
Truth table0%0/3
A and B
A= $sortHeaderB= exists $colSpec->{"dbfield"}
ABresult
0X0
100
111
195 0 print "<th>" . "<a href=" . $sortHeader . $orderBy . "=" . $colSpec->{'dbfield'} . ">" . $colSpec->{'label'} . "</a>";
196 }
197 else {
198
199 0 ▶ if (exists $colSpec->{'tooltip'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $colSpec->{'tooltip'}) { } 0 0 0
200 0 print "<th tooltip=\"" . $colSpec->{'tooltip'} . "\" onmouseover=\"Tooltip.schedule(this, event);\">" . $colSpec->{'label'};
201 }
202 else {
203 0 print "<th>" . $colSpec->{'label'};
204 }
205 }
206
207 0 ▶ if ($mode eq 'edit' && exists $colSpec->{'jsClearColumnOnEdit'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "edit" and exists $colSpec->{"jsClearColumnOnEdit"}) 0 0 0
Condition0%0/3
$mode eq "edit" and exists $colSpec->{"jsClearColumnOnEdit"}
!ll&&!rl&&r
000
MC/DC0%0/2
$mode eq "edit" and exists $colSpec->{"jsClearColumnOnEdit"}
$mode eq "edit" exists $colSpec->{"jsClearColumnOnEdit"}
Truth table0%0/3
A and B
A= $mode eq "edit"B= exists $colSpec->{"jsClearColumnOnEdit"}
ABresult
0X0
100
111
208 0 print "<br>";
209  
210 0 my $name = $colSpec->{'dbfield'};
211
212 0 ▶ if (exists $colSpec->{'rowspanArrayKey'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $colSpec->{"rowspanArrayKey"}) 0 0 0
213 0 $name = $colSpec->{'rowspanArrayKey'}
214 }
215
216 0 print "<input type=button value='clear column' onClick=\"clearColumnOnEdit('$name');\">";
217
218 }
219
220 0 print "</th>";
221
222 }
223 }
224 0 print "</tr>\n";
225 }
226  
227  
228 =head1 SYNOPSIS
229  
230 Implementation of EditableTable for the 'horizontal' case, where the first row presents the data header. There are no public methods in this class. See L<HTML::EditableTable> for documentation.
231  
232 =head1 COPYRIGHT & LICENSE
233  
234 Copyright 2010 Freescale Semiconductor, all rights reserved.
235  
236 This program is free software; you can redistribute it and/or modify it
237 under the same terms as Perl itself.
238  
239  
240 =cut
241  
242 1 1; # End of HTML::EditableTable::Horizontal
↑ Summary blib/lib/HTML/EditableTable/Vertical.pm »