| 1 | package Tapper::Metadata::Query; | ||||||||||||||||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | 1 | $Tapper::Metadata::Query::VERSION = '5.0.1'; | |||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Digest::MD5; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | my ( $s_self, $hr_atts ) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | for my $s_key (qw/ config dbh /) { | |||||||||||||||||||||||||||
| 15 | 2 | ▶ | if (! $hr_atts->{$s_key} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 0 | require Carp; | |||||||||||||||||||||||||||
| 17 | 0 | Carp::confess("missing parameter '$s_key'"); | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | return bless { | ||||||||||||||||||||||||||||
| 22 | now => $hr_atts->{now}, | ||||||||||||||||||||||||||||
| 23 | dbh => $hr_atts->{dbh}, | ||||||||||||||||||||||||||||
| 24 | cache => $hr_atts->{cache}, | ||||||||||||||||||||||||||||
| 25 | debug => $hr_atts->{debug} || 0, | ||||||||||||||||||||||||||||
| 26 | config => $hr_atts->{config}, | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | }, $s_self; | ||||||||||||||||||||||||||
|
Condition50%1/2
$hr_atts->{'debug'} || 0
MC/DC0%0/1
$hr_atts->{'debug'} || 0
$hr_atts->{'debug'}
Truth table50%1/2
A
A= $hr_atts->{'debug'}
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 44 | ▶ | sub execute_query { | ||||||||||||||||||||||||||
|
Subroutine
execute_query: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 44 | my ( $or_self, $s_statement, $ar_vals ) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 44 | ▶ | $ar_vals ||= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$ar_vals ||= []
MC/DC0%0/1
$ar_vals ||= []
$ar_vals
Truth table50%1/2
A
A= $ar_vals
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 44 | ▶ | if ( $or_self->{debug} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | warn $s_statement . ' (' . (join ',', @{$ar_vals}) . ')'; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 44 | local $or_self->{dbh}{RaiseError} = 1; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 44 | my $or_prepared = $or_self->{dbh}->prepare_cached( $s_statement ); | |||||||||||||||||||||||||||
| 44 | 44 | my $b_result = $or_prepared->execute( @{$ar_vals} ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 44 | return ( $or_prepared, $b_result ); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 25 | ▶ | sub insert { | ||||||||||||||||||||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 25 | my ( $or_self, $s_statement, $ar_vals ) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 25 | my ( $or_prepared, $b_result ) = $or_self->execute_query( $s_statement, $ar_vals ); | |||||||||||||||||||||||||||
| 55 | 25 | $or_prepared->finish(); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 25 | return $b_result; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | ▶ | sub selectrow_hashref { | ||||||||||||||||||||||||||
|
Subroutine
selectrow_hashref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 3 | my ( $or_self, $s_statement, $ar_vals ) = @_; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | my ( $or_prepared, undef ) = $or_self->execute_query( $s_statement, $ar_vals ); | |||||||||||||||||||||||||||
| 66 | 3 | my $hr_return = $or_prepared->fetchrow_hashref; | |||||||||||||||||||||||||||
| 67 | 3 | $or_prepared->finish(); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 3 | return $hr_return; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 9 | ▶ | sub selectrow_arrayref { | ||||||||||||||||||||||||||
|
Subroutine
selectrow_arrayref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 9 | my ( $or_self, $s_statement, $ar_vals ) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 9 | my ( $or_prepared, undef ) = $or_self->execute_query( $s_statement, $ar_vals ); | |||||||||||||||||||||||||||
| 78 | 9 | my $hr_return = $or_prepared->fetchrow_arrayref; | |||||||||||||||||||||||||||
| 79 | 9 | $or_prepared->finish(); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 9 | return $hr_return; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub selectall_arrayref { | ||||||||||||||||||||||||||
|
Subroutine
selectall_arrayref: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my ( $or_self, $s_statement, $ar_vals ) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | my ( $or_prepared, undef ) = $or_self->execute_query( $s_statement, $ar_vals ); | |||||||||||||||||||||||||||
| 90 | 0 | my $hr_return = $or_prepared->fetchall_arrayref; | |||||||||||||||||||||||||||
| 91 | 0 | $or_prepared->finish(); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | return $hr_return; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub selectall_hashref { | ||||||||||||||||||||||||||
|
Subroutine
selectall_hashref: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | my ( $or_self, $s_statement, $ar_vals ) = @_; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my ( $or_prepared, undef ) = $or_self->execute_query( $s_statement, $ar_vals ); | |||||||||||||||||||||||||||
| 102 | 0 | my $hr_return = $or_prepared->fetchall_arrayref({}); | |||||||||||||||||||||||||||
| 103 | 0 | $or_prepared->finish(); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | return $hr_return; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 16 | ▶ | sub last_insert_id { | ||||||||||||||||||||||||||
|
Subroutine
last_insert_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 16 | my ( $or_self, $s_table, $s_column ) = @_; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | return $or_self->{dbh}->last_insert_id( | ||||||||||||||||||||||||||||
| 114 | 16 | undef, undef, $s_table, $s_column, | |||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 5 | ▶ | sub start_transaction { | ||||||||||||||||||||||||||
|
Subroutine
start_transaction: called CC=7 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 5 | my ( $or_self ) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 5 | ▶ | if ( defined( $or_self->{transaction_supported} ) && !$or_self->{transaction_supported} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $or_self->{"transaction_supported"} and not $or_self->{"transaction_supported"}
MC/DC0%0/2
defined $or_self->{"transaction_supported"} and not $or_self->{"transaction_supported"}
defined $or_self->{"transaction_supported"}
not $or_self->{"transaction_supported"}
Truth table66%2/3
A and not(B)
A= defined $or_self->{"transaction_supported"}B= not $or_self->{"transaction_supported"}
| |||||||||||||||||||||||||||||
| 124 | 0 | return 0; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 5 | ▶ | if ( $or_self->{dbh}{BegunWork} || $or_self->{dbh}{AutoCommit} == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$or_self->{"dbh"}{"BegunWork"} or $or_self->{"dbh"}{"AutoCommit"} == 0
MC/DC0%0/2
$or_self->{"dbh"}{"BegunWork"} or $or_self->{"dbh"}{"AutoCommit"} == 0
$or_self->{"dbh"}{"BegunWork"}
$or_self->{"dbh"}{"AutoCommit"} == 0
Truth table33%1/3
A or B
A= $or_self->{"dbh"}{"BegunWork"}B= $or_self->{"dbh"}{"AutoCommit"} == 0
| |||||||||||||||||||||||||||||
| 127 | 0 | return 0; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 5 | @{$or_self->{backup_attributes}}{qw/RaiseError PrintError AutoCommit/} = | |||||||||||||||||||||||||||
| 131 | 5 | @{$or_self->{dbh}}{qw/RaiseError PrintError AutoCommit/} | |||||||||||||||||||||||||||
| 132 | ; | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 5 | eval { | |||||||||||||||||||||||||||
| 135 | 5 | $or_self->{dbh}{AutoCommit} = 0; | |||||||||||||||||||||||||||
| 136 | 5 | $or_self->{dbh}{RaiseError} = 1; | |||||||||||||||||||||||||||
| 137 | 5 | $or_self->{dbh}{PrintError} = 0; | |||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||
| 139 | 5 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ( $or_self->{debug} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | require Carp; | |||||||||||||||||||||||||||
| 142 | 0 | Carp::cluck('Transactions not supported by your database'); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 0 | $or_self->{transaction_supported} = 0; | |||||||||||||||||||||||||||
| 145 | 0 | return 0; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else { | ||||||||||||||||||||||||||||
| 148 | 5 | $or_self->{transaction_supported} = 1; | |||||||||||||||||||||||||||
| 149 | 5 | return 1; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 5 | ▶ | sub finish_transaction { | ||||||||||||||||||||||||||
|
Subroutine
finish_transaction: called CC=5 SCAR=22.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 5 | my ( $or_self, $b_started, $s_error ) = @_; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 5 | ▶ | if ( $or_self->{transaction_supported} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 5 | ▶ | if ( $b_started ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 5 | ▶ | if ( $s_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | $or_self->{dbh}->rollback(); | |||||||||||||||||||||||||||
| 162 | 0 | @{$or_self->{dbh}}{qw/RaiseError PrintError AutoCommit/} = | |||||||||||||||||||||||||||
| 163 | 0 | @{$or_self->{backup_attributes}}{qw/RaiseError PrintError AutoCommit/} | |||||||||||||||||||||||||||
| 164 | ; | ||||||||||||||||||||||||||||
| 165 | 0 | require Carp; | |||||||||||||||||||||||||||
| 166 | 0 | Carp::confess("transaction failed: $s_error"); | |||||||||||||||||||||||||||
| 167 | 0 | return 0; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | else { | ||||||||||||||||||||||||||||
| 170 | 5 | $or_self->{dbh}->commit(); | |||||||||||||||||||||||||||
| 171 | 5 | @{$or_self->{dbh}}{qw/RaiseError PrintError AutoCommit/} = | |||||||||||||||||||||||||||
| 172 | 5 | @{$or_self->{backup_attributes}}{qw/RaiseError PrintError AutoCommit/} | |||||||||||||||||||||||||||
| 173 | ; | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | else { | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ( $s_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | require Carp; | |||||||||||||||||||||||||||
| 179 | 0 | Carp::confess("transaction failed: $s_error"); | |||||||||||||||||||||||||||
| 180 | 0 | return 0; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 5 | return 1; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 1 | 1; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | __END__ | ||||||||||||||||||||||||||||