/[webpac2]/trunk/lib/WebPAC/Output/CouchDB.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/CouchDB.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1198 - (hide annotations)
Thu May 28 10:15:20 2009 UTC (14 years, 11 months ago) by dpavlin
File size: 1606 byte(s)
output modules can now define add_row as opposed to add to get input row before normalization
1 dpavlin 1196 package WebPAC::Output::CouchDB;
2    
3     use warnings;
4     use strict;
5    
6     use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7     __PACKAGE__->mk_accessors(qw(
8 dpavlin 1197 input
9     url
10 dpavlin 1196 database
11     ));
12    
13     use Data::Dump qw/dump/;
14     use Net::CouchDb;
15 dpavlin 1197 use URI;
16 dpavlin 1196
17     =head1 NAME
18    
19     WebPAC::Output::CouchDB - feed data into CouchDB
20    
21     =head1 FUNCTIONS
22    
23     =head2 init
24    
25     $out->init;
26    
27     =cut
28    
29     sub init {
30     my $self = shift;
31     my $log = $self->_get_logger;
32    
33     $log->debug('init');
34    
35 dpavlin 1197 my $u = URI->new( $self->url );
36    
37 dpavlin 1196 my $cdb = Net::CouchDb->new(
38 dpavlin 1197 host => $u->host || "localhost",
39     port => $u->port || 5984,
40 dpavlin 1196 );
41    
42     my $database = $self->database || 'webpac2';
43    
44 dpavlin 1197 $log->info("CouchDB database $database info ", dump( $cdb->server_info ) );
45    
46 dpavlin 1196 $cdb->debug( $self->debug );
47     eval { $cdb->delete_db( $self->database ) };
48     $cdb->create_db( $self->database );
49     $self->{_cdb} = $cdb->db( $self->database );
50    
51     return 1;
52     }
53    
54    
55     =head2 add
56    
57     Adds one entry to database.
58    
59     $out->add( 42, $ds );
60    
61     =cut
62    
63 dpavlin 1198 sub add_row {
64 dpavlin 1196 my $self = shift;
65    
66     my ( $id, $ds ) = @_;
67    
68     my $log = $self->_get_logger;
69    
70 dpavlin 1197 $id = $self->input . '-' . $id if $self->input;
71    
72 dpavlin 1196 my $doc = Net::CouchDb::Document->new( $id, $ds );
73     $self->{_cdb}->put( $doc );
74    
75     return 1;
76     }
77    
78     =head2 finish
79    
80     $out->finish;
81    
82     =cut
83    
84     sub finish {
85     my $self = shift;
86    
87     my $log = $self->_get_logger();
88    
89     $log->info('finish');
90     1;
91    
92     }
93    
94     =head1 AUTHOR
95    
96     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
97    
98     =head1 COPYRIGHT & LICENSE
99    
100     Copyright 2009 Dobrica Pavlinusic, All Rights Reserved.
101    
102     This program is free software; you can redistribute it and/or modify it
103     under the same terms as Perl itself.
104    
105     =cut
106    
107     1; # End of WebPAC::Output::CouchDB

  ViewVC Help
Powered by ViewVC 1.1.26