blib/lib/CGI/OptimalQuery/CSV.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 47 SCAR 6.9
CC
1
Cov
0%
output
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package CGI::OptimalQuery::CSV;
2  
3 use strict;
4 use warnings;
5 no warnings qw( uninitialized );
6 use base 'CGI::OptimalQuery::Base';
7 use CGI();
8  
9 sub output {
10 my $o = shift;
11  
12 my $title = $o->{schema}->{title};
13 $title =~ s/\W//g;
14 my @t = localtime;
15 $title .= '_'.($t[5] + 1900).($t[4] + 1).$t[3].$t[2].$t[1];
16  
17 $$o{output_handler}->(CGI::header(-type => 'text/csv', -attachment => "$title.csv"));
18  
19 my $selCols = $o->get_usersel_cols();
20  
21 # print header
22 my @buffer;
23 foreach my $i (0 .. $#$selCols) {
24 my $col = $o->get_nice_name($o->get_usersel_cols->[$i]);
25 $col =~ s/\"/""/g;
26 push @buffer, '"'.$col.'"';
27 }
28 $$o{output_handler}->(join(',', @buffer)."\n");
29  
30 # print data
31 while (my $rec = $o->fetch()) {
32 @buffer = ();
33 foreach my $col (@$selCols) {
34 my $val = $o->get_val($col);
35 $val =~ s/\"/""/g;
36 $val =~ s/[\r\n]+/; /g;
37 $val =~ s/[^!-~\s]//g;
38 push @buffer, '"'.$val.'"';
39 }
40 $$o{output_handler}->(join(',', @buffer)."\n");
41 }
42 $o->finish();
43 return undef;
44 }
45  
46  
47 1;