WebPAC::Output::CouchDB now takes uri to CouchDB server,
[webpac2] / lib / WebPAC / Output / CouchDB.pm
index ee10d0b..0c1c69b 100644 (file)
@@ -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 );