blib/lib/Class/Method/Debug.pm

filter: Statementstmt 42.5% 23 / 54 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 53.8% 7 / 13 Podpod 100% 3 / 3 totaltotal 33.3% 33 / 99 CC 11 SCAR 28.1
CC
11
Cov
30%
__ANON__
42.0
__ANON__
20.0
__ANON__
12.0
CRAP 16.6
↑ Summary
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Class::Method::Debug;
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $Class::Method::Debug::VERSION = '1.101420';
8 }
9 # ABSTRACT: Trace who is calling accessors
10  
11 1 ▶use Class::Method::Modifiers qw(install_modifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Devel::StackTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 our %EXPORT_TAGS = (tracer => [qw/enable_scalar_tracer enable_hash_tracer/],);
16 1 our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] };
17  
18 0 ▶sub print_stacktrace {
Subroutine print_stacktrace: not called CC=1 SCAR=6.9
Pod documented
19 0 my ($accessor, $arg_string) = @_;
20 0 my $seen_modifiers = 0;
21 my $trace = Devel::StackTrace->new(
22 0 ▶ frame_filter => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
23 0 ▶ if ( !$seen_modifiers
Branch: 1 branch
BranchTrueFalseTotal
if (not $seen_modifiers and $_[0]{"caller"}[0] eq "Class::Method::Modifiers") 0 0 0
Condition0%0/3
not $seen_modifiers and $_[0]{"caller"}[0] eq "Class::Method::Modifiers"
!ll&&!rl&&r
000
MC/DC0%0/2
not $seen_modifiers and $_[0]{"caller"}[0] eq "Class::Method::Modifiers"
not $seen_modifiers $_[0]{"caller"}[0] eq "Class::Method::Modifiers"
Truth table0%0/3
not(A) and B
A= not $seen_modifiersB= $_[0]{"caller"}[0] eq "Class::Method::Modifiers"
ABresult
0X0
100
111
24 && $_[0]->{caller}[0] eq 'Class::Method::Modifiers') {
25 0 $seen_modifiers = 1;
26 }
27 0 return $seen_modifiers;
28 }
29 0 );
30 0 (my $subroutine = $trace->frame(0)->{subroutine}) =~
31 s/(.*::).*/$1$accessor/;
32 0 $trace->frame(1)->{subroutine} = $subroutine;
33 0 my $s = $trace->as_string;
34 0 my $indent = ' ' x 4;
35 0 $s =~ s/\n(?!$)/\n$indent/g;
36 0 $s =~ s/ (?=called at)/\n$indent$indent/g;
37 0 $s =~ s/Trace begun.*/TRACE ->$accessor($arg_string)/;
38 0 warn $s;
39 }
40  
41 0 ▶sub enable_scalar_tracer {
Subroutine enable_scalar_tracer: not called CC=1 SCAR=6.9
Pod documented
42 0 my ($accessor, $value) = @_;
43 0 my $pkg = caller();
44 install_modifier(
45 $pkg, 'before',
46 0 ▶ $accessor => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
47 0 ▶ return unless defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
48 0 ▶ return if defined($value) && $_[1] ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $_[1] ne $value 0 0 0
Condition0%0/3
defined $value and $_[1] ne $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and $_[1] ne $value
defined $value $_[1] ne $value
Truth table0%0/3
A and B
A= defined $valueB= $_[1] ne $value
ABresult
0X0
100
111
49 0 print_stacktrace($accessor, $_[1]);
50 }
51 0 );
52 }
53  
54 0 ▶sub enable_hash_tracer {
Subroutine enable_hash_tracer: not called CC=1 SCAR=6.9
Pod documented
55 0 my ($accessor, $key, $value) = @_;
56 0 my $pkg = caller();
57 install_modifier(
58 $pkg, 'before',
59 0 ▶ $accessor => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
60 0 my $self = shift;
61 0 ▶ return if @_ % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 == 1 0 0 0
62 0 my %h = @_;
63 0 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 0 0 0
64 0 ▶ return unless $h{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $h{$key} 0 0 0
65 0 ▶ return if defined($value) && $h{$key} ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and $h{$key} ne $value 0 0 0
Condition0%0/3
defined $value and $h{$key} ne $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and $h{$key} ne $value
defined $value $h{$key} ne $value
Truth table0%0/3
A and B
A= defined $valueB= $h{$key} ne $value
ABresult
0X0
100
111
66 0 print_stacktrace($accessor, "$key => $h{$key}");
67 } else {
68 0 print_stacktrace($accessor, '%values');
69 }
70 }
71 0 );
72 }
73 1 1;
74  
75  
76 __END__
↑ Summary