/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 881 by dpavlin, Thu Aug 23 20:28:09 2007 UTC revision 917 by dpavlin, Tue Oct 30 21:57:36 2007 UTC
# Line 3  package WebPAC::Output::JSON; Line 3  package WebPAC::Output::JSON;
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    
# Line 29  Create JSON output for export into other Line 30  Create JSON output for export into other
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    
# Line 45  path to JSON file Line 46  path to JSON file
46    
47  =head2 init  =head2 init
48    
49    $output->init;    $out->init;
50    
51  =cut  =cut
52    
# Line 55  sub init { Line 56  sub init {
56    
57          $log->debug('init');          $log->debug('init');
58    
59            $self->{_data} = [];
60    
61          return 1;          return 1;
62  }  }
63    
# Line 63  sub init { Line 66  sub init {
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    
# Line 78  sub add { Line 81  sub add {
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    
# Line 92  sub finish { Line 97  sub finish {
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    

Legend:
Removed from v.881  
changed lines
  Added in v.917

  ViewVC Help
Powered by ViewVC 1.1.26