line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::ForPerl; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Make sure we have version info for this module |
4
|
|
|
|
|
|
|
# Be strict from now on |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.02'; |
7
|
1
|
|
|
1
|
|
592
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
139
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# The logging dispatcher that should be used |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $DISPATCHER; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Old settings of standard Perl logging mechanisms |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $WARN; |
16
|
|
|
|
|
|
|
my $DIE; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# At compile time |
19
|
|
|
|
|
|
|
# Save current __WARN__ setting |
20
|
|
|
|
|
|
|
# Replace it with a sub that |
21
|
|
|
|
|
|
|
# Dispatches a warning message if there is a dispatcher |
22
|
|
|
|
|
|
|
# Executes the standard system warn() or whatever was there before |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
BEGIN { |
25
|
1
|
|
|
1
|
|
4
|
$WARN = $SIG{__WARN__}; |
26
|
|
|
|
|
|
|
$SIG{__WARN__} = sub { |
27
|
1
|
50
|
|
|
|
765
|
$DISPATCHER->warning( $_[0] ) if $DISPATCHER; |
28
|
1
|
50
|
|
|
|
17
|
$WARN ? $WARN->( $_[0] ) : CORE::warn( $_[0] ); |
29
|
1
|
|
|
|
|
5
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Save current __DIE__ setting |
32
|
|
|
|
|
|
|
# Replace it with a sub that |
33
|
|
|
|
|
|
|
# Dispatches an error message if there is a dispatcher |
34
|
|
|
|
|
|
|
# Executes the standard system die() or whatever was there before |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
3
|
$DIE = $SIG{__DIE__}; |
37
|
|
|
|
|
|
|
$SIG{__DIE__} = sub { |
38
|
0
|
0
|
|
|
|
0
|
$DISPATCHER->error( $_[0] ) if $DISPATCHER; |
39
|
0
|
0
|
|
|
|
0
|
$DIE ? $DIE->( $_[0] ) : CORE::die( $_[0] ); |
40
|
1
|
|
|
|
|
3
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Make sure we won't be listed ourselves by Carp:: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$Carp::Internal{$_} = 1 |
45
|
1
|
|
|
|
|
90
|
foreach 'Log::Dispatch','Log::Dispatch::Output',__PACKAGE__; |
46
|
|
|
|
|
|
|
} #BEGIN |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Satisfy require |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Class methods |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
57
|
|
|
|
|
|
|
# dispatcher |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# Set and/or return the current dispatcher |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# IN: 1 class (ignored) |
62
|
|
|
|
|
|
|
# 2 new dispatcher (optional) |
63
|
|
|
|
|
|
|
# OUT: 1 current dispatcher |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub dispatcher { |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Set the new dispatcher if there is any |
68
|
|
|
|
|
|
|
# Return the current dispatcher |
69
|
|
|
|
|
|
|
|
70
|
1
|
50
|
|
1
|
0
|
10
|
$DISPATCHER = $_[1] if @_ > 1; |
71
|
1
|
|
|
|
|
7
|
$DISPATCHER; |
72
|
|
|
|
|
|
|
} #dispatcher |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Perl standard features |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
79
|
|
|
|
|
|
|
# import |
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
# Called whenever a -use- is done. |
82
|
|
|
|
|
|
|
# |
83
|
|
|
|
|
|
|
# IN: 1 class (ignored) |
84
|
|
|
|
|
|
|
# 2 new dispatcher (optional) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
*import = \&dispatcher; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
89
|
|
|
|
|
|
|
# unimport |
90
|
|
|
|
|
|
|
# |
91
|
|
|
|
|
|
|
# Called whenever a -use- is done. |
92
|
|
|
|
|
|
|
# |
93
|
|
|
|
|
|
|
# IN: 1 class (ignored) |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
0
|
|
|
sub unimport { import( undef ) } #unimport |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#--------------------------------------------------------------------------- |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |