lib/CGI/OptimalQuery/JSON.pm

filter: Statementstmt 100% 12 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 16 / 16 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/CGI/OptimalQuery/InteractiveQuery2Tools.pm ↑ Summary lib/CGI/OptimalQuery/PrinterFriendly.pm »
1 package CGI::OptimalQuery::JSON;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶no warnings qw( uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'CGI::OptimalQuery::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
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;
« lib/CGI/OptimalQuery/InteractiveQuery2Tools.pm ↑ Summary lib/CGI/OptimalQuery/PrinterFriendly.pm »