line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JIP::Debug; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1394
|
use base qw(Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
15
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
24
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
9
|
1
|
|
|
1
|
|
473
|
use Data::Dumper qw(Dumper); |
|
1
|
|
|
|
|
4855
|
|
|
1
|
|
|
|
|
54
|
|
10
|
1
|
|
|
1
|
|
6
|
use Fcntl qw(LOCK_EX LOCK_UN); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
11
|
1
|
|
|
1
|
|
5
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.999_002'; |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(to_debug to_debug_raw to_debug_empty); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $HANDLE = \*STDERR; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $MSG_FORMAT = qq{%s\n%s\n%s\n%s\n\n}; |
19
|
|
|
|
|
|
|
our $MSG_DELIMITER = q{-} x 80; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $DUMPER_INDENT = 1; |
22
|
|
|
|
|
|
|
our $DUMPER_DEEPCOPY = 1; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $COLOR = 'bright_green'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $MAYBE_COLORED = sub { $ARG[0] }; |
27
|
|
|
|
|
|
|
eval { |
28
|
|
|
|
|
|
|
require Term::ANSIColor; |
29
|
|
|
|
|
|
|
$MAYBE_COLORED = sub { Term::ANSIColor::colored($ARG[0], $COLOR); }; |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $MAKE_MSG_HEADER = sub { |
33
|
|
|
|
|
|
|
# $MAKE_MSG_HEADER=0, to_debug=1 |
34
|
|
|
|
|
|
|
my ($package, undef, $line) = caller(1); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# $MAKE_MSG_HEADER=0, to_debug=1, subroutine=2 |
37
|
|
|
|
|
|
|
my $subroutine = (caller(2))[3]; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$subroutine = _resolve_subroutine_name($subroutine); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $text = join q{, }, ( |
42
|
|
|
|
|
|
|
sprintf('package=%s', $package), |
43
|
|
|
|
|
|
|
(defined $subroutine ? sprintf('subroutine=%s', $subroutine) : ()), |
44
|
|
|
|
|
|
|
sprintf('line=%d', $line, ), |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
$text = qq{[$text]:}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $MAYBE_COLORED->($text); |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Supported on Perl 5.22+ |
52
|
|
|
|
|
|
|
eval { |
53
|
|
|
|
|
|
|
require Sub::Util; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if (my $set_subname = Sub::Util->can('set_subname')) { |
56
|
|
|
|
|
|
|
$set_subname->('MAYBE_COLORED', $MAYBE_COLORED); |
57
|
|
|
|
|
|
|
$set_subname->('MAKE_MSG_HEADER', $MAKE_MSG_HEADER); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub to_debug { |
63
|
1
|
|
|
1
|
0
|
2901
|
my $msg_body = do { |
64
|
1
|
|
|
|
|
4
|
local $Data::Dumper::Indent = $DUMPER_INDENT; |
65
|
1
|
|
|
|
|
2
|
local $Data::Dumper::Deepcopy = $DUMPER_DEEPCOPY; |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
9
|
Dumper(\@_); |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
1
|
50
|
|
|
|
86
|
my $msg_delimiter = defined $MSG_DELIMITER ? $MSG_DELIMITER : q{}; |
71
|
1
|
|
|
|
|
4
|
$msg_delimiter = $MAYBE_COLORED->($msg_delimiter); |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
6
|
my $msg = sprintf $MSG_FORMAT, |
74
|
|
|
|
|
|
|
$msg_delimiter, |
75
|
|
|
|
|
|
|
$MAKE_MSG_HEADER->(), |
76
|
|
|
|
|
|
|
$msg_delimiter, |
77
|
|
|
|
|
|
|
$msg_body; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
8
|
_send_to_output($msg); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub to_debug_raw { |
83
|
1
|
|
|
1
|
0
|
2468
|
my $msg_text = shift; |
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
|
|
4
|
my $msg_delimiter = defined $MSG_DELIMITER ? $MSG_DELIMITER : q{}; |
86
|
1
|
|
|
|
|
3
|
$msg_delimiter = $MAYBE_COLORED->($msg_delimiter); |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
6
|
my $msg = sprintf $MSG_FORMAT, |
89
|
|
|
|
|
|
|
$msg_delimiter, |
90
|
|
|
|
|
|
|
$MAKE_MSG_HEADER->(), |
91
|
|
|
|
|
|
|
$msg_delimiter, |
92
|
|
|
|
|
|
|
$msg_text; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
8
|
_send_to_output($msg); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub to_debug_empty { |
98
|
1
|
50
|
|
1
|
0
|
2323
|
my $msg_delimiter = defined $MSG_DELIMITER ? $MSG_DELIMITER : q{}; |
99
|
1
|
|
|
|
|
3
|
$msg_delimiter = $MAYBE_COLORED->($msg_delimiter); |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
17
|
my $msg = sprintf qq{%s\n%s%s}, |
102
|
|
|
|
|
|
|
$msg_delimiter, |
103
|
|
|
|
|
|
|
$msg_delimiter, |
104
|
|
|
|
|
|
|
qq{\n} x 20; |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
|
|
3
|
_send_to_output($msg); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _send_to_output { |
110
|
5
|
|
|
5
|
|
5245
|
my $msg = shift; |
111
|
|
|
|
|
|
|
|
112
|
5
|
50
|
|
|
|
16
|
return unless $HANDLE; |
113
|
|
|
|
|
|
|
|
114
|
5
|
|
|
|
|
22
|
flock $HANDLE, LOCK_EX; |
115
|
5
|
50
|
|
|
|
23
|
$HANDLE->print($msg) or croak(sprintf q{Can't write to output: %s}, $OS_ERROR); |
116
|
5
|
|
|
|
|
161
|
flock $HANDLE, LOCK_UN; |
117
|
|
|
|
|
|
|
|
118
|
5
|
|
|
|
|
25
|
return 1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _resolve_subroutine_name { |
122
|
5
|
|
|
5
|
|
8300
|
my $subroutine = shift; |
123
|
|
|
|
|
|
|
|
124
|
5
|
100
|
|
|
|
23
|
return unless defined $subroutine; |
125
|
|
|
|
|
|
|
|
126
|
3
|
|
|
|
|
10
|
my ($subroutine_name) = $subroutine =~ m{::(\w+)$}x; |
127
|
|
|
|
|
|
|
|
128
|
3
|
|
|
|
|
12
|
return $subroutine_name; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |