/[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 882 by dpavlin, Thu Aug 23 20:28:09 2007 UTC revision 883 by dpavlin, Thu Aug 23 20:56:59 2007 UTC
# Line 6  use strict; Line 6  use strict;
6  use base qw/WebPAC::Common Class::Accessor/;  use base qw/WebPAC::Common Class::Accessor/;
7  __PACKAGE__->mk_accessors(qw(path));  __PACKAGE__->mk_accessors(qw(path));
8    
9  use Encode qw/from_to/;  #use Encode qw/from_to/;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
11    use JSON;
12    use File::Slurp;
13    
14  =head1 NAME  =head1 NAME
15    
# Line 55  sub init { Line 57  sub init {
57    
58          $log->debug('init');          $log->debug('init');
59    
60            $self->{_data} = [];
61    
62          return 1;          return 1;
63  }  }
64    
# Line 78  sub add { Line 82  sub add {
82    
83          $log->debug("id: $id ds = ",dump($ds));          $log->debug("id: $id ds = ",dump($ds));
84    
85            my $item;
86    
87            foreach my $t ( keys %$ds ) {
88                    my $name = lc($t);
89                    $name =~ s/\W+/_/g;
90    
91                    # FIXME get rid of non hash values in data_structure for consistency?
92                    next unless ref($ds->{$t}) eq 'HASH';
93    
94                    if ( defined( $ds->{$t}->{display} ) ) {
95                            $item->{$name} = $ds->{$t}->{display};
96                    }
97            }
98    
99            push @{ $self->{_data} }, $item;
100    
101          return 1;          return 1;
102  }  }
103    
# Line 92  sub finish { Line 112  sub finish {
112    
113          my $log = $self->_get_logger();          my $log = $self->_get_logger();
114    
115          $log->info("finish");          $log->info("writing JSON output to ", $self->path);
116            write_file( $self->path, objToJson( { items => $self->{_data} } ) );
117    
118  }  }
119    

Legend:
Removed from v.882  
changed lines
  Added in v.883

  ViewVC Help
Powered by ViewVC 1.1.26