blib/lib/DBIO/Carp.pm

filter: Statementstmt 98.4% 62 / 63 Branchbran 93.7% 30 / 32 Conditioncond 88.4% 23 / 26 MC/DCmcdc 46.1% 6 / 13 Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 90.3% 131 / 145 CC 26 SCAR 25.7
CC
26
Cov
95%
__find_caller
21.0
__ANON__
3.0
__ANON__
2.0
CRAP 13.1
« blib/lib/DBIO/SQLMaker.pm ↑ Summary blib/lib/DBIO/Relationship/ManyToMany.pm »
1 package DBIO::Carp;
2 # ABSTRACT: Error reporting utilities for DBIO
3  
4 488 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 488 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 488 our $VERSION = '0.900007';
8  
9 # load Carp early to prevent tickling of the ::Internal stash being
10 # interpreted as "Carp is already loaded" by some braindead loader
11 488 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 488 $Carp::Internal{ (__PACKAGE__) }++;
13  
14  
15 3227 ▶sub __find_caller {
Subroutine __find_caller: called CC=21 SCAR=30.5
16 3227 my ($skip_pattern, $class) = @_;
17  
18 3227 ▶ my $skip_class_data = $class->_skip_namespace_frames
Branch: 1 branch
BranchTrueFalseTotal
if $class and $class->can("_skip_namespace_frames") 2848 379 3227
Condition66%2/3
$class and $class->can("_skip_namespace_frames")
!ll&&!rl&&r
03792848
MC/DC50%1/2
$class and $class->can("_skip_namespace_frames")
$class $class->can("_skip_namespace_frames")
Truth table66%2/3
A and B
A= $classB= $class->can("_skip_namespace_frames")
ABresult
0X0
100
111
19 if ($class and $class->can('_skip_namespace_frames'));
20  
21 3227 ▶ $skip_pattern = qr/$skip_pattern|$skip_class_data/
Branch: 1 branch
BranchTrueFalseTotal
if $skip_class_data 2848 379 3227
22 if $skip_class_data;
23  
24 3227 my $fr_num = 1; # skip us and the calling carp*
25  
26 3227 my (@f, $origin, @skipped);
27 3227 ▶ while (@f = caller($fr_num++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@f = caller $fr_num++) 19145 15 19160
28  
29 # A finally block runs from the DESTROY of Try::Tiny's guard object: that
30 # frame, like the blocks, is no origin -- the sub around the try is.
31 19145 ▶ if
Branch: 1 branch
BranchTrueFalseTotal
if ($f[3] eq "(eval)" or $f[3] eq "Try::Tiny::ScopeGuard::DESTROY" or $f[3] =~ /::(?:__ANON__|(?:try|catch|finally) \{\.\.\.\}\s*)$/) 1805 17340 19145
Condition100%6/6
$f[3] eq "(eval)" or $f[3] eq "Try::Tiny::ScopeGuard::DESTROY" or $f[3] =~ /::(?:__ANON__|(?:try|catch|finally) \{\.\.\.\}\s*)$/
l!l&&r!l&&!r
774103117340
$f[3] eq "(eval)" or $f[3] eq "Try::Tiny::ScopeGuard::DESTROY"
l!l&&r!l&&!r
773118371
MC/DC100%3/3
$f[3] eq "(eval)" or $f[3] eq "Try::Tiny::ScopeGuard::DESTROY" or $f[3] =~ /::(?:__ANON__|(?:try|catch|finally) \{\.\.\.\}\s*)$/
$f[3] eq "(eval)" $f[3] eq "Try::Tiny::ScopeGuard::DESTROY" $f[3] =~ /::(?:__ANON__|(?:try|catch|finally) \{\.\.\.\}\s*)$/
Truth table100%4/4
A or B or C
A= $f[3] eq "(eval)"B= $f[3] eq "Try::Tiny::ScopeGuard::DESTROY"C= $f[3] =~ /::(?:__ANON__|(?:try|catch|finally) \{\.\.\.\}\s*)$/
ABCresult
1XX1
01X1
0011
0000
32 ( $f[3] eq '(eval)'
33 or $f[3] eq 'Try::Tiny::ScopeGuard::DESTROY'
34 or $f[3] =~ /::(?:__ANON__|(?:try|catch|finally) \{\.\.\.\}\s*)$/ ) {
35 1805 push @skipped, [ @f ];
36 1805 next;
37 }
38  
39 $origin ||= (
40 $f[3] =~ /^ (.+) :: ([^\:]+) $/x
41 and
42 17340 ▶ ! $Carp::Internal{$1}
Branch: 1 branch
BranchTrueFalseTotal
$f[3] =~ /^ (.+) :: ([^\:]+) $/x && !$Carp::Internal{$1} && !($1 =~ /^(?: DBIO::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x) && !($2 =~ /^(?: throw_exception | _dbi_handle_error | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x) ? : 2965 7059 10024
Condition91%11/12
$origin ||= $f[3] =~ /^ (.+) :: ([^\:]+) $/x && !$Carp::Internal{$1} && !($1 =~ /^(?: DBIO::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x) && !($2 =~ /^(?: throw_exception | _dbi_handle_error | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x) ? $f[3] : undef
l!l&&r!l&&!r
731629657059
$f[3] =~ /^ (.+) :: ([^\:]+) $/x and not $Carp::Internal{$1} and not $1 =~ /^(?: DBIO::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x and not $2 =~ /^(?: throw_exception | _dbi_handle_error | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x
!ll&&!rl&&r
330637532965
$f[3] =~ /^ (.+) :: ([^\:]+) $/x and not $Carp::Internal{$1} and not $1 =~ /^(?: DBIO::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x
!ll&&!rl&&r
3219876718
$f[3] =~ /^ (.+) :: ([^\:]+) $/x and not $Carp::Internal{$1}
!ll&&!rl&&r
032196805
MC/DC0%0/5
$origin ||= $f[3] =~ /^ (.+) :: ([^\:]+) $/x && !$Carp::Internal{$1} && !($1 =~ /^(?: DBIO::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x) && !($2 =~ /^(?: throw_exception | _dbi_handle_error | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x) ? $f[3] : undef
$origin $f[3] =~ /^ (.+) :: ([^\:]+) $/x not $Carp::Internal{$1} not $1 =~ /^(?: DBIO::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x not $2 =~ /^(?: throw_exception | _dbi_handle_error | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x
Truth table0%0/6
A ||= B and not(C) and not(D) and not(E)
A= $originB= $f[3] =~ /^ (.+) :: ([^\:]+) $/xC= not $Carp::Internal{$1}D= not $1 =~ /^(?: DBIO::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/xE= not $2 =~ /^(?: throw_exception | _dbi_handle_error | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
43 and
44 #############################
45 # Need a way to parameterize this for Carp::Skip
46 $1 !~ /^(?: DBIO::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x
47 and
48 $2 !~ /^(?: throw_exception | _dbi_handle_error | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x
49 #############################
50 ) ? $f[3] : undef;
51  
52 17340 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($f[0]->can("_skip_namespace_frames") and my $extra_skip = $f[0]->_skip_namespace_frames) 11669 5671 17340
Condition66%2/3
$f[0]->can("_skip_namespace_frames") and my $extra_skip = $f[0]->_skip_namespace_frames
!ll&&!rl&&r
5671011669
MC/DC50%1/2
$f[0]->can("_skip_namespace_frames") and my $extra_skip = $f[0]->_skip_namespace_frames
$f[0]->can("_skip_namespace_frames") my $extra_skip = $f[0]->_skip_namespace_frames
Truth table66%2/3
A and B
A= $f[0]->can("_skip_namespace_frames")B= my $extra_skip = $f[0]->_skip_namespace_frames
ABresult
0X0
100
111
53 $f[0]->can('_skip_namespace_frames')
54 and
55 my $extra_skip = $f[0]->_skip_namespace_frames
56 ) {
57 11669 $skip_pattern = qr/$skip_pattern|$extra_skip/;
58 }
59  
60 17340 ▶ last if $f[0] !~ $skip_pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless $f[0] =~ /$skip_pattern/ 3212 14128 17340
61 }
62  
63 # Nothing matched: the frames between the raiser and the program were all
64 # skipped ones (a callback, an eval). Name the first of them called from
65 # outside the skip pattern, as extended by the frames walked; only without
66 # such a frame is the full stack the answer.
67 3227 ▶ unless (@f) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@f) 15 3212 3227
68 15 my ($hit) = grep { $_->[0] !~ $skip_pattern } @skipped;
69 15 ▶ @f = @$hit if $hit;
Branch: 1 branch
BranchTrueFalseTotal
if $hit 10 5 15
70 }
71  
72 my $site = @f # if empty - nothing matched - full stack
73 ? "at $f[1] line $f[2]"
74 3227 ▶ : do {
Branch: 1 branch
BranchTrueFalseTotal
@f ? : 3222 5 3227
75 # The full stack comes with the arguments of its frames: no password
76 # among them. DBIO::Util imports from this module while it compiles,
77 # so it cannot be loaded up there.
78 5 require DBIO::Util;
79 5 DBIO::Util::masked_longmess();
80 }
81 ;
82 3227 ▶ $origin ||= '{UNKNOWN}';
Condition100%2/2
$origin ||= "{UNKNOWN}"
l!l
2965262
MC/DC100%1/1
$origin ||= "{UNKNOWN}"
$origin
Truth table100%2/2
A
A= $origin
Aresult
11
00
83  
84 return (
85 3227 ▶ $site,
Branch: 1 branch
BranchTrueFalseTotal
$origin =~ /::/ ? : 2965 262 3227
86 $origin =~ /::/ ? "$origin(): " : "$origin: ", # cargo-cult from Carp::Clan
87 );
88 };
89  
90 204 ▶my $warn = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
91 204 my ($ln, @warn) = @_;
92 204 ▶ @warn = "Warning: something's wrong" unless @warn;
Branch: 1 branch
BranchTrueFalseTotal
unless @warn 0 204 204
93  
94 # back-compat with Carp::Clan - a warning ending with \n does
95 # not include caller info
96 204 ▶ warn (
Branch: 1 branch
BranchTrueFalseTotal
$warn[-1] =~ /\n$/ ? : 6 198 204
97 @warn,
98 $warn[-1] =~ /\n$/ ? '' : " $ln\n"
99 );
100 488 };
101  
102  
103 6029 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
104 6029 my (undef, $skip_pattern) = @_;
105 6029 my $into = caller;
106  
107 6029 ▶ $skip_pattern = $skip_pattern
Branch: 1 branch
BranchTrueFalseTotal
$skip_pattern ? : 488 5541 6029
108 ? qr/ ^ $into $ | $skip_pattern /x
109 : qr/ ^ $into $ /x
110 ;
111  
112 488 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 6029 ▶ *{"${into}::carp"} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
115 187 $warn->(
116 __find_caller($skip_pattern, $into),
117 @_
118 );
119 6029 };
120  
121 6029 my $fired = {};
122 6029 ▶ *{"${into}::carp_once"} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
123 4 ▶ return if $fired->{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $$fired{$_[0]} 0 4 4
124 4 $fired->{$_[0]} = 1;
125  
126 4 $warn->(
127 __find_caller($skip_pattern, $into),
128 @_,
129 );
130 6029 };
131  
132 6029 my $seen;
133 6029 ▶ *{"${into}::carp_unique"} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
134 22 my ($ln, $calling) = __find_caller($skip_pattern, $into);
135 22 my $msg = join ('', $calling, @_);
136  
137 # unique carping with a hidden caller makes no sense
138 22 $msg =~ s/\n+$//;
139  
140 22 ▶ return if $seen->{$ln}{$msg};
Branch: 1 branch
BranchTrueFalseTotal
if $seen->{$ln}{$msg} 9 13 22
141 13 $seen->{$ln}{$msg} = 1;
142  
143 13 $warn->(
144 $ln,
145 $msg,
146 );
147 6029 };
148 }
149  
150  
151 0 ▶sub unimport {
Subroutine unimport: not called CC=1 SCAR=6.9
152 0 die (__PACKAGE__ . " does not implement unimport yet\n");
153 }
154  
155 488 1;
156  
157 __END__
« blib/lib/DBIO/SQLMaker.pm ↑ Summary blib/lib/DBIO/Relationship/ManyToMany.pm »