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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1354 - (hide annotations)
Sat Nov 13 01:03:33 2010 UTC (13 years, 6 months ago) by dpavlin
Original Path: branches/Sack/lib/WebPAC/Output/Riak.pm
File size: 1410 byte(s)
store rows in Riak

1 dpavlin 1354 package WebPAC::Output::Riak;
2    
3     use warnings;
4     use strict;
5    
6     use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7     __PACKAGE__->mk_accessors(qw(
8     input
9     url
10     database
11     ));
12    
13     use Data::Dump qw/dump/;
14     use URI;
15     use Net::Riak;
16    
17     =head1 NAME
18    
19     WebPAC::Output::Riak - feed data into Riak
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     $self->{_riak} = Net::Riak->new( host => $self->url );
36     $self->{_bucket} = $self->{_riak}->bucket( $self->database );
37    
38     $log->info("Riak ",$self->url, " bucket ", $self->database);
39    
40     $self->{_count} = 0;
41    
42     return 1;
43     }
44    
45    
46     =head2 add
47    
48     Adds one entry to database.
49    
50     $out->add( 42, $ds );
51    
52     =cut
53    
54     sub add_row {
55     my $self = shift;
56    
57     my ( $id, $ds ) = @_;
58    
59     my $log = $self->_get_logger;
60    
61     my $obj = $self->{_bucket}->new_object( $id, $ds );
62     $obj->store;
63    
64     $log->debug( $id, sub { dump($ds) } );
65    
66     $self->{_count}++;
67    
68     return 1;
69     }
70    
71     =head2 finish
72    
73     $out->finish;
74    
75     =cut
76    
77     sub finish {
78     my $self = shift;
79    
80     my $log = $self->_get_logger();
81    
82     $log->info('finish ', $self->{_count}, ' documents');
83    
84     1;
85     }
86    
87     =head1 AUTHOR
88    
89     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
90    
91     =head1 COPYRIGHT & LICENSE
92    
93     Copyright 2010 Dobrica Pavlinusic, All Rights Reserved.
94    
95     This program is free software; you can redistribute it and/or modify it
96     under the same terms as Perl itself.
97    
98     =cut
99    
100     1; # End of WebPAC::Output::Riak

  ViewVC Help
Powered by ViewVC 1.1.26