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

Contents of /trunk/lib/WebPAC/Output/CouchDB.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1196 - (show annotations)
Wed May 27 22:17:00 2009 UTC (14 years, 11 months ago) by dpavlin
File size: 1504 byte(s)
 r1880@llin:  dpavlin | 2009-05-27 23:45:18 +0200
 added output to CouchDB

1 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 database
9
10 host
11 port
12 ));
13
14 use Data::Dump qw/dump/;
15 use Net::CouchDb;
16
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 my $cdb = Net::CouchDb->new(
36 host => $self->host || "localhost",
37 port => $self->port || 5984,
38 );
39
40 $log->info("CouchDB server info ", dump( $cdb->server_info ) );
41
42 my $database = $self->database || 'webpac2';
43
44 $cdb->debug( $self->debug );
45 eval { $cdb->delete_db( $self->database ) };
46 $cdb->create_db( $self->database );
47 $self->{_cdb} = $cdb->db( $self->database );
48
49 return 1;
50 }
51
52
53 =head2 add
54
55 Adds one entry to database.
56
57 $out->add( 42, $ds );
58
59 =cut
60
61 sub add {
62 my $self = shift;
63
64 my ( $id, $ds ) = @_;
65
66 my $log = $self->_get_logger;
67
68 my $doc = Net::CouchDb::Document->new( $id, $ds );
69 $self->{_cdb}->put( $doc );
70
71 return 1;
72 }
73
74 =head2 finish
75
76 $out->finish;
77
78 =cut
79
80 sub finish {
81 my $self = shift;
82
83 my $log = $self->_get_logger();
84
85 $log->info('finish');
86 1;
87
88 }
89
90 =head1 AUTHOR
91
92 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
93
94 =head1 COPYRIGHT & LICENSE
95
96 Copyright 2009 Dobrica Pavlinusic, All Rights Reserved.
97
98 This program is free software; you can redistribute it and/or modify it
99 under the same terms as Perl itself.
100
101 =cut
102
103 1; # End of WebPAC::Output::CouchDB

  ViewVC Help
Powered by ViewVC 1.1.26