| 1 | package EntityModel::StorageClass::KVStore::Layer::PostgreSQL; | ||||||||||
| 2 | { | ||||||||||
| 3 | 1 | $EntityModel::StorageClass::KVStore::Layer::PostgreSQL::VERSION = '0.102'; | |||||||||
| 4 | } | ||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use parent qw(EntityModel::StorageClass::KVStore::Layer EntityModel::StorageClass::KVStore::Mixin::Deferred); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 10 | 0 | my $class = shift; | |||||||||
| 11 | 0 | my %args = @_; | |||||||||
| 12 | 0 | my $self = $class->SUPER::new; | |||||||||
| 13 | 0 | $self->{connected} = 0; | |||||||||
| 14 | 0 | $self->{queue} = [ ]; | |||||||||
| 15 | 0 | my $loop = delete $args{loop}; | |||||||||
| 16 | 0 | require Net::Async::PostgreSQL::Client; | |||||||||
| 17 | 0 | $self->{dbh} = my $pg = Net::Async::PostgreSQL::Client->new( | |||||||||
| 18 | %args, | ||||||||||
| 19 | ); | ||||||||||
| 20 | 0 | $loop->add($pg); | |||||||||
| 21 | $pg->add_handler_for_event( | ||||||||||
| 22 | 0 | ▶ | error => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 23 | 0 | my $x = shift; | |||||||||
| 24 | 0 | my %args = @_; | |||||||||
| 25 | 0 | warn "* $_ => " . $args{error}->{$_} for sort keys %{$args{error}}; | |||||||||
| 26 | 0 | die "failed" | |||||||||
| 27 | }, | ||||||||||
| 28 | 0 | ▶ | ready_for_query => sub { $self->connection_complete }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | 0 | ); | |||||||||
| 30 | 0 | $pg->connect; | |||||||||
| 31 | 0 | $self | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub dbh { shift->{dbh} } | ||||||||
|
Subroutine
dbh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub retrieve { | ||||||||
|
Subroutine
retrieve: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 37 | 0 | my $self = shift; | |||||||||
| 38 | 0 | ▶ | return $self->queue_task(retrieve => @_) unless $self->is_connected; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | my %args = @_; | |||||||||
| 40 | |||||||||||
| 41 | 0 | my $on_success = $args{on_success}; | |||||||||
| 42 | 0 | my $k = $args{query}; | |||||||||
| 43 | |||||||||||
| 44 | $self->dbh->add_handler_for_event( | ||||||||||
| 45 | 0 | ▶ | data_row => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 46 | 0 | ▶ | return 0 unless $on_success; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | my ($self, %args) = @_; | |||||||||
| 48 | 0 | $on_success->($args{row}[0]{data}); | |||||||||
| 49 | 0 | 0 | |||||||||
| 50 | } | ||||||||||
| 51 | 0 | ); | |||||||||
| 52 | # FIXME injected with a poison... | ||||||||||
| 53 | 0 | $self->dbh->simple_query(q{insert into emtest.kvstore(content) values ('} . $k . q{') returning id}); | |||||||||
| 54 | 0 | $self | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | =head2 store | ||||||||||
| 58 | |||||||||||
| 59 | Store a value in the cache. | ||||||||||
| 60 | |||||||||||
| 61 | Takes the following parameters: | ||||||||||
| 62 | |||||||||||
| 63 | =over 4 | ||||||||||
| 64 | |||||||||||
| 65 | =item * $query - query to store under | ||||||||||
| 66 | |||||||||||
| 67 | =item * $value - value to store in key (can be undef) | ||||||||||
| 68 | |||||||||||
| 69 | =back | ||||||||||
| 70 | |||||||||||
| 71 | Returns $self. | ||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub store { | ||||||||
|
Subroutine
store: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 76 | 0 | my ($self, $k, $v) = @_; | |||||||||
| 77 | 0 | ▶ | return $self->queue_task(store => @_) unless $self->is_connected; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | |||||||||||
| 79 | $self->memcached->set( | ||||||||||
| 80 | $k => $v, | ||||||||||
| 81 | 0 | ▶ | on_complete => sub { }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||
| 82 | 0 | ▶ | on_error => sub { die "Failed because of @_\n" } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 83 | 0 | ); | |||||||||
| 84 | 0 | $self | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 1 | 1; | |||||||||
| 88 | |||||||||||