blib/lib/App/RecordStream/Operation/tohtml.pm

filter: Statementstmt 100% 67 / 67 Branchbran 100% 6 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 7 totaltotal 90.4% 85 / 94 CC 7 SCAR 7.8
CC
7
Cov
99%
print_start
4.0
accept_record
3.0
print_header
2.0
CRAP 2.2
« blib/lib/App/RecordStream/Operation/decollate.pm ↑ Summary blib/lib/App/RecordStream/Operation/fromsplit.pm »
1 package App::RecordStream::Operation::tohtml;
2  
3 2 our $VERSION = "4.0.23";
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use base qw(App::RecordStream::Operation);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub init {
11 6 ▶ my $this = shift;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
12 6 my $args = shift;
13  
14 6 my $no_header;
15 6 my $row_attributes = '';
16 6 my $cell_attributes = '';
17  
18 6 my $key_groups = App::RecordStream::KeyGroups->new();
19  
20 my $spec = {
21 2 ▶ 'keys|k|fields|f=s' => sub { $key_groups->add_groups($_[1]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 6 'noheader' => \$no_header,
23 'rowattributes=s' => \$row_attributes,
24 'cellattributes=s' => \$cell_attributes,
25 };
26  
27 6 $this->parse_options($args, $spec);
28  
29 5 $this->{'KEY_GROUPS'} = $key_groups;
30 5 $this->{'NO_HEADER'} = $no_header;
31 5 $this->{'ROW_ATTRIBUTES'} = $row_attributes;
32 5 $this->{'CELL_ATTRIBUTES'} = $cell_attributes;
33 }
34  
35 sub accept_record {
36 25 ▶ my $this = shift;
Subroutine accept_record: called CC=3 SCAR=11.0
Pod undocumented
37 25 my $record = shift;
38  
39 25 $this->print_start($record);
40  
41 25 my $fields = $this->{'FIELDS'};
42 25 my $row_attributes = $this->{'ROW_ATTRIBUTES'};
43 25 my $cell_attributes = $this->{'CELL_ATTRIBUTES'};
44  
45 25 $this->push_line(" <tr $row_attributes>");
46  
47 25 foreach my $field (@$fields) {
48 45 ▶ my $value = ${$record->guess_key_from_spec($field)} || '';
Condition50%1/2
${$record->guess_key_from_spec($field);} || ''
l!l
450
MC/DC0%0/1
${$record->guess_key_from_spec($field);} || ''
${$record->guess_key_from_spec($field);}
Truth table50%1/2
A
A= ${$record->guess_key_from_spec($field);}
Aresult
11
00
49 45 $this->push_line(" <td $cell_attributes>$value</td>");
50 }
51  
52 25 $this->push_line(" </tr>");
53  
54 25 return 1;
55 }
56  
57 sub print_start {
58 25 ▶ my $this = shift;
Subroutine print_start: called CC=4 SCAR=13.9
Pod undocumented
59 25 my $record = shift;
60  
61 25 ▶ return if ( $this->{'PRINTED_START'} );
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"PRINTED_START"} 20 5 25
62 5 $this->{'PRINTED_START'} = 1;
63  
64 5 $this->push_line("<table>");
65  
66 5 my $groups = $this->{'KEY_GROUPS'};
67 5 ▶ if ( $groups->has_any_group() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($groups->has_any_group) { } 2 3 5
68 2 my $specs = $this->{'KEY_GROUPS'}->get_keyspecs($record);
69 2 $this->{'FIELDS'} = $specs;
70 }
71 else {
72 3 $this->{'FIELDS'} = [sort keys %$record];
73 }
74  
75 5 ▶ return if ( $this->{'NO_HEADER'} );
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"NO_HEADER"} 1 4 5
76  
77 4 $this->print_header();
78 }
79  
80 sub print_header {
81 4 ▶ my $this = shift;
Subroutine print_header: called CC=2 SCAR=6.9
Pod undocumented
82  
83 4 my $fields = $this->{'FIELDS'};
84  
85 4 my $row_attributes = $this->{'ROW_ATTRIBUTES'};
86 4 my $cell_attributes = $this->{'CELL_ATTRIBUTES'};
87  
88 4 $this->push_line(" <tr $row_attributes>");
89  
90 4 foreach my $field (@$fields) {
91 7 $this->push_line(" <th $cell_attributes>$field</th>");
92 }
93  
94 4 $this->push_line(" </tr>");
95 }
96  
97 sub stream_done {
98 5 ▶ my $this = shift;
Subroutine stream_done: called CC=1 SCAR=0.0
Pod undocumented
99 5 $this->push_line("</table>");
100 }
101  
102 sub add_help_types {
103 6 ▶ my $this = shift;
Subroutine add_help_types: called CC=1 SCAR=0.0
Pod undocumented
104 6 $this->use_help_type('keyspecs');
105 6 $this->use_help_type('keygroups');
106 6 $this->use_help_type('keys');
107 }
108  
109 sub usage {
110 1 ▶ my $this = shift;
Subroutine usage: called CC=1 SCAR=0.0
Pod undocumented
111  
112 1 my $options = [
113 ['keys <keys>', 'Keys to print in the table. May be specified multiple times, may be comma separated. Default to all fields in the first record. May be a keyspec or a keygroup, see \'--help-keys\' for more information'],
114 ['noheader', 'Do not print the header row'],
115 ['rowattributes', 'HTML attributes to put on the tr tags'],
116 ['cellattributes', 'HTML attributes to put on the td and th tag'],
117 ];
118  
119 1 my $args_string = $this->options_string($options);
120  
121 1 return <<USAGE;
122 Usage: recs-totable <args> [<files>]
123 __FORMAT_TEXT__
124 Prints out an html table for the records from input or from <files>.
125 __FORMAT_TEXT__
126  
127 $args_string
128  
129 Examples:
130 Print all fields
131 recs-tohhtml
132 Print foo and bar fields, without a header
133 recs-tohtml --fields foo,bar --noheader
134 USAGE
135 }
136  
137 2 1;
« blib/lib/App/RecordStream/Operation/decollate.pm ↑ Summary blib/lib/App/RecordStream/Operation/fromsplit.pm »