merge WebPAC::Output::Riak
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 13 Nov 2010 01:17:09 +0000 (01:17 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 13 Nov 2010 01:17:09 +0000 (01:17 +0000)
git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1355 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Output/Riak.pm [new file with mode: 0644]

diff --git a/lib/WebPAC/Output/Riak.pm b/lib/WebPAC/Output/Riak.pm
new file mode 100644 (file)
index 0000000..5ca5a8c
--- /dev/null
@@ -0,0 +1,100 @@
+package WebPAC::Output::Riak;
+
+use warnings;
+use strict;
+
+use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
+__PACKAGE__->mk_accessors(qw(
+       input
+       url
+       database
+));
+
+use Data::Dump qw/dump/;
+use URI;
+use Net::Riak;
+
+=head1 NAME
+
+WebPAC::Output::Riak - feed data into Riak
+
+=head1 FUNCTIONS
+
+=head2 init
+
+  $out->init;
+
+=cut
+
+sub init {
+       my $self = shift;
+       my $log = $self->_get_logger;
+
+       $log->debug('init');
+
+       $self->{_riak} = Net::Riak->new( host => $self->url );
+       $self->{_bucket} = $self->{_riak}->bucket( $self->database );
+
+       $log->info("Riak ",$self->url, " bucket ", $self->database);
+
+       $self->{_count} = 0;
+
+       return 1;
+}
+
+
+=head2 add
+
+Adds one entry to database.
+
+  $out->add( 42, $ds );
+
+=cut
+
+sub add_row {
+       my $self = shift;
+
+       my ( $id, $ds ) = @_;
+
+       my $log = $self->_get_logger;
+
+       my $obj = $self->{_bucket}->new_object( $id, $ds );
+       $obj->store;
+
+       $log->debug( $id, sub { dump($ds) } );
+
+       $self->{_count}++;
+
+       return 1;
+}
+
+=head2 finish
+
+ $out->finish;
+
+=cut
+
+sub finish {
+       my $self = shift;
+
+       my $log = $self->_get_logger();
+
+       $log->info('finish ', $self->{_count}, ' documents');
+
+       1;
+}
+
+=head1 AUTHOR
+
+Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2010 Dobrica Pavlinusic, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of WebPAC::Output::Riak