From: Dobrica Pavlinusic Date: Thu, 28 May 2009 09:58:18 +0000 (+0000) Subject: WebPAC::Output::CouchDB now takes uri to CouchDB server, X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=8aa6538f8ab313a03256517e20a21c278407e5ed;p=webpac2 WebPAC::Output::CouchDB now takes uri to CouchDB server, document ids now include input name git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1197 07558da8-63fa-0310-ba24-9fe276d99e06 --- diff --git a/lib/WebPAC/Output/CouchDB.pm b/lib/WebPAC/Output/CouchDB.pm index ee10d0b..0c1c69b 100644 --- a/lib/WebPAC/Output/CouchDB.pm +++ b/lib/WebPAC/Output/CouchDB.pm @@ -5,14 +5,14 @@ use strict; use base qw/WebPAC::Common WebPAC::Output Class::Accessor/; __PACKAGE__->mk_accessors(qw( + input + url database - - host - port )); use Data::Dump qw/dump/; use Net::CouchDb; +use URI; =head1 NAME @@ -32,15 +32,17 @@ sub init { $log->debug('init'); + my $u = URI->new( $self->url ); + my $cdb = Net::CouchDb->new( - host => $self->host || "localhost", - port => $self->port || 5984, + host => $u->host || "localhost", + port => $u->port || 5984, ); - $log->info("CouchDB server info ", dump( $cdb->server_info ) ); - my $database = $self->database || 'webpac2'; + $log->info("CouchDB database $database info ", dump( $cdb->server_info ) ); + $cdb->debug( $self->debug ); eval { $cdb->delete_db( $self->database ) }; $cdb->create_db( $self->database ); @@ -65,6 +67,8 @@ sub add { my $log = $self->_get_logger; + $id = $self->input . '-' . $id if $self->input; + my $doc = Net::CouchDb::Document->new( $id, $ds ); $self->{_cdb}->put( $doc ); diff --git a/t/5-output-couchdb.t b/t/5-output-couchdb.t index 1f1a59d..fe94498 100755 --- a/t/5-output-couchdb.t +++ b/t/5-output-couchdb.t @@ -15,6 +15,7 @@ BEGIN { my $path = "$abs_path/kino/"; ok(my $out = new WebPAC::Output::CouchDB({ + url => 'http://193.198.212.57:5984', database => 'webpac2', %LOG }), "new");