From: Dobrica Pavlinusic Date: Sat, 16 Oct 2010 17:44:57 +0000 (+0000) Subject: generate json file on disk X-Git-Url: http://git.rot13.org/?p=webpac2;a=commitdiff_plain;h=57b068b1200fb04faade283a0831198c612077b1;ds=sidebyside generate json file on disk git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1345 07558da8-63fa-0310-ba24-9fe276d99e06 --- diff --git a/lib/WebPAC/Output/JSON.pm b/lib/WebPAC/Output/JSON.pm index 049d679..e912815 100644 --- a/lib/WebPAC/Output/JSON.pm +++ b/lib/WebPAC/Output/JSON.pm @@ -9,6 +9,7 @@ __PACKAGE__->mk_accessors(qw(path)); use Data::Dump qw/dump/; use JSON; use File::Slurp; +use autodie; =head1 NAME @@ -97,8 +98,19 @@ sub finish { my $log = $self->_get_logger(); - $log->info("writing JSON output to ", $self->path); - write_file( $self->path, objToJson( { items => $self->{_data} } ) ); + if ( @{ $self->{_data} } ) { + + use bytes; + + open(my $fh, '>', $self->path); + print $fh to_json( { items => $self->{_data} } ); + close $fh; + + $log->info("wrote JSON to ", $self->path, ' ', -s $self->path, ' bytes'); + + } else { + $log->error("no data for JSON generated - remove this output?"); + } }