Tabular/Output/HTML.pm

filter: Statementstmt 87.5% 63 / 72 Branchbran 59.0% 13 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod 100% 2 / 2 totaltotal 78.1% 86 / 110 CC 16 SCAR 20.9
CC
16
Cov
79%
html
13.2
new
5.3
new
2.0
CRAP 8.0
« Tabular/Config/Output.pm ↑ Summary Tabular/Table.pm »
1 # Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Data::Tabular::Output::HTML;
6  
7 3 ▶use base 'Data::Tabular::Output';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Carp qw (croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use overload '""' => \&_render;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new
14 2 ▶{
Subroutine new: called CC=5 SCAR=16.6
Pod documented
15 2 my $class = shift;
16 2 my $args = { @_ };
17  
18 2 my $self = bless {}, $class;
19  
20 2 ▶ die 'No table' unless $args->{table};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"table"} 0 2 2
21 2 $self->{table} = $args->{table};
22 2 ▶ die 'No output config' unless $args->{output};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"output"} 0 2 2
23 2 ▶ die 'No output config' unless ref $args->{output};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args->{"output"} 0 2 2
24 2 ▶ die 'No output config' unless $args->{output}->isa('Data::Tabular::Config::Output');
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"output"}->isa("Data::Tabular::Config::Output") 0 2 2
25 2 $self->{output} = $args->{output};
26  
27 2 $self;
28 }
29  
30 sub _render
31 2 ▶{
Subroutine _render: called CC=1 SCAR=0.0
32 2 my $self = shift;
33 2 $self->html;
34 }
35  
36 {
37 package Data::Tabular::_Type::Text;
38  
39 sub new
40 0 ▶ {
Subroutine new: not called CC=1 SCAR=6.9
41 0 my $class = shift;
42  
43 0 bless {
44 @_
45 }, $class;
46 }
47  
48 sub html_text
49 0 ▶ {
Subroutine html_text: not called CC=1 SCAR=6.9
50 0 my $self = shift;
51  
52 0 sprintf($self->{format}, $self->{data});
53 }
54 }
55  
56 sub html
57 3 ▶{
Subroutine html: called CC=12 SCAR=25.8
Pod documented
58 2 my $self = shift;
59  
60 2 my $output = $self->output;
61  
62 2 my $attributes = $output->html_attribute_string;
63  
64 2 $attributes .= '';
65 2 my $ret = "<table$attributes>\n";
66  
67 2 $ret .= " <colgroup>\n";
68 2 for my $col ($self->columns()) {
69 21 my $attribute = $col->align();
70  
71 21 $ret .= " <col$attribute/>\n";
72 }
73 2 $ret .= " </colgroup>\n";
74 2 my @table;
75  
76 2 for my $row ($self->rows()) {
77 44 my $attribute = $row->html_attribute_string();
78 44 push(@table, " <tr$attribute>\n");
79  
80 44 for my $cell ($row->cells()) {
81 288 my $data = $cell->data;
82 288 my $type = $self->output->type($cell->column_name);
83 288 ▶ unless (ref $data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data) 0 288 288
84 0 warn "ASDF";
85 0 $data = Data::Tabular::Type::Text->new(
86 data => '[' . $data . ']',
87 format => $self->output->get_column_format($cell->column_name),
88 );
89 }
90  
91 288 my $attributes = '';
92 288 ▶ if (my $cs = $cell->colspan) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cs = $cell->colspan) 288 0 288
93 288 ▶ if ($cs > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cs > 1) 27 261 288
94 27 $attributes.= sprintf(' colspan="%s"', $cs);
95 }
96 }
97  
98 288 ▶ if ($type eq 'dollar' or $type eq 'number') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "dollar" or $type eq "number") 0 288 288
Condition33%1/3
$type eq "dollar" or $type eq "number"
l!l&&r!l&&!r
00288
MC/DC0%0/2
$type eq "dollar" or $type eq "number"
$type eq "dollar" $type eq "number"
Truth table33%1/3
A or B
A= $type eq "dollar"B= $type eq "number"
ABresult
1X1
011
000
99 0 $attributes.= ' align="right"';
100 }
101  
102 288 my $hdr = $cell->hdr;
103 288 $hdr = 0;
104 288 ▶ if ($hdr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr) { } 0 288 288
105 0 push(@table, " <th$attributes>");
106 } else {
107 288 push(@table, " <td$attributes>");
108 }
109 288 my $cell_data = $data->html_text;
110  
111 288 ▶ if (length($cell_data) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $cell_data == 0) 5 283 288
112 5 $cell_data = '<br>';
113 }
114 288 push(@table, $cell_data);
115 288 ▶ if ($hdr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr) { } 0 288 288
116 0 push(@table, "</th>\n");
117 } else {
118 288 push(@table, "</td>\n");
119 }
120 }
121 44 push(@table, " </tr>\n");
122 }
123 2 $ret .= join('', @table);
124 2 $ret .= "</table>\n";
125 2 $ret;
126 }
127  
128 3 1;
129 __END__
« Tabular/Config/Output.pm ↑ Summary Tabular/Table.pm »