blib/lib/DBIx/HTMLTable.pm

filter: Statementstmt 10.8% 8 / 74 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 4 totaltotal 7.5% 8 / 106 CC 18 SCAR 38.1
CC
18
Cov
9%
HTMLTableByRef
56.0
table_opts
56.0
HTMLTable
30.0
CRAP 45.0
↑ Summary
1 package DBIx::HTMLTable;
2 1 $VERSION=0.24;
3  
4 1 @EXPORT_OK=qw(&HTMLTable &HTMLTableByRef);
5  
6 # Table Options
7 1 my @options = qw(caption nullfield rs fs);
8  
9 # HTML 4.0 attributes for table tag.
10 1 my @tableattribs = qw(align width cols id class dir title
11 style onclick ondbclick onmousedown
12 onmouseup onmouseover onmousemove
13 onmouseout onkeypress onkeydown
14 onkeyup bgcolor frame rules border
15 cellspacing cellpadding);
16  
17 1 my $nullfield = ' ';
18 1 my $rs = "\n";
19 1 my $fs = ",";
20  
21 0 ▶sub HTMLTable {
Subroutine HTMLTable: not called CC=5 SCAR=34.0
Pod undocumented
22 0 my ($data, @args) = @_;
23 0 my ($i, $j, @cols, @theads, @trows, $thead,$topdatarow);
24 0 &table_opts (@args);
25 0 my @rows = split /$options->{rs}/, $data;
26 0 @cols = split /$options->{fs}/, $rows[0];
27 0 $thead = $rows[0];
28  
29 0 my $cols = $#cols;
30  
31 0 my $table = &table_tag;
32 0 print $table."\n";
33 0 print qq|<colgroup>\n|;
34 0 foreach my $row (@rows) {
35 0 print qq|<tr>\n|;
36 0 my @trow = split /\,/, $row;
37 0 foreach my $col (@trow) {
38 0 print qq|<td>|;
39 0 ▶ if ($col and length $col) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col and length $col) { } 0 0 0
Condition0%0/3
$col and length $col
!ll&&!rl&&r
000
MC/DC0%0/2
$col and length $col
$col length $col
Truth table0%0/3
A and B
A= $colB= length $col
ABresult
0X0
100
111
40 0 print $col;
41 } else {
42 0 print $options->{nullfield};
43 }
44 0 print qq|</td>\n|;
45 }
46 0 print qq|</tr>\n|;
47 }
48 0 print qq|</colgroup>\n|;
49 0 print qq|</table>\n|;
50 }
51  
52 0 ▶sub HTMLTableByRef {
Subroutine HTMLTableByRef: not called CC=7 SCAR=40.3
Pod undocumented
53 0 my $dataref = $_[0];
54 0 my $opts = $_[1];
55 0 my ($newopts,$newattribs) = &table_opts ($opts);
56 0 my ($i, $j, $nrows, $ncols, @rows);
57  
58 0 foreach (@$dataref) { push @rows, $_ }
59  
60 0 $nrows = $#rows;
61 0 $ncols = scalar @{$rows[0]};
62  
63 0 my $table = &table_tag ($newattribs);
64 0 print $table."\n";
65  
66 0 ▶ if (length $newopts->{caption}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $newopts->{"caption"}) 0 0 0
67 0 print qq|<caption>$newopts->{caption}</caption>\n|;
68 }
69  
70 0 print qq|<colgroup>\n|;
71  
72 0 ▶ for ( $i = 0; $i <= $nrows; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $nrows) 0 0 0
73 0 print qq|<tr>\n|;
74 0 ▶ for ( $j = 0; $j < $ncols; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $ncols) 0 0 0
75 0 ▶ if ( not ${$rows[$i]}[$j] or (${$rows[$i]}[$j] eq '') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not do { $rows[$i] }->[$j] or do { $rows[$i] }->[$j] eq "") 0 0 0
Condition0%0/3
not do { $rows[$i] }->[$j] or do { $rows[$i] }->[$j] eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not do { $rows[$i] }->[$j] or do { $rows[$i] }->[$j] eq ""
not do { $rows[$i] }->[$j] do { $rows[$i] }->[$j] eq ""
Truth table0%0/3
not(A) or B
A= not do { $rows[$i] }->[$j]B= do { $rows[$i] }->[$j] eq ""
ABresult
1X1
011
000
76 0 ${$rows[$i]}[$j] = '&nbsp';
77 }
78 0 print "<td>".${rows[$i]}[$j]."</td>\n";
79 }
80 0 print qq|</tr>\n|;
81 }
82  
83 0 print qq|</colgroup>\n|;
84 0 print qq|</table>\n|;
85 }
86  
87 0 ▶sub table_tag {
Subroutine table_tag: not called CC=2 SCAR=17.9
Pod undocumented
88 0 my ($attribs) = @_;
89 0 my $tag = '<table ';
90 0 foreach my $attrib (keys %$attribs) {
91 0 $tag .= ' '.$attrib."\=\"".$attribs->{$attrib}."\"";
92 }
93 0 $tag .= '>';
94 }
95  
96 # All this does is check that options and attrbutes are valid.
97 0 ▶sub table_opts {
Subroutine table_opts: not called CC=7 SCAR=40.3
Pod undocumented
98 0 my ($args) = @_;
99 0 my (%newopts,%newattribs);
100 0 foreach my $key (keys %$args) {
101 0 foreach my $opt (@options) {
102 0 ▶ if ($key =~ /$opt/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /$opt/) 0 0 0
103 0 $newopts{$key} = $args->{$key};
104 0 last;
105 }
106 }
107 }
108 0 foreach my $key (keys %$args) {
109 0 foreach my $attrib (@tableattribs) {
110 0 ▶ if ($key =~ /$attrib/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /$attrib/) 0 0 0
111 0 $newattribs{$key} = $args->{$key};
112 0 last;
113 }
114 }
115 }
116 0 return \%newopts, \%newattribs;
117 }
118  
119 1 1;
120 __END__;
↑ Summary