| 1 | package DBIx::QueryByName::QueryPool; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use DBIx::QueryByName::Logger qw(get_logger debug); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 8 | 0 | return bless( {}, $_[0] ); | |||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub add_query { | ||||||||||||||||||||||||||
|
Subroutine
add_query: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 13 | 0 | my $log = get_logger(); | |||||||||||||||||||||||||||
| 14 | 0 | ▶ | my $name = $args{name} || $log->logcroak("BUG: undefined query name"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'name'} || $log->logcroak('BUG: undefined query name')
MC/DC0%0/2
$args{'name'} || $log->logcroak('BUG: undefined query name')
$args{'name'}
$log->logcroak('BUG: undefined query name')
Truth table0%0/3
A || B
A= $args{'name'}B= $log->logcroak('BUG: undefined query name')
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $sql = $args{sql} || $log->logcroak("BUG: undefined query sql"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'sql'} || $log->logcroak('BUG: undefined query sql')
MC/DC0%0/2
$args{'sql'} || $log->logcroak('BUG: undefined query sql')
$args{'sql'}
$log->logcroak('BUG: undefined query sql')
Truth table0%0/3
A || B
A= $args{'sql'}B= $log->logcroak('BUG: undefined query sql')
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | my $session = $args{session} || $log->logcroak("BUG: undefined query session"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'session'} || $log->logcroak('BUG: undefined query session')
MC/DC0%0/2
$args{'session'} || $log->logcroak('BUG: undefined query session')
$args{'session'}
$log->logcroak('BUG: undefined query session')
Truth table0%0/3
A || B
A= $args{'session'}B= $log->logcroak('BUG: undefined query session')
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $params = $args{params} || $log->logcroak("BUG: undefined query parameters"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'params'} || $log->logcroak('BUG: undefined query parameters')
MC/DC0%0/2
$args{'params'} || $log->logcroak('BUG: undefined query parameters')
$args{'params'}
$log->logcroak('BUG: undefined query parameters')
Truth table0%0/3
A || B
A= $args{'params'}B= $log->logcroak('BUG: undefined query parameters')
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $result = $args{result} || $log->logcroak("BUG: undefined query result"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'result'} || $log->logcroak('BUG: undefined query result')
MC/DC0%0/2
$args{'result'} || $log->logcroak('BUG: undefined query result')
$args{'result'}
$log->logcroak('BUG: undefined query result')
Truth table0%0/3
A || B
A= $args{'result'}B= $log->logcroak('BUG: undefined query result')
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $retry = $args{retry} || $log->logcroak("BUG: undefined query retry"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'retry'} || $log->logcroak('BUG: undefined query retry')
MC/DC0%0/2
$args{'retry'} || $log->logcroak('BUG: undefined query retry')
$args{'retry'}
$log->logcroak('BUG: undefined query retry')
Truth table0%0/3
A || B
A= $args{'retry'}B= $log->logcroak('BUG: undefined query retry')
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $log->logcroak("invalid query name: contain non alfanumeric characters ($name)") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | if ($name !~ /^[a-zA-Z0-9_]+$/); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $log->logcroak("invalid query parameters: expecting an array reference: ".Dumper($params)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | if (ref $params ne 'ARRAY'); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | foreach my $p (@{$params}) { | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | $log->logcroak("invalid query parameter: contain undefined parameter: ".Dumper($params)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | if (!defined $p); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $log->logcroak("invalid query parameter: contain non alfanumeric characters [$p]") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | if ($p !~ /^[a-zA-Z0-9\,_]+$/); | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | $result = lc $result; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | $log->logcroak("invalid result type: $result") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | if ($result !~ /^(sth|scalar|hashref|scalariterator|hashrefiterator)$/); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $log->logcroak("invalid retry type: $result") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | if ($retry !~ /^(safe|never|always)$/); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # TODO: validate the query's sql code | ||||||||||||||||||||||||||||
| 43 | # TODO: validate session | ||||||||||||||||||||||||||||
| 44 | # my $session = $args{session} || $log->logcroak("BUG: undefined query session"); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | debug "adding query $name to pool, under session $session"; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | $self->{$name} = { | |||||||||||||||||||||||||||
| 49 | sql => $sql, | ||||||||||||||||||||||||||||
| 50 | session => $session, | ||||||||||||||||||||||||||||
| 51 | params => $params, | ||||||||||||||||||||||||||||
| 52 | result => $result, | ||||||||||||||||||||||||||||
| 53 | retry => $retry, | ||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | return $self; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub delete_queries { | ||||||||||||||||||||||||||
|
Subroutine
delete_queries: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $session) = @_; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | get_logger()->logcroak("BUG: undefined query session") unless defined $session; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | foreach my $name (keys %$self) { | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (exists $self->{$name}->{session} && $self->{$name}->{session} eq $session) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $self->{$name}{"session"} and $self->{$name}{"session"} eq $session
MC/DC0%0/2
exists $self->{$name}{"session"} and $self->{$name}{"session"} eq $session
exists $self->{$name}{"session"}
$self->{$name}{"session"} eq $session
Truth table0%0/3
A and B
A= exists $self->{$name}{"session"}B= $self->{$name}{"session"} eq $session
| |||||||||||||||||||||||||||||
| 65 | 0 | delete $self->{$name}; | |||||||||||||||||||||||||||
| 66 | 0 | debug "removing query $name from pool, under session $session"; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub knows_query { | ||||||||||||||||||||||||||
|
Subroutine
knows_query: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | get_logger()->logcroak("BUG: undefined query name") if (!defined $name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return (exists $self->{$name}) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub get_query { | ||||||||||||||||||||||||||
|
Subroutine
get_query: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | get_logger()->logcroak("BUG: undefined query name") if (!defined $name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | get_logger()->logcroak("BUG: unknown query $name") if (!$self->knows_query($name)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | return ($self->{$name}->{session}, $self->{$name}->{sql}, $self->{$name}->{result}, @{$self->{$name}->{params}}); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub get_retry_attribute { | ||||||||||||||||||||||||||
|
Subroutine
get_retry_attribute: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | get_logger()->logcroak("BUG: undefined query name") if (!defined $name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | get_logger()->logcroak("BUG: unknown query $name") if (!$self->knows_query($name)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | return $self->{$name}->{retry}; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||