| 1 | package DBIx::NoSQL::Storage; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 8 | has store => qw/ is ro required 1 weak_ref 1 /; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 8 | has statement_caching => qw/ is rw isa Bool default 0 /; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 8 | has foreign_storage => qw/ is ro lazy_build 1 weak_ref 1 /; | |||||||||||||||||||||||||||||||
| 11 | sub _build_foreign_storage { | ||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_build_foreign_storage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 9 | return $self->store->schema->storage; | |||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | sub do { | ||||||||||||||||||||||||||||||||
| 17 | 49 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
do: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 18 | 49 | my $statement = shift; | |||||||||||||||||||||||||||||||
| 19 | 49 | my @bind = @_; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 49 | my $attributes; | |||||||||||||||||||||||||||||||
| 22 | 49 | ▶ | $attributes = shift @bind if @bind && ref $bind[0] eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@bind and ref $bind[0] eq "HASH"
MC/DC0%0/2
@bind and ref $bind[0] eq "HASH"
@bind
ref $bind[0] eq "HASH"
Truth table33%1/3
A and B
A= @bindB= ref $bind[0] eq "HASH"
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 49 | $self->_query_start( $statement => @bind ); | |||||||||||||||||||||||||||||||
| 25 | $self->foreign_storage->dbh_do( sub { | ||||||||||||||||||||||||||||||||
| 26 | 49 | ▶ | $_[1]->do( $statement, $attributes, @bind ); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 49 | } ); | |||||||||||||||||||||||||||||||
| 28 | 48 | $self->_query_end( $statement => @bind ); | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | sub retrying_do { | ||||||||||||||||||||||||||||||||
| 32 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
retrying_do: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 33 | 7 | my $code = shift; | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 7 | return $self->foreign_storage->dbh_do( $code, @_ ); | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | sub select { | ||||||||||||||||||||||||||||||||
| 39 | 43 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=4 SCAR=15.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 40 | 43 | my $statement = shift; | |||||||||||||||||||||||||||||||
| 41 | 43 | my $attributes = shift; | |||||||||||||||||||||||||||||||
| 42 | 43 | my $bind = shift; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 43 | $self->_query_start( $statement => @$bind ); | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 43 | my $foreign = $self->foreign_storage; | |||||||||||||||||||||||||||||||
| 47 | my $sth = $foreign->dbh_do( sub { | ||||||||||||||||||||||||||||||||
| 48 | 43 | ▶ | my $dbh = $_[1]; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=19.2
| |||||||||||||||||||||||||||||||||
| 49 | 43 | ▶ | my $sth = $self->statement_caching ? | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$attributes || {}
$attributes || {}
MC/DC0%0/1
$attributes || {}
$attributes
MC/DC0%0/1
$attributes || {}
$attributes
Truth table0%0/2
A
A= $attributes
Truth table50%1/2
A
A= $attributes
| |||||||||||||||||||||||||||||||||
| 50 | $dbh->prepare_cached( $statement, $attributes || {}, 3 ) : | ||||||||||||||||||||||||||||||||
| 51 | $dbh->prepare( $statement, $attributes || {} ) | ||||||||||||||||||||||||||||||||
| 52 | ; | ||||||||||||||||||||||||||||||||
| 53 | 43 | ▶ | croak $dbh->errstr unless $sth; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 43 | return $sth; | |||||||||||||||||||||||||||||||
| 55 | 43 | } ); | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 43 | my $rv = $sth->execute( @$bind ); | |||||||||||||||||||||||||||||||
| 58 | 43 | ▶ | croak $sth->errstr || $sth->err || "Unknown error: \$sth->execute return false without setting an error flag" unless $rv; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$sth->errstr || $sth->err || 'Unknown error: $sth->execute return false without setting an error flag'
$sth->errstr or $sth->err
MC/DC0%0/2
$sth->errstr || $sth->err || 'Unknown error: $sth->execute return false without setting an error flag'
$sth->errstr
$sth->err
Truth table0%0/3
A or B
A= $sth->errstrB= $sth->err
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 43 | $self->_query_end( $statement, @$bind ); | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 43 | return $sth; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | sub cursor { | ||||||||||||||||||||||||||||||||
| 66 | 42 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
cursor: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 67 | 42 | my $statement = shift; | |||||||||||||||||||||||||||||||
| 68 | 42 | my $attributes; | |||||||||||||||||||||||||||||||
| 69 | 42 | ▶ | $attributes = shift if ref $_[0] eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 42 | my $bind = shift; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 42 | return DBIx::NoSQL::Storage::Cursor->new( storage => $self, statement => $statement, attributes => $attributes, bind => $bind ); | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | sub _query_start { | ||||||||||||||||||||||||||||||||
| 76 | 92 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_query_start: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||
| 77 | 92 | ▶ | if ( $self->foreign_storage->debug ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | 0 | $self->foreign_storage->debugobj->query_start( @_ ); | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | sub _query_end { | ||||||||||||||||||||||||||||||||
| 83 | 91 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_query_end: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||
| 84 | 91 | ▶ | if ( $self->foreign_storage->debug ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 0 | $self->foreign_storage->debugobj->query_end( @_ ); | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | sub table_exists { | ||||||||||||||||||||||||||||||||
| 90 | 28 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
table_exists: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 91 | 28 | my $table_name = shift; | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 28 | my $statement = <<_END_; | |||||||||||||||||||||||||||||||
| 94 | SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = ? | ||||||||||||||||||||||||||||||||
| 95 | _END_ | ||||||||||||||||||||||||||||||||
| 96 | 28 | my @bind = ( $table_name ); | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 28 | my $cursor = $self->cursor( $statement, \@bind ); | |||||||||||||||||||||||||||||||
| 99 | 28 | my $result = $cursor->next; | |||||||||||||||||||||||||||||||
| 100 | 28 | ▶ | return $result->[0] ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | package DBIx::NoSQL::Storage::Cursor; | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 8 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 106 | 8 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 8 | has storage => qw/ is ro required 1 /; | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 8 | has statement => qw/ is ro required 1 /; | |||||||||||||||||||||||||||||||
| 111 | 8 | has attributes => qw/ is ro /; | |||||||||||||||||||||||||||||||
| 112 | 8 | has bind => qw/ is ro required 1 isa ArrayRef /; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 8 | has sth => qw/ is rw /; | |||||||||||||||||||||||||||||||
| 115 | 8 | has finished => qw/ is rw isa Bool default 0 /; | |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | sub _select { | ||||||||||||||||||||||||||||||||
| 118 | 43 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_select: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 119 | 43 | return $self->storage->select( $self->statement, $self->attributes, $self->bind ); | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | sub next { | ||||||||||||||||||||||||||||||||
| 123 | 37 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 37 | ▶ | return if $self->finished; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 37 | ▶ | unless ( $self->sth ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 36 | $self->sth( $self->_select ); | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 37 | ▶ | my $row = $self->sth->fetchrow_arrayref or do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 1 | $self->sth( undef ); | |||||||||||||||||||||||||||||||
| 133 | 1 | $self->finished( 0 ); | |||||||||||||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 37 | ▶ | return $row || []; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$row || []
MC/DC100%1/1
$row || []
$row
Truth table100%2/2
A
A= $row
| |||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | sub all { | ||||||||||||||||||||||||||||||||
| 140 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 7 | ▶ | $self->sth->finish if $self->sth && $self->sth->{Active}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->sth and $self->sth->{"Active"}
MC/DC0%0/2
$self->sth and $self->sth->{"Active"}
$self->sth
$self->sth->{"Active"}
Truth table33%1/3
A and B
A= $self->sthB= $self->sth->{"Active"}
| |||||||||||||||||||||||||||||||||
| 143 | 7 | $self->sth( undef ); | |||||||||||||||||||||||||||||||
| 144 | 7 | my $sth; | |||||||||||||||||||||||||||||||
| 145 | $self->storage->retrying_do( sub { | ||||||||||||||||||||||||||||||||
| 146 | 7 | ▶ | $sth = $self->_select; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 147 | 7 | } ); | |||||||||||||||||||||||||||||||
| 148 | 7 | my $all = $sth->fetchall_arrayref; | |||||||||||||||||||||||||||||||
| 149 | 7 | ▶ | return [] unless $all; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | 7 | return $all; | |||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | sub reset { | ||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | try { $self->sth->finish } if $self->sth && $self->sth->{Active}; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
$self->sth and $self->sth->{"Active"}
MC/DC0%0/2
$self->sth and $self->sth->{"Active"}
$self->sth
$self->sth->{"Active"}
Truth table0%0/3
A and B
A= $self->sthB= $self->sth->{"Active"}
| |||||||||||||||||||||||||||||||||
| 157 | 0 | $self->_soft_reset; | |||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | sub _soft_reset { | ||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_soft_reset: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | 0 | $self->sth( undef ); | |||||||||||||||||||||||||||||||
| 164 | 0 | $self->finished( 0 ); | |||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | 8 | 1; | |||||||||||||||||||||||||||||||