« 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 | 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 | $$o{output_handler}->($$o{httpHeader}->(-type => 'application/json', -attachment => "$title.json").'['); | ||
| 17 | my @selCols = @{ $o->get_usersel_cols() }; | ||
| 18 | my $encoder = JSON::XS->new->utf8(); | ||
| 19 | while(my $rec = $o->fetch()) { | ||
| 20 | $$o{output_handler}->($encoder->encode($rec)); | ||
| 21 | } | ||
| 22 | $$o{output_handler}->(']'); | ||
| 23 | $o->finish(); | ||
| 24 | return undef; | ||
| 25 | } | ||
| 26 | |||
| 27 | 1; | ||