/[webpac2]/trunk/lib/WebPAC/Output/JSON.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/WebPAC/Output/JSON.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 917 - (hide annotations)
Tue Oct 30 21:57:36 2007 UTC (16 years, 7 months ago) by dpavlin
File size: 1603 byte(s)
 r1380@llin:  dpavlin | 2007-10-30 22:57:36 +0100
 pod tweaks

1 dpavlin 881 package WebPAC::Output::JSON;
2    
3     use warnings;
4     use strict;
5    
6 dpavlin 913 use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7 dpavlin 881 __PACKAGE__->mk_accessors(qw(path));
8    
9     use Data::Dump qw/dump/;
10 dpavlin 883 use JSON;
11     use File::Slurp;
12 dpavlin 881
13     =head1 NAME
14    
15     WebPAC::Output::JSON - Create JSON output
16    
17     =head1 VERSION
18    
19     Version 0.00
20    
21     =cut
22    
23     our $VERSION = '0.00';
24    
25     =head1 SYNOPSIS
26    
27     Create JSON output for export into other sistems
28    
29     =head1 FUNCTIONS
30    
31     =head2 new
32    
33 dpavlin 917 my $out = new WebPAC::Output::JSON({
34 dpavlin 881 path => '/path/to/file.js',
35     });
36    
37     Options are:
38    
39     =over 4
40    
41     =item path
42    
43     path to JSON file
44    
45     =back
46    
47     =head2 init
48    
49 dpavlin 917 $out->init;
50 dpavlin 881
51     =cut
52    
53     sub init {
54     my $self = shift;
55     my $log = $self->_get_logger;
56    
57     $log->debug('init');
58    
59 dpavlin 883 $self->{_data} = [];
60    
61 dpavlin 881 return 1;
62     }
63    
64    
65     =head2 add
66    
67     Adds one entry to database.
68    
69 dpavlin 917 $out->add( 42, $ds );
70 dpavlin 881
71     =cut
72    
73     sub add {
74     my $self = shift;
75    
76     my ( $id, $ds ) = @_;
77    
78     my $log = $self->_get_logger;
79     $log->logdie("need id") unless defined $id;
80     $log->logdie("need ds") unless $ds;
81    
82     $log->debug("id: $id ds = ",dump($ds));
83    
84 dpavlin 913 push @{ $self->{_data} }, $self->ds_to_hash( $ds, 'display' );
85 dpavlin 883
86 dpavlin 881 return 1;
87     }
88    
89     =head2 finish
90    
91 dpavlin 917 $out->finish;
92 dpavlin 881
93     =cut
94    
95     sub finish {
96     my $self = shift;
97    
98     my $log = $self->_get_logger();
99    
100 dpavlin 883 $log->info("writing JSON output to ", $self->path);
101     write_file( $self->path, objToJson( { items => $self->{_data} } ) );
102 dpavlin 881
103     }
104    
105     =head1 AUTHOR
106    
107     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
108    
109     =head1 COPYRIGHT & LICENSE
110    
111     Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
112    
113     This program is free software; you can redistribute it and/or modify it
114     under the same terms as Perl itself.
115    
116     =cut
117    
118     1; # End of WebPAC::Output::JSON

  ViewVC Help
Powered by ViewVC 1.1.26