Pluggable/Plugin/BreakOnTestNumber.pm

filter: Statementstmt 52.7% 29 / 55 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 69.2% 9 / 13 Podpod 100% 2 / 2 totaltotal 44.9% 40 / 89 SCAR 32.7
CC
9
Cov
40%
watchfunction
42.7
__ANON__
6.0
__ANON__
3.4
CRAP 26.3
↑ Summary Pluggable.pm »
1 package DB::Pluggable::Plugin::BreakOnTestNumber;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Role::Basic;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Hook::LexWrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Test::Builder; # preload so we can "safely" overwrite lock()
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 with qw(
9 DB::Pluggable::Role::Initializer
10 DB::Pluggable::Role::WatchFunction
11 );
12 2 our $VERSION = '1.112001';
13  
14 sub initialize {
15 0 ▶ @DB::testbreak = ();
Subroutine initialize: not called CC=1 SCAR=3.3
Pod documented
16 our $cmd_b_wrapper = wrap 'DB::cmd_b', pre => sub {
17 0 ▶ return unless $_[1] =~ /\s*#\s*(\d+(?:\s*,\s*\d+)*)$/;
Subroutine __ANON__: not called CC=2 SCAR=12.2
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] =~ /\s*#\s*(\d+(?:\s*,\s*\d+)*)$/ 0 0 0
18 0 my %seen;
19 0 @DB::testbreak = grep { !$seen{$_}++ }
20 0 sort { $a <=> $b } (split(/\s*,\s*/, $1), @DB::testbreak);
21  
22 # Making use of the fact that Test::Builder calls lock() each
23 # time before accessing {Curr_Test} is a hack, but directly
24 # enabling the watchfunction here would mean everything slows
25 # down to a crawl. It also means that this plugin won't work
26 # with threads. And let's hope Test::Builder continues to use
27 # lock()... Not nice, but it works and is fast.
28 2 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 *Test::Builder::lock = sub {
31 0 ▶ return if (caller(1))[3] eq 'Test::Builder::current_test';
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if (&CORE::GLOBAL::caller(1))[3] eq "Test::Builder::current_test" 0 0 0
32  
33 # Enable watchfunction
34 0 $DB::trace |= 4;
35 0 };
36  
37 # short-circuit (i.e., don't call the original debugger function)
38 # if a plugin has handled it
39 0 $_[-1] = 1;
40 0 return;
41 }
42 0 }
43  
44 sub watchfunction {
45 0 ▶ my $self = shift;
Subroutine watchfunction: not called CC=7 SCAR=37.5
Pod documented
46  
47 # disable the watchfunction until it is next enabled by lock()
48 0 $DB::trace &= ~4;
49 0 ▶ return unless @DB::testbreak;
Branch: 1 branch
BranchTrueFalseTotal
unless @DB::testbreak 0 0 0
50 0 my $next = Test::Builder->new->current_test + 1;
51 0 ▶ if ($next >= $DB::testbreak[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next >= $DB::testbreak[0]) 0 0 0
52 0 ▶ shift @DB::testbreak while @DB::testbreak && $next >= $DB::testbreak[0];
Branch: 1 branch
BranchTrueFalseTotal
@DB::testbreak and $next >= $DB::testbreak[0] and do { shift @DB::testbreak } 0 0 0
Condition0%0/3
@DB::testbreak and $next >= $DB::testbreak[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@DB::testbreak and $next >= $DB::testbreak[0]
@DB::testbreak $next >= $DB::testbreak[0]
Truth table0%0/3
A and B
A= @DB::testbreakB= $next >= $DB::testbreak[0]
ABresult
0X0
100
111
53 0 my $depth = 1;
54 0 while (1) {
55 0 my $package = (caller $depth)[0];
56 0 ▶ last unless defined $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 0 0 0
57 0 ▶ last unless $package =~ /^(DB(::|$)|Test::)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $package =~ /^(DB(::|$)|Test::)/ 0 0 0
58 0 $depth++;
59 }
60 2 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 0 $DB::stack[ -$depth + 1 ] = 1;
62 }
63 0 return;
64 }
65 2 1;
66  
67 =pod
68  
69 =for stopwords watchfunction
70  
71 =for test_synopsis 1;
72 __END__
↑ Summary Pluggable.pm »