IMP/Debug.pm

filter: Statementstmt 40.4% 19 / 47 Branchbran 15.6% 5 / 32 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 31.6% 31 / 98 CC 20 SCAR 41.0
CC
20
Cov
28%
debug
113.4
import
25.3
set_debug
20.0
CRAP 60.3
« IMP/Filter.pm ↑ Summary IMP/Example/IRCShout.pm »
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Net::IMP::Debug;
4  
5 8 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 our @EXPORT = qw($DEBUG debug);
7 8 our @EXPORT_OK = qw($DEBUG_RX set_debug);
8  
9 8 our $DEBUG = 0; # is debugging enabled at all
10 8 our $DEBUG_RX = undef; # debug only packages matching given regex
11 8 my $DEBUG_SUB = undef; # external debug function to call instead of internal
12  
13 # import exported stuff, special case var => \$debug, func => \$code
14 sub import {
15 # on default import go immediately to Exporter
16 39 ▶ goto &Exporter::import if @_ == 1;
Subroutine import: called CC=7 SCAR=32.3
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 31 8 39
17  
18 # extract var => \$var from import and alias it to DEBUG
19 # extract sub => \$code and set $DEBUG_SUB
20 8 ▶ for(my $i=1;$i<@_-1;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_ - 1) 0 8 8
21 0 ▶ if ( $_[$i] eq 'var' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_[$i] eq 'var') { } 0 0 0
elsif ($_[$i] eq 'rxvar') { } 0 0 0
elsif ($_[$i] eq 'sub') { } 0 0 0
22 0 *DEBUG = $_[$i+1];
23 0 splice(@_,$i,2);
24 0 $i-=2;
25 } elsif ( $_[$i] eq 'rxvar' ) {
26 0 *DEBUG_RX = $_[$i+1];
27 0 splice(@_,$i,2);
28 0 $i-=2;
29 } elsif ( $_[$i] eq 'sub' ) {
30 0 $DEBUG_SUB = $_[$i+1];
31 0 splice(@_,$i,2);
32 0 $i-=2;
33 }
34 }
35  
36 # call Exporter only if we have remaining args, because we don't
37 # want to trigger the default export if user gave args (e.g. var,sub)
38 8 ▶ goto &Exporter::import if @_>1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 8 0 8
39 }
40  
41 # set debugging properties
42 sub set_debug {
43 0 ▶ $DEBUG = $_[1] if @_>1 && defined $_[1];
Subroutine set_debug: not called CC=4 SCAR=30.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and defined $_[1] 0 0 0
Condition0%0/3
@_ > 1 and defined $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 1 and defined $_[1]
@_ > 1 defined $_[1]
Truth table0%0/3
A and B
A= @_ > 1B= defined $_[1]
ABresult
0X0
100
111
44 0 ▶ $DEBUG_RX = $_[2] if @_>2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
45 }
46  
47 # print out debug message or forward to external debug func
48 sub debug {
49 293 ▶ $DEBUG or return;
Subroutine debug: called CC=11 SCAR=47.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$Net::IMP::Debug::DEBUG or return 293 0 293
50 0 my $msg = shift;
51 0 ▶ $msg = sprintf($msg,@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
52 0 ▶ if ( $DEBUG_SUB ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DEBUG_SUB) 0 0 0
53 0 @_ = ($msg);
54 # goto foreign debug sub
55 # if DEBUG_RX is set this ill be done later
56 0 ▶ goto &$DEBUG_SUB if ! $DEBUG_RX;
Branch: 1 branch
BranchTrueFalseTotal
unless $Net::IMP::Debug::DEBUG_RX 0 0 0
57 }
58  
59 0 my ($pkg,$line) = (caller(0))[0,2];
60 0 ▶ if ( $DEBUG_RX ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::IMP::Debug::DEBUG_RX) 0 0 0
61 0 ▶ $pkg ||= 'main';
Condition0%0/2
$pkg ||= "main"
l!l
00
MC/DC0%0/1
$pkg ||= "main"
$pkg
Truth table0%0/2
A
A= $pkg
Aresult
11
00
62 # does not match wanted package
63 0 ▶ return if $pkg !~ $DEBUG_RX;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /$Net::IMP::Debug::DEBUG_RX/ 0 0 0
64 # goto foreign debug sub
65 0 ▶ goto &$DEBUG_SUB if $DEBUG_SUB;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG_SUB 0 0 0
66 }
67  
68 0 my $sub = (caller(1))[3];
69 0 ▶ $sub =~s{^main::}{} if $sub;
Branch: 1 branch
BranchTrueFalseTotal
if $sub 0 0 0
70 0 ▶ $sub ||= 'Main';
Condition0%0/2
$sub ||= "Main"
l!l
00
MC/DC0%0/1
$sub ||= "Main"
$sub
Truth table0%0/2
A
A= $sub
Aresult
11
00
71 0 $msg = "${sub}[$line]: ".$msg;
72  
73 0 $msg =~s{^}{DEBUG: }mg;
74 0 print STDERR $msg,"\n";
75 }
76  
77  
78 8 1;
79 __END__
« IMP/Filter.pm ↑ Summary IMP/Example/IRCShout.pm »