| 1 | package Daemonise::Plugin::CouchDB; | ||
| 2 | |||
| 3 | 1 | ▶ | use Mouse::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | # ABSTRACT: Daemonise CouchDB plugin | ||
| 6 | |||
| 7 | 0 | ▶ | use Store::CouchDB; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use Carp; | ||
| 9 | |||
| 10 | |||
| 11 | has 'couch_host' => ( | ||
| 12 | is => 'rw', | ||
| 13 | isa => 'Str', | ||
| 14 | lazy => 1, | ||
| 15 | default => sub { 'localhost' }, | ||
| 16 | ); | ||
| 17 | |||
| 18 | |||
| 19 | has 'couch_port' => ( | ||
| 20 | is => 'rw', | ||
| 21 | isa => 'Int', | ||
| 22 | lazy => 1, | ||
| 23 | default => sub { 5984 }, | ||
| 24 | ); | ||
| 25 | |||
| 26 | |||
| 27 | has 'couch_db' => ( | ||
| 28 | is => 'rw', | ||
| 29 | isa => 'Str', | ||
| 30 | lazy => 1, | ||
| 31 | default => sub { 'test' }, | ||
| 32 | ); | ||
| 33 | |||
| 34 | |||
| 35 | has 'couch_user' => ( | ||
| 36 | is => 'rw', | ||
| 37 | isa => 'Str', | ||
| 38 | ); | ||
| 39 | |||
| 40 | |||
| 41 | has 'couch_pass' => ( | ||
| 42 | is => 'rw', | ||
| 43 | isa => 'Str', | ||
| 44 | ); | ||
| 45 | |||
| 46 | |||
| 47 | has 'couch_debug' => ( | ||
| 48 | is => 'rw', | ||
| 49 | isa => 'Bool', | ||
| 50 | lazy => 1, | ||
| 51 | default => sub { 0 }, | ||
| 52 | ); | ||
| 53 | |||
| 54 | has 'couchdb' => ( | ||
| 55 | is => 'rw', | ||
| 56 | isa => 'Store::CouchDB', | ||
| 57 | required => 1, | ||
| 58 | ); | ||
| 59 | |||
| 60 | |||
| 61 | after 'configure' => sub { | ||
| 62 | my ($self, $reconfig) = @_; | ||
| 63 | |||
| 64 | $self->log("configuring CouchDB plugin") if $self->debug; | ||
| 65 | |||
| 66 | if (ref($self->config->{couchdb}) eq 'HASH') { | ||
| 67 | foreach | ||
| 68 | my $conf_key ('host', 'port', 'user', 'pass', 'db', 'view', 'debug') | ||
| 69 | { | ||
| 70 | my $attr = "couch_" . $conf_key; | ||
| 71 | $self->$attr($self->config->{couchdb}->{$conf_key}) | ||
| 72 | if defined $self->config->{couchdb}->{$conf_key}; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | my $sc = Store::CouchDB->new( | ||
| 77 | host => $self->couch_host, | ||
| 78 | port => $self->couch_port, | ||
| 79 | debug => $self->couch_debug, | ||
| 80 | ); | ||
| 81 | $sc->db($self->couch_db) if ($self->couch_db); | ||
| 82 | if ($self->couch_user && $self->couch_pass) { | ||
| 83 | $sc->user($self->couch_user); | ||
| 84 | $sc->pass($self->couch_pass); | ||
| 85 | } | ||
| 86 | $self->couchdb($sc); | ||
| 87 | |||
| 88 | return; | ||
| 89 | }; | ||
| 90 | |||
| 91 | 1; | ||
| 92 | |||
| 93 | __END__ | ||