DBIx/Class/Carp.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 96.4% 27 / 28 Conditioncond 86.9% 20 / 23 MC/DCmcdc 41.6% 5 / 12 Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 89.8% 115 / 128 CC 23 SCAR 23.7
CC
23
Cov
95%
__find_caller
18.1
__ANON__
3.0
import
2.0
CRAP 10.7
« DBIx/Class/Storage/DBI/DB2.pm ↑ Summary DBIx/Class/_Util.pm »
1 package # hide from pause
2 DBIx::Class::Carp;
3  
4 308 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 308 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # load Carp early to prevent tickling of the ::Internal stash being
8 # interpreted as "Carp is already loaded" by some braindead loader
9 308 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 308 $Carp::Internal{ (__PACKAGE__) }++;
11  
12 sub __find_caller {
13 2709 ▶ my ($skip_pattern, $class) = @_;
Subroutine __find_caller: called CC=18 SCAR=28.9
14  
15 2709 ▶ my $skip_class_data = $class->_skip_namespace_frames
Branch: 1 branch
BranchTrueFalseTotal
if $class and $class->can("_skip_namespace_frames") 2680 29 2709
Condition66%2/3
$class and $class->can("_skip_namespace_frames")
!ll&&!rl&&r
0292680
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
16 if ($class and $class->can('_skip_namespace_frames'));
17  
18 2709 ▶ $skip_pattern = qr/$skip_pattern|$skip_class_data/
Branch: 1 branch
BranchTrueFalseTotal
if $skip_class_data 2680 29 2709
19 if $skip_class_data;
20  
21 2709 my $fr_num = 1; # skip us and the calling carp*
22  
23 2709 my (@f, $origin);
24 2709 ▶ while (@f = caller($fr_num++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@f = caller $fr_num++) 31310 6 31316
25  
26 next if
27 31310 ▶ ( $f[3] eq '(eval)' or $f[3] =~ /::__ANON__$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $f[3] eq "(eval)" or $f[3] =~ /::__ANON__$/ 3356 27954 31310
Condition100%3/3
$f[3] eq "(eval)" or $f[3] =~ /::__ANON__$/
l!l&&r!l&&!r
238297427954
MC/DC100%2/2
$f[3] eq "(eval)" or $f[3] =~ /::__ANON__$/
$f[3] eq "(eval)" $f[3] =~ /::__ANON__$/
Truth table100%3/3
A or B
A= $f[3] eq "(eval)"B= $f[3] =~ /::__ANON__$/
ABresult
1X1
011
000
28  
29 $origin ||= (
30 $f[3] =~ /^ (.+) :: ([^\:]+) $/x
31 and
32 27954 ▶ ! $Carp::Internal{$1}
Branch: 1 branch
BranchTrueFalseTotal
$f[3] =~ /^ (.+) :: ([^\:]+) $/x && !$Carp::Internal{$1} && !($1 =~ /^(?: DBIx::Class::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x) && !($2 =~ /^(?: throw_exception | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x) ? : 2521 10171 12692
Condition91%11/12
$origin ||= $f[3] =~ /^ (.+) :: ([^\:]+) $/x && !$Carp::Internal{$1} && !($1 =~ /^(?: DBIx::Class::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x) && !($2 =~ /^(?: throw_exception | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x) ? $f[3] : undef
l!l&&r!l&&!r
15262252110171
$f[3] =~ /^ (.+) :: ([^\:]+) $/x and not $Carp::Internal{$1} and not $1 =~ /^(?: DBIx::Class::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x and not $2 =~ /^(?: throw_exception | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x
!ll&&!rl&&r
303371382521
$f[3] =~ /^ (.+) :: ([^\:]+) $/x and not $Carp::Internal{$1} and not $1 =~ /^(?: DBIx::Class::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x
!ll&&!rl&&r
26254089659
$f[3] =~ /^ (.+) :: ([^\:]+) $/x and not $Carp::Internal{$1}
!ll&&!rl&&r
0262510067
MC/DC0%0/5
$origin ||= $f[3] =~ /^ (.+) :: ([^\:]+) $/x && !$Carp::Internal{$1} && !($1 =~ /^(?: DBIx::Class::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x) && !($2 =~ /^(?: throw_exception | 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 =~ /^(?: DBIx::Class::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x not $2 =~ /^(?: throw_exception | 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 =~ /^(?: DBIx::Class::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/xE= not $2 =~ /^(?: throw_exception | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
33 and
34 #############################
35 # Need a way to parameterize this for Carp::Skip
36 $1 !~ /^(?: DBIx::Class::Storage::BlockRunner | Context::Preserve | Try::Tiny | Class::Accessor::Grouped | Class::C3::Componentised | Module::Runtime )$/x
37 and
38 $2 !~ /^(?: throw_exception | carp | carp_unique | carp_once | dbh_do | txn_do | with_deferred_fk_checks)$/x
39 #############################
40 ) ? $f[3] : undef;
41  
42 27954 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($f[0]->can("_skip_namespace_frames") and my $extra_skip = $f[0]->_skip_namespace_frames) 20937 7017 27954
Condition66%2/3
$f[0]->can("_skip_namespace_frames") and my $extra_skip = $f[0]->_skip_namespace_frames
!ll&&!rl&&r
7017020937
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
43 $f[0]->can('_skip_namespace_frames')
44 and
45 my $extra_skip = $f[0]->_skip_namespace_frames
46 ) {
47 20937 $skip_pattern = qr/$skip_pattern|$extra_skip/;
48 }
49  
50 27954 ▶ last if $f[0] !~ $skip_pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless $f[0] =~ /$skip_pattern/ 2703 25251 27954
51 }
52  
53 2709 ▶ my $site = @f # if empty - nothing matched - full stack
Branch: 1 branch
BranchTrueFalseTotal
@f ? : 2703 6 2709
54 ? "at $f[1] line $f[2]"
55 : Carp::longmess()
56 ;
57 2709 ▶ $origin ||= '{UNKNOWN}';
Condition100%2/2
$origin ||= "{UNKNOWN}"
l!l
2521188
MC/DC100%1/1
$origin ||= "{UNKNOWN}"
$origin
Truth table100%2/2
A
A= $origin
Aresult
11
00
58  
59 return (
60 2709 ▶ $site,
Branch: 1 branch
BranchTrueFalseTotal
$origin =~ /::/ ? : 2521 188 2709
61 $origin =~ /::/ ? "$origin(): " : "$origin: ", # cargo-cult from Carp::Clan
62 );
63 };
64  
65 my $warn = sub {
66 75 ▶ my ($ln, @warn) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.1
67 75 ▶ @warn = "Warning: something's wrong" unless @warn;
Branch: 1 branch
BranchTrueFalseTotal
unless @warn 0 75 75
68  
69 # back-compat with Carp::Clan - a warning ending with \n does
70 # not include caller info
71 75 ▶ warn (
Branch: 1 branch
BranchTrueFalseTotal
$warn[-1] =~ /\n$/ ? : 9 66 75
72 @warn,
73 $warn[-1] =~ /\n$/ ? '' : " $ln\n"
74 );
75 308 };
76  
77 sub import {
78 5121 ▶ my (undef, $skip_pattern) = @_;
Subroutine import: called CC=2 SCAR=6.9
79 5121 my $into = caller;
80  
81 5121 ▶ $skip_pattern = $skip_pattern
Branch: 1 branch
BranchTrueFalseTotal
$skip_pattern ? : 616 4505 5121
82 ? qr/ ^ $into $ | $skip_pattern /x
83 : qr/ ^ $into $ /x
84 ;
85  
86 308 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 5121 *{"${into}::carp"} = sub {
89 42 ▶ $warn->(
Subroutine __ANON__: called CC=1 SCAR=0.0
90 __find_caller($skip_pattern, $into),
91 @_
92 );
93 5121 };
94  
95 5121 my $fired = {};
96 5121 *{"${into}::carp_once"} = sub {
97 13 ▶ return if $fired->{$_[0]};
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $$fired{$_[0]} 4 9 13
98 9 $fired->{$_[0]} = 1;
99  
100 9 $warn->(
101 __find_caller($skip_pattern, $into),
102 @_,
103 );
104 5121 };
105  
106 5121 my $seen;
107 5121 *{"${into}::carp_unique"} = sub {
108 36 ▶ my ($ln, $calling) = __find_caller($skip_pattern, $into);
Subroutine __ANON__: called CC=2 SCAR=6.9
109 36 my $msg = join ('', $calling, @_);
110  
111 # unique carping with a hidden caller makes no sense
112 36 $msg =~ s/\n+$//;
113  
114 36 ▶ return if $seen->{$ln}{$msg};
Branch: 1 branch
BranchTrueFalseTotal
if $seen->{$ln}{$msg} 12 24 36
115 24 $seen->{$ln}{$msg} = 1;
116  
117 24 $warn->(
118 $ln,
119 $msg,
120 );
121 5121 };
122 }
123  
124 sub unimport {
125 0 ▶ die (__PACKAGE__ . " does not implement unimport yet\n");
Subroutine unimport: not called CC=1 SCAR=6.9
126 }
127  
128 308 1;
129  
130 =head1 NAME
131  
132 DBIx::Class::Carp - Provides advanced Carp::Clan-like warning functions for DBIx::Class internals
133  
134 =head1 DESCRIPTION
135  
136 Documentation is lacking on purpose - this an experiment not yet fit for
137 mass consumption. If you use this do not count on any kind of stability,
138 in fact don't even count on this module's continuing existence (it has
139 been noindexed for a reason).
140  
141 In addition to the classic interface:
142  
143 use DBIx::Class::Carp '^DBIx::Class'
144  
145 this module also supports a class-data based way to specify the exclusion
146 regex. A message is only carped from a callsite that matches neither the
147 closed over string, nor the value of L</_skip_namespace_frames> as declared
148 on any callframe already skipped due to the same mechanism. This is to ensure
149 that intermediate callsites can declare their own additional skip-namespaces.
150  
151 =head1 CLASS ATTRIBUTES
152  
153 =head2 _skip_namespace_frames
154  
155 A classdata attribute holding the stringified regex matching callsites that
156 should be skipped by the carp methods below. An empty string C<q{}> is treated
157 like no setting/C<undef> (the distinction is necessary due to semantics of the
158 class data accessors provided by L<Class::Accessor::Grouped>)
159  
160 =head1 EXPORTED FUNCTIONS
161  
162 This module export the following 3 functions. Only warning related C<carp*>
163 is being handled here, for C<croak>-ing you must use
164 L<DBIx::Class::Schema/throw_exception> or L<DBIx::Class::Exception>.
165  
166 =head2 carp
167  
168 Carps message with the file/line of the first callsite not matching
169 L</_skip_namespace_frames> nor the closed-over arguments to
170 C<use DBIx::Class::Carp>.
171  
172 =head2 carp_unique
173  
174 Like L</carp> but warns once for every distinct callsite (subject to the
175 same ruleset as L</carp>).
176  
177 =head2 carp_once
178  
179 Like L</carp> but warns only once for the life of the perl interpreter
180 (regardless of callsite).
181  
182 =cut
« DBIx/Class/Storage/DBI/DB2.pm ↑ Summary DBIx/Class/_Util.pm »