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

filter: Statementstmt 0.0% 0 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 41 SCAR 6.9
CC
1
Cov
0%
output
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package CGI::OptimalQuery::JSON;
2  
3 use strict;
4 use warnings;
5 no warnings qw( uninitialized );
6 use base 'CGI::OptimalQuery::Base';
7 use CGI();
8 use JSON::XS();
9  
10 sub output {
11 my $o = shift;
12  
13 my $title = $o->{schema}->{title};
14 $title =~ s/\W//g;
15 my @t = localtime;
16 $title .= '_'.($t[5] + 1900).($t[4] + 1).$t[3].$t[2].$t[1];
17  
18 $$o{output_handler}->(CGI::header(-type => 'application/json', -attachment => "$title.json"));
19  
20 my @selCols = @{ $o->get_usersel_cols() };
21 my @buf = ();
22
23 while(my $rec = $o->fetch()) {
24 push @buf, JSON::XS->new->utf8->encode($rec);
25 }
26
27 $$o{output_handler}->('[' . join(',', @buf) . ']');
28
29 $o->finish();
30 return undef;
31 }
32  
33 1;