| 1 | package DBIx::OpenTracing; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use feature qw[ state ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use syntax 'maybe'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use B; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Carp qw[ croak ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Caller::Hide qw[ hide_package ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use DBIx::OpenTracing::Constants ':ALL'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use List::Util qw[ sum0 ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use OpenTracing::GlobalTracer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use Package::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Scalar::Util qw[ blessed looks_like_number ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Scope::Context; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | hide_package(__PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use constant TAGS_DEFAULT => (DB_TAG_TYPE ,=> 'sql'); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | _DBI_EXECUTE => \&DBI::st::execute, | |||||||||||||||||||||||||||||||||||||||||
| 25 | _DBI_DO => \&DBI::db::do, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | _DBI_SELECTROW_ARRAY => \&DBI::db::selectrow_array, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | _DBI_SELECTROW_ARRAYREF => \&DBI::db::selectrow_arrayref, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | _DBI_SELECTROW_HASHREF => \&DBI::db::selectrow_hashref, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | _DBI_SELECTALL_ARRAYREF => \&DBI::db::selectall_arrayref, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | _DBI_SELECTALL_ARRAY => \&DBI::db::selectall_array, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | _DBI_SELECTROW_ARRAY => \&DBI::db::selectrow_array, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | _DBI_SELECTALL_HASHREF => \&DBI::db::selectall_hashref, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | _DBI_SELECTCOL_ARRAYREF => \&DBI::db::selectcol_arrayref, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | ▶ | if (%DBIx::QueryLog::SKIP_PKG_MAP) { # hide from DBIx::QueryLog's caller() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $DBIx::QueryLog::SKIP_PKG_MAP{ (__PACKAGE__) } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | our $is_currently_traced; # lexicals can't be localized | |||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | my ($is_enabled, $is_suspended); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 31 | ▶ | sub _numeric_result { 0+ $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_numeric_result: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | ▶ | sub _sum_elements { looks_like_number($_[0]) ? $_[0] : 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sum_elements: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 74 | ▶ | sub _array_size { scalar @{ $_[0] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_array_size: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 16 | ▶ | sub _hash_key_count { scalar keys %{ $_[0] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hash_key_count: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # signature processors statement, bind values | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 169 | ▶ | sub _sig_dbh_stmt_attr_bind { @_[ 1, 3 .. $#_ ] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sig_dbh_stmt_attr_bind: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 16 | ▶ | sub _sig_dbh_stmt_key_attr_bind { @_[ 1, 4 .. $#_ ] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sig_dbh_stmt_key_attr_bind: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 10 | ▶ | sub _sig_sth_bind { @_[ 0, 1 .. $#_ ] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sig_sth_bind: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 29 | ▶ | sub enable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 29 | ▶ | return if $is_enabled or $is_suspended; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_enabled or $is_suspended
MC/DC100%2/2
$is_enabled or $is_suspended
$is_enabled
$is_suspended
Truth table100%3/3
A or B
A= $is_enabledB= $is_suspended
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | state $execute = _gen_wrapper(_DBI_EXECUTE, { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | signature => \&_sig_sth_bind, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | row_counter => \&_numeric_result, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 10 | ▶ | count_condition => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | my ($sth) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | my $fields = $sth->{NUM_OF_FIELDS}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 10 | ▶ | return !defined $fields || $fields == 0; # non-select | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
!defined($fields) || $fields == 0
MC/DC50%1/2
!defined($fields) || $fields == 0
!defined($fields)
$fields == 0
Truth table66%2/3
not(A) || B
A= !defined($fields)B= $fields == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 23 | }); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 23 | *DBI::st::execute = $execute; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 23 | state $do = _gen_wrapper(_DBI_DO, { | |||||||||||||||||||||||||||||||||||||||||
| 68 | signature => \&_sig_dbh_stmt_attr_bind, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | row_counter => \&_numeric_result, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 23 | *DBI::db::do = $do; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 23 | state $selectall_array = _gen_wrapper(_DBI_SELECTALL_ARRAY, { | |||||||||||||||||||||||||||||||||||||||||
| 74 | signature => \&_sig_dbh_stmt_attr_bind, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | row_counter => \&_sum_elements | ||||||||||||||||||||||||||||||||||||||||||
| 76 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 23 | *DBI::db::selectall_array = $selectall_array; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 23 | state $selectall_arrayref = _gen_wrapper(_DBI_SELECTALL_ARRAYREF, { | |||||||||||||||||||||||||||||||||||||||||
| 80 | signature => \&_sig_dbh_stmt_attr_bind, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | row_counter => \&_array_size | ||||||||||||||||||||||||||||||||||||||||||
| 82 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 23 | *DBI::db::selectall_arrayref = $selectall_arrayref; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 23 | state $selectcol_arrayref = _gen_wrapper(_DBI_SELECTCOL_ARRAYREF, { | |||||||||||||||||||||||||||||||||||||||||
| 86 | signature => \&_sig_dbh_stmt_attr_bind, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | row_counter => \&_array_size, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 23 | *DBI::db::selectcol_arrayref = $selectcol_arrayref; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | state $selectrow_array = _gen_wrapper(_DBI_SELECTROW_ARRAY, { | |||||||||||||||||||||||||||||||||||||||||
| 92 | signature => \&_sig_dbh_stmt_attr_bind, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 23 | *DBI::db::selectrow_array = $selectrow_array; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 23 | state $selectrow_arrayref = _gen_wrapper(_DBI_SELECTROW_ARRAYREF, { | |||||||||||||||||||||||||||||||||||||||||
| 97 | signature => \&_sig_dbh_stmt_attr_bind | ||||||||||||||||||||||||||||||||||||||||||
| 98 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 23 | *DBI::db::selectrow_arrayref = $selectrow_arrayref; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 23 | state $selectall_hashref = _gen_wrapper(_DBI_SELECTALL_HASHREF, { | |||||||||||||||||||||||||||||||||||||||||
| 102 | signature => \&_sig_dbh_stmt_key_attr_bind, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | row_counter => \&_hash_key_count, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 23 | *DBI::db::selectall_hashref = $selectall_hashref; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 23 | state $selectrow_hashref = _gen_wrapper(_DBI_SELECTROW_HASHREF, { | |||||||||||||||||||||||||||||||||||||||||
| 108 | signature => \&_sig_dbh_stmt_attr_bind, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 23 | *DBI::db::selectrow_hashref = $selectrow_hashref; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 23 | $is_enabled = 1; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 23 | return; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 20 | ▶ | sub disable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 20 | ▶ | return unless $is_enabled; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 7 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 16 | *DBI::st::execute = _DBI_EXECUTE; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 16 | *DBI::db::do = _DBI_DO; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 16 | *DBI::db::selectall_array = _DBI_SELECTALL_ARRAY; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 16 | *DBI::db::selectall_arrayref = _DBI_SELECTALL_ARRAYREF; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 16 | *DBI::db::selectcol_arrayref = _DBI_SELECTCOL_ARRAYREF; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 16 | *DBI::db::selectrow_array = _DBI_SELECTROW_ARRAY; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 16 | *DBI::db::selectrow_arrayref = _DBI_SELECTROW_ARRAYREF; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 16 | *DBI::db::selectall_hashref = _DBI_SELECTALL_HASHREF; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 16 | *DBI::db::selectrow_hashref = _DBI_SELECTROW_HASHREF; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 16 | $is_enabled = 0; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 7 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 7 | my ($class, $tag_mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | enable(); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | ▶ | return if not defined $tag_mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | my @sensitive_tags = ( | |||||||||||||||||||||||||||||||||||||||||
| 143 | DB_TAG_SQL, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | DB_TAG_BIND, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | DB_TAG_USER, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | DB_TAG_DBNAME, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | ▶ | if ($tag_mode eq '-none') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $class->hide_tags(DB_TAGS_ALL); | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | elsif ($tag_mode eq '-safe') { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | $class->hide_tags(@sensitive_tags); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | elsif ($tag_mode eq '-secure') { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | $class->_disable_tags(@sensitive_tags); | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | croak "Unknown mode: $tag_mode"; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub unimport { disable() } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unimport: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 205 | ▶ | sub _tags_dbh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tags_dbh: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 205 | my ($dbh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 205 | ▶ | return if !blessed($dbh) or !$dbh->isa('DBI::db'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($dbh) and $dbh->isa("DBI::db")
MC/DC50%1/2
builtin::blessed($dbh) and $dbh->isa("DBI::db")
builtin::blessed($dbh)
$dbh->isa("DBI::db")
Truth table66%2/3
A and B
A= builtin::blessed($dbh)B= $dbh->isa("DBI::db")
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 195 | my $dbname = $dbh->{Name}; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 195 | ▶ | $dbname = $1 if $dbname =~ /dbname=([^;]+);/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 174 | maybe DB_TAG_USER ,=> $dbh->{Username}, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 195 | maybe DB_TAG_DBNAME ,=> $dbname, | |||||||||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 195 | ▶ | sub _tags_sth { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tags_sth: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 195 | my ($sth) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 195 | my (%tags, $sql); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 195 | ▶ | if (!blessed($sth) or !$sth->isa('DBI::st')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($sth) && $sth->isa('DBI::st')
MC/DC50%1/2
builtin::blessed($sth) && $sth->isa('DBI::st')
builtin::blessed($sth)
$sth->isa('DBI::st')
Truth table66%2/3
A && B
A= builtin::blessed($sth)B= $sth->isa('DBI::st')
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 185 | $sql = "$sth"; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 10 | %tags = _tags_dbh($sth->{Database}); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 10 | $sql = $sth->{Statement}; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 195 | $sql = _remove_sql_comments($sql); | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 195 | $tags{ (DB_TAG_SQL) } = $sql; | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 195 | ▶ | if (my $summary = _gen_sql_summary($sql)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 175 | $tags{ (DB_TAG_SQL_SUMMARY) } = $summary; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 195 | return %tags; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 195 | ▶ | sub _remove_sql_comments { # TODO: support engine-specific syntax properly | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_sql_comments: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 195 | my ($sql) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 195 | $sql =~ s{ | |||||||||||||||||||||||||||||||||||||||||
| 204 | (?> # skip over strings and quoted table names | ||||||||||||||||||||||||||||||||||||||||||
| 205 | (['"`]) # opening quote | ||||||||||||||||||||||||||||||||||||||||||
| 206 | .*? | ||||||||||||||||||||||||||||||||||||||||||
| 207 | (?<!\\)(?:\\{2})* # make sure the closing quote is not escaped | ||||||||||||||||||||||||||||||||||||||||||
| 208 | \1 # closing quote | ||||||||||||||||||||||||||||||||||||||||||
| 209 | )? \K | ||||||||||||||||||||||||||||||||||||||||||
| 210 | | \#.*?$ # hash until end of line | ||||||||||||||||||||||||||||||||||||||||||
| 211 | | --.*?$ # double-dash until end of line | ||||||||||||||||||||||||||||||||||||||||||
| 212 | | /\* (?s).*? \*/ # multi-line C-style comment | ||||||||||||||||||||||||||||||||||||||||||
| 213 | }{}gmx; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 195 | return $sql; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 195 | ▶ | sub _gen_sql_summary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_sql_summary: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 195 | my ($sql) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # comments are removed, so the first occurence should be the keyword | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 195 | my ($type) = $sql =~ /\b( | |||||||||||||||||||||||||||||||||||||||||
| 223 | insert | select | update | ||||||||||||||||||||||||||||||||||||||||||
| 224 | | delete | truncate | show | ||||||||||||||||||||||||||||||||||||||||||
| 225 | | alter | create | drop | ||||||||||||||||||||||||||||||||||||||||||
| 226 | )/ix; | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 195 | ▶ | return if not $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 175 | my $table = '...'; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 175 | ▶ | if ($sql =~ m{(?:from|into|update|truncate|drop|alter|table)\s+(`?)(\w+)\1}i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 131 | $table = $2; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 175 | return uc($type) . ": $table"; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 195 | ▶ | sub _tags_bind_values { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tags_bind_values: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 195 | my ($bind_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 195 | ▶ | return if not @$bind_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 50 | ▶ | my $bind_str = join ',', map { defined $_ ? "`$_`" : 'undef' } @$bind_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 50 | return (DB_TAG_BIND ,=> $bind_str); | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 195 | ▶ | sub _tags_caller { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tags_caller: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 195 | my ($call_package, $call_filename, $call_line) = CORE::caller(1); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 195 | my $call_sub = (CORE::caller(2))[3]; | |||||||||||||||||||||||||||||||||||||||||
| 247 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 195 | maybe | |||||||||||||||||||||||||||||||||||||||||
| 249 | DB_TAG_CALLER_SUB ,=> $call_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | DB_TAG_CALLER_FILE ,=> $call_filename, | ||||||||||||||||||||||||||||||||||||||||||
| 251 | DB_TAG_CALLER_LINE ,=> $call_line, | ||||||||||||||||||||||||||||||||||||||||||
| 252 | DB_TAG_CALLER_PACKAGE ,=> $call_package, | ||||||||||||||||||||||||||||||||||||||||||
| 253 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 7 | my (%hidden_tags, %disabled_tags); | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 332 | ▶ | sub _filter_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filter_tags: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 332 | my ($tags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 332 | delete @$tags{ keys %disabled_tags, keys %hidden_tags }; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 332 | return $tags; | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 137 | ▶ | sub _tag_enabled { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tag_enabled: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 137 | my ($tag) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 137 | return !!_filter_tags({ $tag => 1 })->{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 26 | ▶ | sub hide_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hide_tags: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 26 | my ($class, @tags) = @_;; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 26 | ▶ | return if not @tags; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 20 | undef @hidden_tags{@tags}; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 20 | return; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 31 | ▶ | sub show_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_tags: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 31 | my ($class, @tags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 31 | ▶ | return if not @tags; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 25 | delete @hidden_tags{@tags}; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 25 | return; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 8 | ▶ | sub hide_tags_temporarily { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hide_tags_temporarily: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 8 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 8 | my @tags = grep { not exists $hidden_tags{$_} } @_; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 8 | $class->hide_tags(@tags); | |||||||||||||||||||||||||||||||||||||||||
| 290 | 8 | ▶ | Scope::Context->up->reap(sub { $class->show_tags(@tags) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 8 | ▶ | sub show_tags_temporarily { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_tags_temporarily: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 8 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 8 | my @tags = grep { exists $hidden_tags{$_} } @_; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 8 | $class->show_tags(@tags); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 8 | ▶ | Scope::Context->up->reap(sub { $class->hide_tags(@tags) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 3 | ▶ | sub _disable_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_disable_tags: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 3 | my ($class, @tags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | undef @disabled_tags{@tags}; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | ▶ | sub _enable_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enable_tags: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | my ($class, @tags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | delete @disabled_tags{@tags}; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | ▶ | sub disable_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable_tags: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | my @tags = grep { not exists $disabled_tags{$_} } @_; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | $class->_disable_tags(@tags); | |||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | ▶ | Scope::Context->up->reap(sub { $class->_enable_tags(@tags) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 7 | ▶ | sub _add_tag { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_tag: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 137 | my ($span, $tag, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 137 | ▶ | return unless _tag_enabled($tag); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 135 | $span->add_tag($tag => $value); | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 63 | ▶ | sub _gen_wrapper { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_wrapper: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 63 | my ($method, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 63 | my $row_counter = $args->{row_counter}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 63 | my $sig_processor = $args->{signature}; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 63 | my $count_condition = $args->{count_condition}; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 63 | my $method_name = B::svref_2object($method)->GV->NAME; | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 175 | ▶ | my $can_count_rows = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 175 | ▶ | defined $row_counter | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $row_counter && (!defined($count_condition) || &$count_condition(@_))
not defined $count_condition or &$count_condition(@_)
MC/DC100%3/3
defined $row_counter && (!defined($count_condition) || &$count_condition(@_))
defined $row_counter
not defined $count_condition
&$count_condition(@_)
Truth table100%4/4
A && not(B) or C
A= defined $row_counterB= not defined $count_conditionC= &$count_condition(@_)
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | and | ||||||||||||||||||||||||||||||||||||||||||
| 336 | !defined $count_condition || $count_condition->(@_) | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 63 | }; | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 324 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 324 | ▶ | goto $method if $is_currently_traced; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 195 | local $is_currently_traced = 1; | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 195 | my ($statement, @bind) = $sig_processor->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 344 | 195 | my $handle = shift; | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 195 | my $tracer = OpenTracing::GlobalTracer->get_global_tracer(); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 195 | my $scope = $tracer->start_active_span( | |||||||||||||||||||||||||||||||||||||||||
| 348 | "dbi_$method_name", | ||||||||||||||||||||||||||||||||||||||||||
| 349 | tags => _filter_tags({ | ||||||||||||||||||||||||||||||||||||||||||
| 350 | TAGS_DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||
| 351 | _tags_sth($statement), | ||||||||||||||||||||||||||||||||||||||||||
| 352 | _tags_dbh($handle), | ||||||||||||||||||||||||||||||||||||||||||
| 353 | _tags_bind_values(\@bind), | ||||||||||||||||||||||||||||||||||||||||||
| 354 | _tags_caller(), | ||||||||||||||||||||||||||||||||||||||||||
| 355 | }), | ||||||||||||||||||||||||||||||||||||||||||
| 356 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 195 | my $span = $scope->get_span(); | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 195 | my $result; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 195 | my $wantarray = wantarray; # eval has its own | |||||||||||||||||||||||||||||||||||||||||
| 361 | 195 | my $failed = !eval { | |||||||||||||||||||||||||||||||||||||||||
| 362 | 195 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 26 | $result = [ $handle->$method(@_) ]; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 169 | $result = $handle->$method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 185 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 369 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 195 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 195 | ▶ | if ($failed or defined $handle->err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$failed or defined $handle->err
MC/DC100%2/2
$failed or defined $handle->err
$failed
defined $handle->err
Truth table100%3/3
A or B
A= $failedB= defined $handle->err
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 20 | $span->add_tags( generate_error_tags($handle, $failed) ); | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | elsif ($can_count_rows->($handle)) { | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 137 | ▶ | my $rows = sum0(map { $row_counter->($_) } $wantarray ? @$result : $result); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 137 | _add_tag($span, DB_TAG_ROWS,=> $rows); | |||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 195 | $scope->close(); | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 195 | ▶ | die $error if $failed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 185 | ▶ | return $wantarray ? @$result : $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 63 | } | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 8 | ▶ | sub enable_temporarily { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable_temporarily: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 8 | ▶ | return if $is_enabled; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 6 | enable(); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 6 | Scope::Context->up->reap(\&disable); | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 8 | ▶ | sub disable_temporarily { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable_temporarily: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 8 | ▶ | return unless $is_enabled; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 4 | disable(); | |||||||||||||||||||||||||||||||||||||||||
| 397 | 4 | Scope::Context->up->reap(\&enable); | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | ▶ | sub suspend { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
suspend: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | ▶ | return if $is_suspended; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 2 | my $was_enabled = $is_enabled; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 2 | disable(); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 2 | $is_suspended = 1; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | ▶ | Scope::Context->up->reap(sub { $is_suspended = 0; enable() if $was_enabled }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 20 | ▶ | sub generate_error_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_error_tags: called CC=4 SCAR=14.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 20 | my ($handle, $failed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 20 | ▶ | my $error_message = sprintf ("DBI Error: SQLSTATE_%s - [%s]", | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$handle->state || '-----'
$handle->err || '-'
MC/DC0%0/1
$handle->state || '-----'
$handle->state
MC/DC0%0/1
$handle->err || '-'
$handle->err
Truth table50%1/2
A
A= $handle->state
Truth table50%1/2
A
A= $handle->err
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | $handle->state || '-----', | ||||||||||||||||||||||||||||||||||||||||||
| 414 | $handle->err || '-', | ||||||||||||||||||||||||||||||||||||||||||
| 415 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 20 | ▶ | my $error_kind = sprintf("SQLSTATE_%s", | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$handle->state || '-----'
MC/DC0%0/1
$handle->state || '-----'
$handle->state
Truth table50%1/2
A
A= $handle->state
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | $handle->state || '-----', | ||||||||||||||||||||||||||||||||||||||||||
| 418 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 20 | 'error' => 1, | |||||||||||||||||||||||||||||||||||||||||
| 422 | 'message' => $error_message, | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 'error.kind' => $error_kind, | ||||||||||||||||||||||||||||||||||||||||||
| 424 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||