| 1 | package LEOCHARRE::DEBUG2; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | #use Exporter; | ||||||||||||||||||||||||||||
| 4 | #use vars qw(@ISA @EXPORT $VERSION @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | #@ISA = qw(Exporter); | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | #@EXPORT_OK = qw( &DEBUG $DEBUG &debug &_debug_test ); | ||||||||||||||||||||||||||||
| 9 | #@EXPORT = qw($DEBUG); | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | #$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)/g; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | $LEOCHARRE::DEBUG2::DEBUG_LEVEL = 1; | |||||||||||||||||||||||||||
| 17 | 1 | $LEOCHARRE::DEBUG2::DEBUG = 0; | |||||||||||||||||||||||||||
| 18 | 1 | $LEOCHARRE::DEBUG2::_LAST_DEBUG_HAD_NEWLINE=1; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 13 | ▶ | sub DEBUG { | ||||||||||||||||||||||||||
|
Subroutine
DEBUG: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 13 | ▶ | my $val = ref $_[0] ? $_[1] : $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 13 | ▶ | $LEOCHARRE::DEBUG2::DEBUG = $val if defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | =for TOO FANCY | ||||||||||||||||||||||||||||
| 24 | my $val = shift; | ||||||||||||||||||||||||||||
| 25 | if (ref $val){ | ||||||||||||||||||||||||||||
| 26 | $val = shift; | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | if (defined $val){ | ||||||||||||||||||||||||||||
| 29 | $LEOCHARRE::DEBUG2::DEBUG = $val; | ||||||||||||||||||||||||||||
| 30 | printf STDERR" set $val, %s\n", ref $val; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | 13 | return $LEOCHARRE::DEBUG2::DEBUG; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 6 | ▶ | sub debug { | ||||||||||||||||||||||||||
|
Subroutine
debug: called CC=8 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | # my $val = shift; $val = shift if ref $val; | ||||||||||||||||||||||||||||
| 39 | 6 | ▶ | my $val = ref $_[0] ? $_[1] : $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 6 | ▶ | DEBUG or return 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | ▶ | if ( !$LEOCHARRE::DEBUG2::DEBUG_LEVEL ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $val=~/\n$/; | |||||||||||||||||||||||||||
| 45 | 0 | print STDERR " $val\n"; | |||||||||||||||||||||||||||
| 46 | 0 | return 1; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | my $sub = (caller(1))[3]; | |||||||||||||||||||||||||||
| 52 | # if used in a script, caller wont be there | ||||||||||||||||||||||||||||
| 53 | 4 | ▶ | $sub ||= 'main'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$sub ||= "main"
MC/DC0%0/1
$sub ||= "main"
$sub
Truth table50%1/2
A
A= $sub
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 4 | ▶ | if ($LEOCHARRE::DEBUG2::DEBUG_LEVEL == 1){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 4 | $sub=~s/^.*:://; # just want last part | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | ▶ | if( $LEOCHARRE::DEBUG2::_LAST_DEBUG_HAD_NEWLINE ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 4 | print STDERR " $sub(),"; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | print STDERR " $val"; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 4 | ▶ | $LEOCHARRE::DEBUG2::_LAST_DEBUG_HAD_NEWLINE = ( $val=~/\n$/ ? 1 : 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 4 | return 1; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 6 | ▶ | sub _debug_test { | ||||||||||||||||||||||||||
|
Subroutine
_debug_test: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 74 | 6 | ▶ | my $val = ref $_[0] ? $_[1] : $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 6 | ▶ | $val=~s/\s+$// if defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 6 | my $callerpkg = caller; | |||||||||||||||||||||||||||
| 77 | 6 | my $sub = (caller(1))[3]; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 6 | printf STDERR " package is %s, call pkg is $callerpkg, callspace %s [$val]\n",__PACKAGE__,$sub; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 6 | return 1; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 85 | ## find out who is calling us | ||||||||||||||||||||||||||||
| 86 | 1 | my $pkg = caller; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | ## while strict doesn't deal with globs, it still | ||||||||||||||||||||||||||||
| 89 | ## catches symbolic de/referencing | ||||||||||||||||||||||||||||
| 90 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | ## iterate through all the globs in the symbol table | ||||||||||||||||||||||||||||
| 93 | 1 | foreach my $glob (keys %LEOCHARRE::DEBUG2::) { | |||||||||||||||||||||||||||
| 94 | ## skip anything without a subroutine and 'import' | ||||||||||||||||||||||||||||
| 95 | 7 | next if not defined *{$LEOCHARRE::DEBUG2::{$glob}}{CODE} | |||||||||||||||||||||||||||
| 96 | 7 | ▶ | or $glob eq 'import'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined *{$LEOCHARRE::DEBUG2::{$glob};}{"CODE"} or $glob eq "import"
MC/DC100%2/2
not defined *{$LEOCHARRE::DEBUG2::{$glob};}{"CODE"} or $glob eq "import"
not defined *{$LEOCHARRE::DEBUG2::{$glob};}{"CODE"}
$glob eq "import"
Truth table100%3/3
not(A) or B
A= not defined *{$LEOCHARRE::DEBUG2::{$glob};}{"CODE"}B= $glob eq "import"
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | ## assign subroutine into caller's package | ||||||||||||||||||||||||||||
| 99 | 3 | *{$pkg . "::$glob"} = \&{"LEOCHARRE::DEBUG2::$glob"}; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # ABUSE CALLING PACKAGE, these are scalars we want | ||||||||||||||||||||||||||||
| 103 | 1 | for (qw(DEBUG _LAST_DEBUG_HAD_NEWLINE DEBUG_LEVEL)){ | |||||||||||||||||||||||||||
| 104 | 3 | my $glob = $_; | |||||||||||||||||||||||||||
| 105 | 3 | *{$pkg . "::$glob"} = \${"LEOCHARRE::DEBUG2::$glob"}; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 DEBUG_LEVEL | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | Just message and newline: | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | $MYMOD::DEBUG_LEVEL = 0; | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Show calling sub (default): | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | $MYMOD::DEBUG_LEVEL = 1; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | Show calling full name: | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | $MYMOD::DEBUG_LEVEL = 2; | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | Show tons of garble: | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | $MYMOD::DEBUG_LEVEL = 3; | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | 1; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||