TrackSIG.pm

filter: Statementstmt 69.6% 39 / 56 Branchbran 37.5% 6 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 100% 2 / 2 totaltotal 64.7% 55 / 85 CC 11 SCAR 19.9
CC
11
Cov
62%
dump_all_sources
20.0
get_source
12.0
_report
5.1
CRAP 7.3
« TrackGlobalScalar.pm ↑ Summary
1 package Devel::TrackSIG;
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 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶eval "use Carp::Heavy;";
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 require Tie::Hash;
7 1 our @ISA = qw(Tie::ExtraHash);
8  
9 1 our $VERSION = '0.04';
10  
11 1 tie %main::SIG => __PACKAGE__;
12  
13 1 our %opt = (
14 track_source => 1,
15 report_write_access => 0,
16 );
17  
18 1 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
19 1 my $class = shift;
20 1 my %args = @_;
21  
22 1 $opt{$_} = $args{$_} for keys %args;
23 }
24  
25  
26 14 ▶sub DELETE {
Subroutine DELETE: called CC=1 SCAR=0.0
27 14 _report($_[0], $_[1], 'DELETE');
28 14 return delete $_[0]->[0]->{$_[1]};
29 }
30  
31 11 ▶sub STORE {
Subroutine STORE: called CC=1 SCAR=0.0
32 11 _report($_[0], $_[1], 'STORE');
33 11 return $_[0]->[0]->{$_[1]} = $_[2];
34 }
35  
36 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
37 0 _report($_[0], '', 'CLEAR');
38 0 %{$_[0]->[0]} = ();
39 }
40  
41  
42 25 ▶sub _report {
Subroutine _report: called CC=5 SCAR=16.2
43 25 my $obj = shift;
44 25 my $key = shift;
45 25 my $action = shift;
46  
47
48 25 ▶ push @$obj, {} if @$obj < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$obj < 2 1 24 25
49  
50 25 my $sources = $obj->[1];
51  
52 25 my $msg = do {
53 25 my $i;
54 my @stack;
55 25 ▶ while ( my @caller = caller $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@caller) = caller $i++) 412 25 437
56 412 push @stack, sprintf ' %s::%s called at %s line %s', @caller[0,3,1,2];
57 }
58 25 "${action}ing signal handler '$key' at\n" . join("\n", @stack );
59 };
60  
61 25 ▶ if ($opt{track_source}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::TrackSIG::opt{"track_source"}) 25 0 25
62 25 $sources->{$key} = $msg;
63 }
64 25 ▶ if ($opt{report_write_access}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::TrackSIG::opt{"report_write_access"}) 0 25 25
65 0 print STDERR $msg . "\n";
66 }
67 }
68  
69 0 ▶sub get_source {
Subroutine get_source: not called CC=3 SCAR=24.8
Pod documented
70 0 my $self = shift;
71 0 my $key = shift;
72 print STDERR "Source tracking not enabled. Pass the track_source => 1 option when loading TrackSIG to enable\n"
73 0 ▶ if not $opt{track_source};
Branch: 1 branch
BranchTrueFalseTotal
unless $Devel::TrackSIG::opt{"track_source"} 0 0 0
74 0 ▶ return '' if not @{$self} > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self;} > 1 0 0 0
75 0 return $self->[1]->{$key};
76 }
77  
78 0 ▶sub dump_all_sources {
Subroutine dump_all_sources: not called CC=4 SCAR=30.0
Pod documented
79 0 my $self = shift;
80 print STDERR "Source tracking not enabled. Pass the track_source => 1 option when loading TrackSIG to enable\n"
81 0 ▶ if not $opt{track_source};
Branch: 1 branch
BranchTrueFalseTotal
unless $Devel::TrackSIG::opt{"track_source"} 0 0 0
82 0 ▶ return if not @{$self} > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self;} > 1 0 0 0
83 0 my $sources = $self->[1];
84 0 foreach my $key (keys %$sources) {
85 0 print STDERR "\$SIG{$key} was last set at:\n" . $sources->{$key} . "\n\n";
86 }
87 }
88  
89 1 1;
90  
91 __END__
« TrackGlobalScalar.pm ↑ Summary