DataTable.pm

filter: Statementstmt 6.8% 16 / 235 Branchbran 0.0% 0 / 126 Conditioncond 0.0% 0 / 124 MC/DCmcdc 0.0% 0 / 72 Subroutinesub 17.2% 5 / 29 Podpod 41.1% 7 / 17 totaltotal 4.6% 28 / 603 CC 117 SCAR 62.1
CC
117
Cov
3%
list_HTML
1482.0
format
506.0
link
156.0
CRAP 498.5
↑ Summary DataTable/DBI.pm »
1 package HTML::DataTable;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use HTML::FromArrayref;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use overload q{""} => \&list_HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 HTML::DataTable - Print HTML tables from Perl data
14  
15 =head1 VERSION
16  
17 Version 0.54
18  
19 =cut
20  
21 1 our $VERSION = 0.54;
22  
23 =head1 SYNOPSIS
24  
25 use HTML::DataTable
26 my $list = HTML::DataTable->new(
27 data => $cgi_data,
28 columns => [
29 # hashrefs describing column formats
30 ],
31 rows => [
32 # arrayrefs listing data to show in table
33 ],
34 );
35 print $list;
36  
37 =head1 METHODS
38  
39 =head2 new()
40  
41 Creates a new HTML::DataTable object.
42  
43 =head3 ATTRIBUTES
44  
45 =head3 header_bg
46  
47 The HTML color code for the background of the first row of the list.
48  
49 =head3 header_bar
50  
51 If this is defined, there will be a 1px black line under the header.
52  
53 =head3 shade_alternate_rows
54  
55 If this is defined, then alternating rows will be colored differently.
56  
57 =head3 light_bg, dark_bg
58  
59 The HTML color codes for the alternating backgrounds of the list rows.
60  
61 =head3 sections
62  
63 If this evaluates to a reference to a subroutine, then that subroutine will be called with each row's values, and when the returned values changes, the table will be divided and the value printed as a section title. (Since there's no value initially, there will be a section title before the first row.)
64  
65 =head3 section_headers
66  
67 If this is defined, the table header will be reprinted after each section title.
68  
69 =head3 alphabet
70  
71 If this is defined, a linked alphabet index will be printed above the table header. Subclasses of this class are responsible for using the "letter" CGI parameter to show the appropriate rows.
72  
73 =head3 search
74  
75 If this is defined, then a field called "search" will be shown in the table header (after the alphabet, if that attribute is also defined). If it evaluates to a reference to a hash, then the keys of the hash will be shown in a SELECT control called "search_columns" after the field. Subclasses of this class are responsible for using these CGI parameters to show the appropriate rows.
76  
77 =head3 data
78  
79 Should be assigned a hashref representing the CGI parameters.
80  
81 =head3 rows
82  
83 One of:
84  
85 * An arrayref listing one arrayref holding the values to appear in each row of the list.
86  
87 * An arrayref listing one hashref holding the values to appear in each row of the list.
88  
89 * A hashref mapping each row's ID to a hashref holding the values to appear in that row of the list, in which case the "sort" attribute should name the hash key by which to sort the hashref entries.
90  
91 =head3 columns
92  
93 An arrayref listing one hashref defining each column of the table. These hashrefs can have these attributes:
94  
95 =head4 header
96  
97 The text to print at the top of this column.
98  
99 =head4 category
100  
101 A second-level header to be printed above the column header; adjacent column's category headers will be merged if they are the same.
102  
103 =head4 format
104  
105 This can be either
106  
107 * A scalar, which will be used as an index in the current row's data array
108  
109 * An arrayref, which will list an index in the current row's data array and singular and plural nouns to append to the value found there
110  
111 * A reference to a subroutine, which will be passed the current row's data array
112  
113 * A hashref, which will map a predefined format name to an index in the current row's data array
114  
115 =head4 none
116  
117 A string to show if the value in that column is undefined. Defaults to "None".
118  
119 =head4 style, class, align
120  
121 If any of these attributes evaluate to a string, they will become the corresponding attributes of each table cell in the column.
122  
123 =head4 action
124  
125 The path or URL of a CGI program to which each entry will linked.
126  
127 =head4 data
128  
129 A reference to a hash listing the CGI parameters to be included in the "action" link. Each value is either a scalar or a reference, as for the "format" attribute.
130  
131 =head4 link_empty
132  
133 If defined, then if the value in the column is undefined the "None" shown will be linked to the "action" URL.
134  
135 =head4 norepeat
136  
137 If this is defined, then the column will be left blank if the value printed would be the same the that for the previous row.
138  
139 =head4 nobr
140  
141 If this is defined, then the column's content will be surrounded by <nobr> tags so it isn't formatted into multiple lines.
142  
143 =cut
144  
145 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
146 0 my $pkg = shift;
147  
148 0 ▶ my $attribs = ref $_[0] ? $_[0] : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
149 0 return bless $attribs, $pkg;
150 }
151  
152 =head3 list_HTML()
153  
154 Returns the HTML that renders the list.
155  
156 =cut
157  
158 0 ▶sub list_HTML {
Subroutine list_HTML: not called CC=38 SCAR=73.0
Pod documented
159 0 my $me = shift;
160  
161 0 my ($html, $title, @cols, $bgcolor);
162  
163 0 ▶ if ( ! $me->{columns} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($me->{"columns"}) 0 0 0
164 0 print "<p>Invalid list definiton.</p>";
165 0 return;
166 }
167  
168 0 ▶ $me->{cellpadding} ||= 1;
Condition0%0/2
$me->{"cellpadding"} ||= 1
l!l
00
MC/DC0%0/1
$me->{"cellpadding"} ||= 1
$me->{"cellpadding"}
Truth table0%0/2
A
A= $me->{"cellpadding"}
Aresult
11
00
169 0 ▶ $me->{cellspacing} ||= 0;
Condition0%0/2
$me->{"cellspacing"} ||= 0
l!l
00
MC/DC0%0/1
$me->{"cellspacing"} ||= 0
$me->{"cellspacing"}
Truth table0%0/2
A
A= $me->{"cellspacing"}
Aresult
11
00
170 0 ▶ $me->{light_bg} ||= '#ffffff';
Condition0%0/2
$me->{"light_bg"} ||= "#ffffff"
l!l
00
MC/DC0%0/1
$me->{"light_bg"} ||= "#ffffff"
$me->{"light_bg"}
Truth table0%0/2
A
A= $me->{"light_bg"}
Aresult
11
00
171 0 ▶ $me->{_bg_color} = $me->{dark_bg} ||= '#eeeeee';
Condition0%0/2
$me->{"dark_bg"} ||= "#eeeeee"
l!l
00
MC/DC0%0/1
$me->{"dark_bg"} ||= "#eeeeee"
$me->{"dark_bg"}
Truth table0%0/2
A
A= $me->{"dark_bg"}
Aresult
11
00
172 0 ▶ $me->{header_bg} ||= $me->{dark_bg};
Condition0%0/3
$me->{"header_bg"} ||= $me->{"dark_bg"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$me->{"header_bg"} ||= $me->{"dark_bg"}
$me->{"header_bg"} $me->{"dark_bg"}
Truth table0%0/3
A ||= B
A= $me->{"header_bg"}B= $me->{"dark_bg"}
ABresult
1X1
011
000
173 0 ▶ $me->{none} ||= 'None';
Condition0%0/2
$me->{"none"} ||= "None"
l!l
00
MC/DC0%0/1
$me->{"none"} ||= "None"
$me->{"none"}
Truth table0%0/2
A
A= $me->{"none"}
Aresult
11
00
174 0 ▶ $me->{shade_alternate_rows} = 'no' if grep $_->{shade_alternate_vals}, @{$me->{columns}};
Branch: 1 branch
BranchTrueFalseTotal
if grep $_->{"shade_alternate_vals"}, @{$$me{"columns"};} 0 0 0
175  
176 0 $me->{columns}->[0]->{class} = 'first_col';
177  
178 0 ▶ if ( $me->{alphabet} and ! $me->{data}->{search} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"alphabet"} and not $me->{"data"}{"search"}) 0 0 0
Condition0%0/3
$me->{"alphabet"} and not $me->{"data"}{"search"}
!ll&&!rl&&r
000
MC/DC0%0/2
$me->{"alphabet"} and not $me->{"data"}{"search"}
$me->{"alphabet"} not $me->{"data"}{"search"}
Truth table0%0/3
A and not(B)
A= $me->{"alphabet"}B= not $me->{"data"}{"search"}
ABresult
0X0
100
111
179 0 ▶ $me->set_letter( $me->{data}->{letter} ||= 'a' );
Condition0%0/2
$me->{"data"}{"letter"} ||= "a"
l!l
00
MC/DC0%0/1
$me->{"data"}{"letter"} ||= "a"
$me->{"data"}{"letter"}
Truth table0%0/2
A
A= $me->{"data"}{"letter"}
Aresult
11
00
180 }
181  
182 0 ▶ if ( $me->{data}->{search} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"data"}{"search"}) 0 0 0
183 0 $me->set_search();
184 }
185  
186 # SET ORDER BY IF SORTING ##############
187  
188 0 ▶ delete $me->{data}->{sort} if defined $me->{data}->{sort} and $me->{data}->{sort} eq $me->{sort}->[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $me->{"data"}{"sort"} and $me->{"data"}{"sort"} eq $me->{"sort"}[0] 0 0 0
Condition0%0/3
defined $me->{"data"}{"sort"} and $me->{"data"}{"sort"} eq $me->{"sort"}[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $me->{"data"}{"sort"} and $me->{"data"}{"sort"} eq $me->{"sort"}[0]
defined $me->{"data"}{"sort"} $me->{"data"}{"sort"} eq $me->{"sort"}[0]
Truth table0%0/3
A and B
A= defined $me->{"data"}{"sort"}B= $me->{"data"}{"sort"} eq $me->{"sort"}[0]
ABresult
0X0
100
111
189 0 ▶ unshift @{$me->{sort}}, $me->{data}->{sort} if defined $me->{data}->{sort};
Branch: 1 branch
BranchTrueFalseTotal
if defined $me->{"data"}{"sort"} 0 0 0
190  
191 0 ▶ delete $me->{data}->{sort_dir} if defined $me->{data}->{sort_dir} and $me->{data}->{sort_dir} eq 'asc';
Branch: 1 branch
BranchTrueFalseTotal
if defined $me->{"data"}{"sort_dir"} and $me->{"data"}{"sort_dir"} eq "asc" 0 0 0
Condition0%0/3
defined $me->{"data"}{"sort_dir"} and $me->{"data"}{"sort_dir"} eq "asc"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $me->{"data"}{"sort_dir"} and $me->{"data"}{"sort_dir"} eq "asc"
defined $me->{"data"}{"sort_dir"} $me->{"data"}{"sort_dir"} eq "asc"
Truth table0%0/3
A and B
A= defined $me->{"data"}{"sort_dir"}B= $me->{"data"}{"sort_dir"} eq "asc"
ABresult
0X0
100
111
192 0 ▶ $me->{sort_dir} = $me->{data}->{sort_dir} if defined $me->{data}->{sort_dir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $me->{"data"}{"sort_dir"} 0 0 0
193 0 ▶ if ( $me->{sort} ) { $me->set_sort_order }
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"sort"}) 0 0 0
194  
195 # PRINT LIST #############
196  
197 0 $me->{n_cols} = scalar( @{$me->{columns}} );
198  
199 0 ▶ $html .= qq(<p class="hed">$me->{hed}</p>) if $me->{hed};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"hed"} 0 0 0
200 0 ▶ $me->{cellpadding} ||= 1;
Condition0%0/2
$me->{"cellpadding"} ||= 1
l!l
00
MC/DC0%0/1
$me->{"cellpadding"} ||= 1
$me->{"cellpadding"}
Truth table0%0/2
A
A= $me->{"cellpadding"}
Aresult
11
00
201 0 ▶ $me->{cellspacing} ||= 0;
Condition0%0/2
$me->{"cellspacing"} ||= 0
l!l
00
MC/DC0%0/1
$me->{"cellspacing"} ||= 0
$me->{"cellspacing"}
Truth table0%0/2
A
A= $me->{"cellspacing"}
Aresult
11
00
202 0 my $table_attribs = join ' ', map qq($_="$me->{$_}"), grep exists $me->{$_},
203 qw( border width cellspacing cellpadding class id style );
204 0 $html .= qq(<table $table_attribs>);
205 0 ▶ $html .= qq(<form method="get">) if $me->{search};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"search"} 0 0 0
206  
207 # List header ###########
208  
209 0 ▶ my $alphabet = $me->alphabet if $me->{alphabet};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"alphabet"} 0 0 0
210 0 ▶ my $search = $me->search_form if $me->{search} and ! $me->{hide_search_form};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"search"} and not $me->{"hide_search_form"} 0 0 0
Condition0%0/3
$me->{"search"} and not $me->{"hide_search_form"}
!ll&&!rl&&r
000
MC/DC0%0/2
$me->{"search"} and not $me->{"hide_search_form"}
$me->{"search"} not $me->{"hide_search_form"}
Truth table0%0/3
A and not(B)
A= $me->{"search"}B= not $me->{"hide_search_form"}
ABresult
0X0
100
111
211  
212 # Alphabet
213 0 ▶ $html .= qq(<tr><td align="center" colspan="$me->{n_cols}" class="first_col" id="alphabet">$alphabet$search</td></tr>)
Branch: 1 branch
BranchTrueFalseTotal
if $alphabet or $search 0 0 0
Condition0%0/3
$alphabet or $search
l!l&&r!l&&!r
000
MC/DC0%0/2
$alphabet or $search
$alphabet $search
Truth table0%0/3
A or B
A= $alphabetB= $search
ABresult
1X1
011
000
214 if $alphabet or $search;
215  
216 # Table header
217 $html .= $me->header unless
218 defined $me->{header} and $me->{header} eq 'no'
219 0 ▶ or ( $me->{sections} and $me->{header} ne 'yes' );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $me->{"header"} and $me->{"header"} eq "no" or $me->{"sections"} and $me->{"header"} ne "yes" 0 0 0
Condition0%0/9
defined $me->{"header"} and $me->{"header"} eq "no" or $me->{"sections"} and $me->{"header"} ne "yes"
l!l&&r!l&&!r
000
defined $me->{"header"} and $me->{"header"} eq "no"
!ll&&!rl&&r
000
$me->{"sections"} and $me->{"header"} ne "yes"
!ll&&!rl&&r
000
MC/DC0%0/4
defined $me->{"header"} and $me->{"header"} eq "no" or $me->{"sections"} and $me->{"header"} ne "yes"
defined $me->{"header"} $me->{"header"} eq "no" $me->{"sections"} $me->{"header"} ne "yes"
Truth table0%0/7
A and B or C and D
A= defined $me->{"header"}B= $me->{"header"} eq "no"C= $me->{"sections"}D= $me->{"header"} ne "yes"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
220  
221 # Print rows ###################
222  
223 0 my $rows;
224 0 ▶ while ( my $d = $me->next_row ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $me->next_row) 0 0 0
225 0 $rows .= $me->table_row( $d );
226 }
227  
228 0 ▶ if ( ! $rows and $me->{hide_if_empty} ) { return '' }
Branch: 1 branch
BranchTrueFalseTotal
if (not $rows and $me->{"hide_if_empty"}) 0 0 0
Condition0%0/3
not $rows and $me->{"hide_if_empty"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $rows and $me->{"hide_if_empty"}
not $rows $me->{"hide_if_empty"}
Truth table0%0/3
not(A) and B
A= not $rowsB= $me->{"hide_if_empty"}
ABresult
0X0
100
111
229  
230 0 $html .= $rows;
231  
232 0 ▶ $html .= qq(</form>) if $me->{search};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"search"} 0 0 0
233 0 $html .= '</table>';
234  
235 0 ▶ $html .= << "" if $me->{javascript};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"javascript"} 0 0 0
236 <script type="text/javascript" charset="utf-8">
237 $me->{javascript}
238 </script>
239  
240 0 return $html;
241 }
242  
243 0 ▶sub header {
Subroutine header: not called CC=9 SCAR=45.0
Pod documented
244 0 my $me = shift;
245  
246 0 my $html;
247  
248 0 ▶ if ( grep $_->{category}, @{$me->{columns}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep $_->{"category"}, @{$$me{"columns"};}) 0 0 0
249 0 $html = qq(<tr bgcolor="$me->{header_bg}" valign="bottom">);
250 0 my ($prev_col, $i_col, $colspan);
251 0 for my $col ( @{$me->{columns}}, { category => '_END_OF_COLUMNS' } ) {
252 0 ▶ $colspan++ if $i_col;
Branch: 1 branch
BranchTrueFalseTotal
if $i_col 0 0 0
253 0 ▶ if ( $i_col++ and $col->{category} ne $prev_col->{category} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_col++ and $col->{"category"} ne $prev_col->{"category"}) 0 0 0
Condition0%0/3
$i_col++ and $col->{"category"} ne $prev_col->{"category"}
!ll&&!rl&&r
000
MC/DC0%0/2
$i_col++ and $col->{"category"} ne $prev_col->{"category"}
$i_col++ $col->{"category"} ne $prev_col->{"category"}
Truth table0%0/3
A and B
A= $i_col++B= $col->{"category"} ne $prev_col->{"category"}
ABresult
0X0
100
111
254 $html .= HTML
255 [ th => { colspan => $colspan, class => $col->{class}, style => 'text-align: center; font-weight: bold' },
256 0 ▶ [ $col->{nobr} && 'nobr', $prev_col->{category} ]
Condition0%0/2
$col->{'nobr'} && 'nobr'
!ll
00
MC/DC0%0/1
$col->{'nobr'} && 'nobr'
$col->{'nobr'}
Truth table0%0/2
A
A= $col->{'nobr'}
Aresult
00
11
257 ];
258 0 $colspan = 0;
259 }
260 0 $prev_col = $col;
261 }
262 0 $html .= qq(</tr>);
263 }
264  
265 0 $html .= qq(<tr bgcolor="$me->{header_bg}" valign="bottom" class="nodrag nodrop">);
266 0 for my $col ( @{$me->{columns}} ) {
267 0 $html .= $me->column_header( $col );
268 }
269 0 $html .= qq(</tr>);
270  
271 0 ▶ $html .= $me->header_bar if $me->{header_bar};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"header_bar"} 0 0 0
272  
273 0 return $html;
274 }
275  
276 0 ▶sub column_header {
Subroutine column_header: not called CC=9 SCAR=45.0
Pod undocumented
277 0 my ($me, $col) = @_;
278  
279 0 my $content;
280  
281 0 ▶ if ( $col->{sort} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col->{'sort'}) { } 0 0 0
282 0 ▶ if ( $col->{sort} eq $me->{sort}->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col->{'sort'} eq $me->{'sort'}[0]) { } 0 0 0
283 0 ▶ my ($other_dir, $dir_link) = $me->{sort_dir} eq 'desc' ? ('asc', '/') : ('desc', '\\');
Branch: 1 branch
BranchTrueFalseTotal
$me->{'sort_dir'} eq 'desc' ? : 0 0 0
284 0 $content = [ a => { href => $me->query_string( sort_dir => $other_dir ) }, [ b => $col->{header} ] ];
285 } else {
286 0 $content = [ a => { href => $me->query_string( sort => $col->{sort} ) }, $col->{header} ];
287 }
288 } else {
289 0 $content = $col->{header};
290 }
291  
292 return HTML [ th => { class => $col->{class}, style => $col->{header_style} || $col->{style} || undef },
293 [ $col->{nobr} && 'nobr',
294 $content,
295 0 ▶ defined $col->{data} && $col->{add} && ( ' (', [[ $me->link( $col, 'Add' ) ]], ')' )
Condition0%0/13
$col->{'header_style'} || $col->{'style'} || undef
l!l
00
$col->{"header_style"} or $col->{"style"}
l!l&&r!l&&!r
000
$col->{'nobr'} && 'nobr'
!ll
00
defined $col->{'data'} && $col->{'add'} && (' (', [[$me->link($col, 'Add')]], ')')
!ll&&!rl&&r
000
defined $col->{"data"} and $col->{"add"}
!ll&&!rl&&r
000
MC/DC0%0/2
$col->{'header_style'} || $col->{'style'} || undef
$col->{"header_style"} $col->{"style"}
MC/DC0%0/1
$col->{'nobr'} && 'nobr'
$col->{'nobr'}
MC/DC0%0/3
defined $col->{'data'} && $col->{'add'} && (' (', [[$me->link($col, 'Add')]], ')')
defined $col->{"data"} $col->{"add"} (' (', [[$me->link($col, 'Add')]], ')')
Truth table0%0/3
A or B
A= $col->{"header_style"}B= $col->{"style"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $col->{'nobr'}
Aresult
00
11
Truth table0%0/4
A and B && C
A= defined $col->{"data"}B= $col->{"add"}C= (' (', [[$me->link($col, 'Add')]], ')')
ABCresult
0XX0
10X0
1100
1111
296 ]
297 ];
298 }
299  
300 0 ▶sub header_bar {
Subroutine header_bar: not called CC=1 SCAR=6.9
Pod documented
301 0 my $me = shift;
302  
303 return HTML [ tr => { height => 1, valign => 'bottom', class => 'nodrag nodrop' },
304 0 [ td => { height => 1, colspan => $me->{n_cols}, id => 'header_bar' },
305 [ table => { cellspacing => 0, cellpadding => 0, height => 1, width => '100%' },
306 [ tr => { height => 1, bgcolor => '#000000' }, [ 'td' ] ]
307 ]
308 ]
309 ];
310 }
311  
312 0 ▶sub set_letter { }
Subroutine set_letter: not called CC=1 SCAR=0.0
Pod undocumented
313  
314 0 ▶sub search_form {
Subroutine search_form: not called CC=2 SCAR=17.9
Pod undocumented
315 0 my $me = shift;
316  
317 return HTML
318 [ input => { name => 'search', value => $me->{data}->{search} } ],
319 ref $me->{search} eq 'HASH' && [ select => { name => 'search_columns' },
320 0 ▶ map [ option => $_ ], keys %{$me->{search}}
Condition0%0/2
ref $me->{'search'} eq 'HASH' && ['select', {'name', 'search_columns'}, map(['option', $_], keys %{$$me{'search'};})]
!ll
00
MC/DC0%0/1
ref $me->{'search'} eq 'HASH' && ['select', {'name', 'search_columns'}, map(['option', $_], keys %{$$me{'search'};})]
ref $me->{'search'} eq 'HASH'
Truth table0%0/2
A
A= ref $me->{'search'} eq 'HASH'
Aresult
00
11
321 ];
322 }
323  
324 0 ▶sub set_sort_order { }
Subroutine set_sort_order: not called CC=1 SCAR=0.0
Pod undocumented
325  
326 0 ▶sub next_row {
Subroutine next_row: not called CC=4 SCAR=30.0
Pod undocumented
327 0 my $me = shift;
328  
329 0 ▶ if ( ref $me->{rows} eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $me->{'rows'} eq 'ARRAY') { } 0 0 0
elsif (ref $me->{'rows'} eq 'HASH') { } 0 0 0
330 0 return shift @{$me->{rows}};
331 } elsif ( ref $me->{rows} eq 'HASH' ) {
332 0 ▶ my $sorter = sub{ $me->{rows}->{ $_[0] }->{ $me->{sort} || 'name' } };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$me->{'sort'} || 'name'
l!l
00
MC/DC0%0/1
$me->{'sort'} || 'name'
$me->{'sort'}
Truth table0%0/2
A
A= $me->{'sort'}
Aresult
11
00
333 return $me->{rows}->{
334 0 ▶ shift @{ $me->{_row_hash_ids} ||= [ sort { $sorter->($a) cmp $sorter->($b) } keys %{$me->{rows}} ] }
Condition0%0/2
$me->{"_row_hash_ids"} ||= [(sort {&$sorter($a) cmp &$sorter($b);} keys %{$$me{"rows"};})]
l!l
00
MC/DC0%0/1
$me->{"_row_hash_ids"} ||= [(sort {&$sorter($a) cmp &$sorter($b);} keys %{$$me{"rows"};})]
$me->{"_row_hash_ids"}
Truth table0%0/2
A
A= $me->{"_row_hash_ids"}
Aresult
11
00
335 };
336 }
337 }
338  
339 0 ▶sub table_row {
Subroutine table_row: not called CC=8 SCAR=42.8
Pod undocumented
340 0 my ($me, $d) = @_;
341  
342 0 my $html;
343  
344 # Start a new section if section has changed
345 0 ▶ if ( $me->{sections} and $me->{_section} ne ( my $section = $me->{sections}->( @$d ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"sections"} and $me->{"_section"} ne (my $section = $me->{"sections"}->(@$d))) 0 0 0
Condition0%0/3
$me->{"sections"} and $me->{"_section"} ne (my $section = $me->{"sections"}->(@$d))
!ll&&!rl&&r
000
MC/DC0%0/2
$me->{"sections"} and $me->{"_section"} ne (my $section = $me->{"sections"}->(@$d))
$me->{"sections"} $me->{"_section"} ne (my $section = $me->{"sections"}->(@$d))
Truth table0%0/3
A and B
A= $me->{"sections"}B= $me->{"_section"} ne (my $section = $me->{"sections"}->(@$d))
ABresult
0X0
100
111
346 0 $html .= qq(<tr valign="top"><td colspan="$me->{n_cols}" class="section_header first_col"><p class="hed">$section</p></td></tr>);
347 0 ▶ $html .= $me->header if $me->{section_headers} ne 'no';
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"section_headers"} ne "no" 0 0 0
348 0 $me->{_section} = $section;
349 0 $me->{_bgcolor} = $me->{dark_bg};
350 }
351  
352 0 my $cells;
353 0 for my $col ( @{$me->{columns}} ) {
354 0 $cells .= $me->table_cell( $col, $d );
355 }
356  
357 # Change row bgcolor
358 0 ▶ $me->switch_bgs unless defined $me->{shade_alternate_rows} and $me->{shade_alternate_rows} eq 'no';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $me->{"shade_alternate_rows"} and $me->{"shade_alternate_rows"} eq "no" 0 0 0
Condition0%0/3
defined $me->{"shade_alternate_rows"} and $me->{"shade_alternate_rows"} eq "no"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $me->{"shade_alternate_rows"} and $me->{"shade_alternate_rows"} eq "no"
defined $me->{"shade_alternate_rows"} $me->{"shade_alternate_rows"} eq "no"
Truth table0%0/3
A and B
A= defined $me->{"shade_alternate_rows"}B= $me->{"shade_alternate_rows"} eq "no"
ABresult
0X0
100
111
359  
360 $html .= HTML [ tr =>
361 {
362 valign => 'top',
363 bgcolor => $me->{_bgcolor},
364 0 ▶ id => defined $me->{row_id_col} && join '-', 'row', $d->[$me->{row_id_col} ]
Condition0%0/3
defined $me->{'row_id_col'} && join('-', 'row', $$d[$me->{'row_id_col'}])
!ll&&!rl&&r
000
MC/DC0%0/2
defined $me->{'row_id_col'} && join('-', 'row', $$d[$me->{'row_id_col'}])
defined $me->{'row_id_col'} join('-', 'row', $$d[$me->{'row_id_col'}])
Truth table0%0/3
A && B
A= defined $me->{'row_id_col'}B= join('-', 'row', $$d[$me->{'row_id_col'}])
ABresult
0X0
100
111
365 },
366 [[ $cells ]]
367 ];
368  
369 0 return $html;
370  
371 }
372  
373 0 ▶sub switch_bgs {
Subroutine switch_bgs: not called CC=3 SCAR=24.8
Pod undocumented
374 0 my $me = shift;
375  
376 $me->{_bgcolor} = ( defined $me->{_bgcolor} and $me->{_bgcolor} eq $me->{light_bg} ) ?
377 0 ▶ $me->{dark_bg} : $me->{light_bg};
Branch: 1 branch
BranchTrueFalseTotal
defined $me->{'_bgcolor'} && $me->{'_bgcolor'} eq $me->{'light_bg'} ? : 0 0 0
Condition0%0/3
defined $me->{"_bgcolor"} and $me->{"_bgcolor"} eq $me->{"light_bg"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $me->{"_bgcolor"} and $me->{"_bgcolor"} eq $me->{"light_bg"}
defined $me->{"_bgcolor"} $me->{"_bgcolor"} eq $me->{"light_bg"}
Truth table0%0/3
A and B
A= defined $me->{"_bgcolor"}B= $me->{"_bgcolor"} eq $me->{"light_bg"}
ABresult
0X0
100
111
378 }
379  
380 0 ▶sub table_cell {
Subroutine table_cell: not called CC=3 SCAR=24.8
Pod undocumented
381 0 my ($me, $col, $d) = @_;
382  
383 0 ▶ $col->{none} ||= $me->{none};
Condition0%0/3
$col->{"none"} ||= $me->{"none"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$col->{"none"} ||= $me->{"none"}
$col->{"none"} $me->{"none"}
Truth table0%0/3
A ||= B
A= $col->{"none"}B= $me->{"none"}
ABresult
1X1
011
000
384  
385 0 my $content;
386  
387 0 $content = $me->format( $col, $d );
388  
389 return HTML [ td => { style => $col->{style}, class => $col->{class}, align => $col->{align} },
390 0 ▶ [ $col->{nobr} && 'nobr',
Condition0%0/2
$col->{'nobr'} && 'nobr'
!ll
00
MC/DC0%0/1
$col->{'nobr'} && 'nobr'
$col->{'nobr'}
Truth table0%0/2
A
A= $col->{'nobr'}
Aresult
00
11
391 [[ $content ]]
392 ]
393 ];
394 }
395  
396 0 ▶sub format {
Subroutine format: not called CC=22 SCAR=62.3
Pod documented
397 0 my ($me, $col, $d) = @_;
398  
399 0 my @data;
400  
401 # Upgrade $col->{format} to a subroutine ref
402 0 ▶ if ( ! ref $col->{format} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $col->{'format'}) { } 0 0 0
elsif (ref $col->{'format'} eq 'ARRAY') { } 0 0 0
elsif (ref $col->{'format'} eq 'HASH') { } 0 0 0
403 # the "format" attribute can be either an index into an array or a key into a hash
404 0 ▶ if ( $col->{format} =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col->{'format'} =~ /\D/) { } 0 0 0
405 0 ▶ $col->{formatter} ||= sub { my %d = @_; $d{ $col->{format} } };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$col->{"formatter"} ||= sub { my(%d) = @_; $d{$col->{"format"}}; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$col->{"formatter"} ||= sub { my(%d) = @_; $d{$col->{"format"}}; }
$col->{"formatter"} sub { my(%d) = @_; $d{$col->{"format"}}; }
Truth table0%0/3
A ||= B
A= $col->{"formatter"}B= sub { my(%d) = @_; $d{$col->{"format"}}; }
ABresult
1X1
011
000
406 0 @data = ( %$d );
407 } else {
408 0 ▶ $col->{formatter} ||= sub { $_[ $col->{format} ] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$col->{"formatter"} ||= sub { $_[$col->{"format"}]; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$col->{"formatter"} ||= sub { $_[$col->{"format"}]; }
$col->{"formatter"} sub { $_[$col->{"format"}]; }
Truth table0%0/3
A ||= B
A= $col->{"formatter"}B= sub { $_[$col->{"format"}]; }
ABresult
1X1
011
000
409 0 @data = ( @$d );
410 }
411 } elsif ( ref $col->{format} eq 'ARRAY' ) {
412 # or it can be a reference to an array mapping the index to a noun and optional plural
413 0 ▶ $col->{formatter} ||= sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
414 0 my ($index, $noun, $plural) = @{$col->{format}};
415 0 my $value = $_[ $index ];
416 0 ▶ return 0 if $value == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $value == 0 0 0 0
417 0 ▶ $noun .= 's' if $value > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $value > 1 0 0 0
418 0 ▶ $noun = $plural if $value > 1 and $plural;
Branch: 1 branch
BranchTrueFalseTotal
if $value > 1 and $plural 0 0 0
Condition0%0/3
$value > 1 and $plural
!ll&&!rl&&r
000
MC/DC0%0/2
$value > 1 and $plural
$value > 1 $plural
Truth table0%0/3
A and B
A= $value > 1B= $plural
ABresult
0X0
100
111
419 0 return "$value $noun";
420 0 ▶ };
Condition0%0/3
$col->{"formatter"} ||= sub { my($index, $noun, $plural) = @{$col->{"format"};}; my $value = $_[$index]; return 0 if $value == 0; $noun .= 's' if $value > 1; $noun = $plural if $value > 1 and $plural; return "$value $noun"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$col->{"formatter"} ||= sub { my($index, $noun, $plural) = @{$col->{"format"};}; my $value = $_[$index]; return 0 if $value == 0; $noun .= 's' if $value > 1; $noun = $plural if $value > 1 and $plural; return "$value $noun"; }
$col->{"formatter"} sub { my($index, $noun, $plural) = @{$col->{"format"};}; my $value = $_[$index]; return 0 if $value == 0; $noun .= 's' if $value > 1; $noun = $plural if $value > 1 and $plural; return "$value $noun"; }
Truth table0%0/3
A ||= B
A= $col->{"formatter"}B= sub { my($index, $noun, $plural) = @{$col->{"format"};}; my $value = $_[$index]; return 0 if $value == 0; $noun .= 's' if $value > 1; $noun = $plural if $value > 1 and $plural; return "$value $noun"; }
ABresult
1X1
011
000
421 0 @data = ( @$d );
422 } elsif ( ref $col->{format} eq 'HASH' ) {
423 # or it can be a reference to a hash mapping a predefined format to an index into the data
424 0 ▶ if ( ! $col->{formatter} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($col->{"formatter"}) 0 0 0
425 0 my ($format, $index) = each %{$col->{format}};
426 $col->{formatter} = {
427 0 ▶ date => sub { my @parts = split /\D/, $_[$index]; join '/', grep $_, @parts[1,2,0]; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
428 0 ▶ datetime => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
429 0 my @parts = split /\D/, $_[$index];
430 0 join ' ', join( '/', grep $_, @parts[1,2,0] ), join( ':', grep $_, @parts[3,4,5] );
431 },
432 0 ▶ }->{$format} || sub { "UNKNOWN FORMAT NAME $format" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
{'date', sub { my @parts = split(/\D/, $_[$index], 0); join '/', grep($_, @parts[1, 2, 0]); } , 'datetime', sub { my @parts = split(/\D/, $_[$index], 0); join ' ', join('/', grep($_, @parts[1, 2, 0])), join(':', grep($_, @parts[3, 4, 5])); } }->{$format} || sub { "UNKNOWN FORMAT NAME $format"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
{'date', sub { my @parts = split(/\D/, $_[$index], 0); join '/', grep($_, @parts[1, 2, 0]); } , 'datetime', sub { my @parts = split(/\D/, $_[$index], 0); join ' ', join('/', grep($_, @parts[1, 2, 0])), join(':', grep($_, @parts[3, 4, 5])); } }->{$format} || sub { "UNKNOWN FORMAT NAME $format"; }
{'date', sub { my @parts = split(/\D/, $_[$index], 0); join '/', grep($_, @parts[1, 2, 0]); } , 'datetime', sub { my @parts = split(/\D/, $_[$index], 0); join ' ', join('/', grep($_, @parts[1, 2, 0])), join(':', grep($_, @parts[3, 4, 5])); } }->{$format} sub { "UNKNOWN FORMAT NAME $format"; }
Truth table0%0/3
A || B
A= {'date', sub { my @parts = split(/\D/, $_[$index], 0); join '/', grep($_, @parts[1, 2, 0]); } , 'datetime', sub { my @parts = split(/\D/, $_[$index], 0); join ' ', join('/', grep($_, @parts[1, 2, 0])), join(':', grep($_, @parts[3, 4, 5])); } }->{$format}B= sub { "UNKNOWN FORMAT NAME $format"; }
ABresult
1X1
011
000
433 }
434 0 @data = ( @$d );
435 } else {
436 # or it can already be a reference to a subroutine
437 0 ▶ $col->{formatter} ||= $col->{format};
Condition0%0/3
$col->{"formatter"} ||= $col->{"format"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$col->{"formatter"} ||= $col->{"format"}
$col->{"formatter"} $col->{"format"}
Truth table0%0/3
A ||= B
A= $col->{"formatter"}B= $col->{"format"}
ABresult
1X1
011
000
438 0 @data = ( @$d );
439 }
440  
441 0 my $test = $col->{test};
442  
443 0 my $formatted;
444  
445 0 ▶ if (
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $test eq 'CODE' && !&$test(@data) and $formatted = $col->{'formatter'}->(map({$col->{'contains_html'} ? $_ : &HTML($_);} @data))) { } 0 0 0
elsif ($col->{'action'} and $col->{'link_empty'}) { } 0 0 0
elsif ($col->{'none_not_dimmed'}) { } 0 0 0
Condition0%0/6
not ref $test eq "CODE" && !&$test(@data) and $formatted = $col->{"formatter"}->(map({$col->{"contains_html"} ? $_ : &HTML($_);} @data))
!ll&&!rl&&r
000
ref $test eq 'CODE' && !&$test(@data)
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $test eq "CODE" && !&$test(@data) and $formatted = $col->{"formatter"}->(map({$col->{"contains_html"} ? $_ : &HTML($_);} @data))
ref $test eq 'CODE' !&$test(@data) $formatted = $col->{"formatter"}->(map({$col->{"contains_html"} ? $_ : &HTML($_);} @data))
Truth table0%0/5
not(A && not(B)) and C
A= ref $test eq 'CODE'B= !&$test(@data)C= $formatted = $col->{"formatter"}->(map({$col->{"contains_html"} ? $_ : &HTML($_);} @data))
ABCresult
11X0
0X00
1000
0X11
1011
446 ! ( ref $test eq 'CODE' and ! $test->(@data) )
447 and $formatted = $col->{formatter}->(
448 0 ▶ map { $col->{contains_html} ? $_ : HTML $_ } @data
Branch: 1 branch
BranchTrueFalseTotal
$col->{'contains_html'} ? : 0 0 0
449 )
450 ) {
451  
452 0 ▶ if ( $col->{norepeat} and $formatted eq $col->{_prev_value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col->{'norepeat'} and $formatted eq $col->{'_prev_value'}) { } 0 0 0
Condition0%0/3
$col->{"norepeat"} and $formatted eq $col->{"_prev_value"}
!ll&&!rl&&r
000
MC/DC0%0/2
$col->{"norepeat"} and $formatted eq $col->{"_prev_value"}
$col->{"norepeat"} $formatted eq $col->{"_prev_value"}
Truth table0%0/3
A and B
A= $col->{"norepeat"}B= $formatted eq $col->{"_prev_value"}
ABresult
0X0
100
111
453 0 $formatted = '';
454 } else {
455 0 ▶ $me->switch_bgs if $col->{shade_alternate_vals};
Branch: 1 branch
BranchTrueFalseTotal
if $col->{"shade_alternate_vals"} 0 0 0
456 0 $col->{_prev_value} = $formatted;
457 0 ▶ $formatted = $me->link( $col, $formatted, $d ) if $col->{action};
Branch: 1 branch
BranchTrueFalseTotal
if $col->{"action"} 0 0 0
458 }
459  
460 ▶ } elsif ( $col->{action} and $col->{link_empty} ) {
Condition0%0/3
$col->{"action"} and $col->{"link_empty"}
!ll&&!rl&&r
000
MC/DC0%0/2
$col->{"action"} and $col->{"link_empty"}
$col->{"action"} $col->{"link_empty"}
Truth table0%0/3
A and B
A= $col->{"action"}B= $col->{"link_empty"}
ABresult
0X0
100
111
461  
462 0 $formatted = $me->link( $col, $col->{none}, $d );
463  
464 } elsif ( $col->{none_not_dimmed} ) {
465  
466 0 $formatted = $col->{none};
467  
468 } else {
469  
470 0 $formatted = qq(<span style="color: gray">$col->{none}</span>);
471  
472 }
473  
474 0 return $formatted;
475  
476 }
477  
478 0 ▶sub link {
Subroutine link: not called CC=12 SCAR=50.5
Pod undocumented
479 0 my ($me, $col, $formatted, $d) = @_;
480  
481 0 ▶ my $action = $col->{action} || $me->{action}; # . ( $col->{action} =~ /\?/ ? '&' : '?' );
Condition0%0/3
$col->{'action'} || $me->{'action'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$col->{'action'} || $me->{'action'}
$col->{'action'} $me->{'action'}
Truth table0%0/3
A || B
A= $col->{'action'}B= $me->{'action'}
ABresult
1X1
011
000
482 0 ▶ if ( ref $action eq 'CODE' ) { $action = $action->(@$d) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $action eq "CODE") 0 0 0
483 0 ▶ return $formatted unless $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
484  
485 0 my %query_data;
486  
487 0 ▶ while ( my ($q_key, $q_format) = each %{$col->{data}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$col{"data"};}) 0 0 0
488 # The datum's 'format' attribute can be a reference to a subroutine,
489 # in which case we execute it; the word 'format', in which case we use
490 # the column's formatted value; or any other value, which we use unaltered.
491 0 ▶ next unless $q_format;
Branch: 1 branch
BranchTrueFalseTotal
unless $q_format 0 0 0
492 0 ▶ if ( ref $q_format eq 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $q_format eq 'CODE') { } 0 0 0
elsif ($q_format eq 'format') { } 0 0 0
493 0 $query_data{$q_key} = $q_format->(@$d);
494 } elsif ( $q_format eq 'format' ) {
495 0 $query_data{$q_key} = $formatted;
496 } else {
497 0 $query_data{$q_key} = $q_format;
498 }
499 0 $query_data{$q_key} =~ s|(\W)|sprintf("%%%x", ord($1))|eg;
500 }
501  
502 0 ▶ $me->{first_row_data} ||= \%query_data;
Condition0%0/2
$me->{"first_row_data"} ||= \%query_data
l!l
00
MC/DC0%0/1
$me->{"first_row_data"} ||= \%query_data
$me->{"first_row_data"}
Truth table0%0/2
A
A= $me->{"first_row_data"}
Aresult
11
00
503  
504 0 ▶ my $query_string = join '&', ( map { join '=', $_, $query_data{$_} } grep defined $query_data{$_}, keys %query_data ) if %query_data;
Branch: 1 branch
BranchTrueFalseTotal
if %query_data 0 0 0
505 0 ▶ $action .= ( $action =~ /\?/ ? '&' : '?' ) if $query_string;
Branch: 2 branches
BranchTrueFalseTotal
if $query_string 0 0 0
$action =~ /\?/ ? : 0 0 0
506 0 return HTML [ a => { href => "$action$query_string" }, [[ $formatted ]] ];
507 }
508  
509 0 ▶sub alphabet {
Subroutine alphabet: not called CC=5 SCAR=34.0
Pod documented
510 0 my $me = shift;
511  
512 0 my @alphabet;
513  
514 0 ▶ my $letter = $me->{data}->{letter} || 'a';
Condition0%0/2
$me->{'data'}{'letter'} || 'a'
l!l
00
MC/DC0%0/1
$me->{'data'}{'letter'} || 'a'
$me->{'data'}{'letter'}
Truth table0%0/2
A
A= $me->{'data'}{'letter'}
Aresult
11
00
515 0 ▶ undef $letter if $me->{data}->{search};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"data"}{"search"} 0 0 0
516 0 for my $l ( 'A' .. 'Z' ) {
517 0 ▶ push @alphabet,
Branch: 1 branch
BranchTrueFalseTotal
lc $l eq lc $letter ? : 0 0 0
518 lc $l eq lc $letter ?
519 "<b>$l</b> " :
520 q(<a href=") . $me->query_string( letter => $l, search => undef ) . qq(">$l</a> );
521 }
522 0 return join ' ', @alphabet;
523 }
524  
525 0 ▶sub query_string {
Subroutine query_string: not called CC=2 SCAR=17.9
Pod undocumented
526 0 my $me = shift;
527 0 my %replace = @_;
528  
529 0 my %data = %{$me->{data}};
530 0 @data{ keys %replace } = values %replace;
531 0 ▶ return ( %data ? '?' : '' ) . join '&', map "$_=$data{$_}", grep $data{$_}, keys %data;
Branch: 1 branch
BranchTrueFalseTotal
%data ? : 0 0 0
532 }
533  
534 =head3 xls
535  
536 Returns the list as an Excel spreadsheet.
537  
538 =cut
539  
540 0 ▶sub xls {
Subroutine xls: not called CC=6 SCAR=37.4
Pod documented
541 0 my $me = shift;
542  
543 0 require Spreadsheet::WriteExcel;
544  
545 0 ▶ open my $fh, '>', \my $str or die "Failed to open filehandle: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", \my $str or die "Failed to open filehandle: $!" 0 0 0
546 0 my $workbook = Spreadsheet::WriteExcel->new( $fh );
547  
548 0 my $worksheet = $workbook->addworksheet("Data");
549 0 $worksheet->set_column('A:AZ', 40);
550  
551 0 my $i_col = 0;
552 0 for ( @{$me->{columns}} ) {
553 0 $worksheet->write_string( 0, $i_col++, $_->{header} );
554 }
555 0 $worksheet->freeze_panes(1, 0);
556  
557 0 ▶ if ( $me->{sort} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"sort"}) 0 0 0
558 0 $me->set_sort_order;
559 }
560  
561 0 my $i_row = 1;
562 0 ▶ while ( my $data = $me->next_row ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $me->next_row) 0 0 0
563 0 $i_col = 0;
564 0 for my $col ( @{$me->{columns}} ) {
565 0 $col->{none_not_dimmed} = 'y';
566 0 delete $col->{action};
567 0 $col->{contains_html} = 'y';
568 0 $worksheet->write_string( $i_row, $i_col++, $me->format( $col, $data ) );
569 }
570 0 $i_row++;
571 }
572  
573 0 $workbook->close;
574  
575 0 $str;
576  
577 }
578  
579 1 1;
580  
581 =head1 SEE ALSO
582  
583 HTML::DataTable::DBI, HTML::FromArrayref
584  
585 =head1 AUTHORS
586  
587 Nic Wolff <nic@angel.net>
588 Jason Barden <jason@angel.net>
589  
590 =cut
↑ Summary DataTable/DBI.pm »