3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use base qw/WebPAC::Common Class::Accessor/; |
use base qw/WebPAC::Common WebPAC::Output Class::Accessor/; |
7 |
__PACKAGE__->mk_accessors(qw(path)); |
__PACKAGE__->mk_accessors(qw(path)); |
8 |
|
|
|
use Encode qw/from_to/; |
|
9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
|
use JSON; |
11 |
|
use File::Slurp; |
12 |
|
|
13 |
=head1 NAME |
=head1 NAME |
14 |
|
|
30 |
|
|
31 |
=head2 new |
=head2 new |
32 |
|
|
33 |
my $output = new WebPAC::Output::JSON({ |
my $out = new WebPAC::Output::JSON({ |
34 |
path => '/path/to/file.js', |
path => '/path/to/file.js', |
35 |
}); |
}); |
36 |
|
|
46 |
|
|
47 |
=head2 init |
=head2 init |
48 |
|
|
49 |
$output->init; |
$out->init; |
50 |
|
|
51 |
=cut |
=cut |
52 |
|
|
56 |
|
|
57 |
$log->debug('init'); |
$log->debug('init'); |
58 |
|
|
59 |
|
$self->{_data} = []; |
60 |
|
|
61 |
return 1; |
return 1; |
62 |
} |
} |
63 |
|
|
66 |
|
|
67 |
Adds one entry to database. |
Adds one entry to database. |
68 |
|
|
69 |
$est->add( 42, $ds ); |
$out->add( 42, $ds ); |
70 |
|
|
71 |
=cut |
=cut |
72 |
|
|
81 |
|
|
82 |
$log->debug("id: $id ds = ",dump($ds)); |
$log->debug("id: $id ds = ",dump($ds)); |
83 |
|
|
84 |
|
push @{ $self->{_data} }, $self->ds_to_hash( $ds, 'display' ); |
85 |
|
|
86 |
return 1; |
return 1; |
87 |
} |
} |
88 |
|
|
89 |
=head2 finish |
=head2 finish |
90 |
|
|
91 |
$output->finish; |
$out->finish; |
92 |
|
|
93 |
=cut |
=cut |
94 |
|
|
97 |
|
|
98 |
my $log = $self->_get_logger(); |
my $log = $self->_get_logger(); |
99 |
|
|
100 |
$log->info("finish"); |
$log->info("writing JSON output to ", $self->path); |
101 |
|
write_file( $self->path, objToJson( { items => $self->{_data} } ) ); |
102 |
|
|
103 |
} |
} |
104 |
|
|