blib/lib/Log/Trace.pm

filter: Statementstmt 82.8% 261 / 315 Branchbran 67.5% 104 / 154 Conditioncond 52.3% 34 / 65 MC/DCmcdc 31.7% 13 / 41 Subroutinesub 81.8% 45 / 55 Podpod 66.6% 2 / 3 totaltotal 72.5% 459 / 633 CC 107 SCAR 21.7
CC
107
Cov
75%
__ANON__
22.5
_import
21.3
_wrap_functions
14.3
CRAP 8.8
↑ Summary
1 package Log::Trace;
2 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 #Hires times if available
5 eval
6 12 {
7 12 require Time::HiRes;
8 };
9  
10 12 ▶use vars qw($VERSION @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 @EXPORT = qw(TRACE_HERE TRACEF); # TRACE, DUMP
12 12 ▶use strict qw(subs vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use Fcntl ':flock';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 12 $VERSION = sprintf"%d.%03d", q$Revision: 1.70 $ =~ /: (\d+)\.(\d+)/;
16  
17 #################################################
18 # Importing
19 #################################################
20  
21 0 ▶*{"_debug"} = 0 ? sub { warn __PACKAGE__ . " @_\n" } : sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.4
Subroutine __ANON__: called CC=1 SCAR=0.4
22  
23 #Import into calling packages
24 sub import
25 36 ▶{
Subroutine import: called CC=2 SCAR=6.9
26 36 my $pkg = shift;
27 36 my $callpkg = caller(0);
28 36 my @args = @_;
29 36 ▶ if (ref $args[1] eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[1] eq "HASH") 5 31 36
30 {
31 # e.g. 'import (print => {Verbose => 1})
32 5 @args = ($args[0], undef, @args[1..$#args])
33 }
34 36 $pkg->_import($callpkg, @args);
35 }
36  
37 sub deep_import # deprecated. use 'import Log::Trace {Deep => 1, ...} ...'
38 0 ▶{
Subroutine deep_import: not called CC=3 SCAR=24.8
Pod undocumented
39 0 my $pkg = shift;
40 0 my $callpkg = caller(0);
41 0 ▶ my $params = ref $_[0] ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
42 0 $params->{Deep} = 1;
43 0 ▶ push @_, undef if @_ == 1; # deep_import 'print';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
44 0 $pkg->_import($callpkg, @_, $params);
45 }
46  
47  
48 sub TRACEF
49 3 ▶{
Subroutine TRACEF: called CC=2 SCAR=6.9
Pod documented
50 3 my $callpkg = caller();
51 3 my $trace = *{"$callpkg\::TRACE"};
52 3 ▶ my $params = ref $_[0] ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 2 1 3
53 3 my $format = shift;
54 3 $trace->($params, sprintf($format, @_));
55 }
56  
57  
58 sub TRACE_HERE
59 5 ▶{
Subroutine TRACE_HERE: called CC=5 SCAR=16.1
Pod documented
60 5 my $callpkg = caller();
61 5 ▶ my $params = ref $_[0] ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 2 3 5
62 # see 'perldoc -f caller'
63 # calling caller() from the DB package stores subroutine args in @DB::args
64 5 my @caller;
65 5 do {
66 package DB;
67 5 @caller = caller(1);
68 5 ▶ @caller = caller(0) unless $caller[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $caller[0] 3 2 5
69 };
70 5 my $sub = $caller[3]; # the subroutine that called TRACE_HERE
71 5 my ($file, $line) = (caller(0))[1,2]; # the location of the TRACE_HERE
72 5 my $trace = *{"$callpkg\::TRACE"};
73 5 ▶ shift @DB::args if @DB::args && "$DB::args[0]" eq "$params";
Branch: 1 branch
BranchTrueFalseTotal
if @DB::args and "$DB::args[0]" eq "$params" 2 3 5
Condition100%3/3
@DB::args and "$DB::args[0]" eq "$params"
!ll&&!rl&&r
212
MC/DC100%2/2
@DB::args and "$DB::args[0]" eq "$params"
@DB::args "$DB::args[0]" eq "$params"
Truth table100%3/3
A and B
A= @DB::argsB= "$DB::args[0]" eq "$params"
ABresult
0X0
100
111
74 5 $trace->($params, "In $sub(".join(",", @DB::args).") - line $line of $file");
75 }
76  
77  
78 #################################################
79 # Exporting
80 #################################################
81  
82 sub _import
83 37 ▶{
Subroutine _import: called CC=18 SCAR=30.6
84 37 my $pkg = shift;
85 37 my (@packages) = shift;
86 37 my ($target, $arg, $params) = @_;
87 37 ▶ $target = '' unless defined $target;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target 0 37 37
88  
89 37 ▶ if ($params->{Deep}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"Deep"}) 4 33 37
90 # extend the package list
91 4 push @packages, _deep_import_packages($params->{Everywhere});
92 }
93 37 ▶ if ($params->{AutoImport}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"AutoImport"}) 2 35 37
94 # override the default require() to catch new modules being loaded
95 2 _install_require($pkg, $params, $target, $arg)
96 }
97  
98 # lookup: valid target > TRACE sub. These are also closures around '$arg'
99 my %import_targets = (
100 5 ▶ 'print' => sub {_log_to_fh($arg, _log_normal(@_))},
Subroutine __ANON__: called CC=1 SCAR=0.0
101 1 ▶ 'print-verbose' => sub {_log_to_fh($arg, _log_verbose(@_))},
Subroutine __ANON__: called CC=1 SCAR=0.0
102 1 ▶ 'print-debug' => sub {_log_to_fh($arg, _log_debug(@_))},
Subroutine __ANON__: called CC=1 SCAR=0.0
103 3 ▶ 'warn' => sub {warn _log_normal(@_)},
Subroutine __ANON__: called CC=1 SCAR=0.0
104 1 ▶ 'warn-verbose' => sub {warn _log_verbose(@_)},
Subroutine __ANON__: called CC=1 SCAR=0.0
105 1 ▶ 'warn-debug' => sub {warn _log_debug(@_)},
Subroutine __ANON__: called CC=1 SCAR=0.0
106 3 ▶ 'buffer' => sub {$$arg .= _log_normal(@_)},
Subroutine __ANON__: called CC=1 SCAR=0.0
107 1 ▶ 'buffer-verbose' => sub {$$arg .= _log_verbose(@_)},
Subroutine __ANON__: called CC=1 SCAR=0.0
108 1 ▶ 'buffer-debug' => sub {$$arg .= _log_debug(@_)},
Subroutine __ANON__: called CC=1 SCAR=0.0
109 3 ▶ 'file' => sub {_log_to_file($arg, _log_normal(@_))},
Subroutine __ANON__: called CC=1 SCAR=0.0
110 1 ▶ 'file-verbose' => sub {_log_to_file($arg, _log_verbose(@_))},
Subroutine __ANON__: called CC=1 SCAR=0.0
111 1 ▶ 'file-debug' => sub {_log_to_file($arg, _log_debug(@_))},
Subroutine __ANON__: called CC=1 SCAR=0.0
112 0 ▶ 'log' => sub {_log_to_file($arg, _log_debug(@_))},
Subroutine __ANON__: not called CC=1 SCAR=6.9
113 0 ▶ 'syslog' => sub {_log_to_syslog($arg, _log_normal(@_))},
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 0 ▶ 'syslog-verbose' => sub {_log_to_syslog($arg, _log_verbose(@_))},
Subroutine __ANON__: not called CC=1 SCAR=6.9
115 0 ▶ 'syslog-debug' => sub {_log_to_syslog($arg, _log_debug(@_))},
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 37 'custom' => $arg,
117 );
118  
119 37 my $suffix = '';
120 37 ▶ $params->{Verbose} = 0 unless defined $params->{Verbose};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"Verbose"} 24 13 37
121 37 ▶ if ($params->{Verbose} == 1)
Branch: 2 branches
BranchTrueFalseTotal
if ($params->{'Verbose'} == 1) { } 4 33 37
elsif ($params->{'Verbose'} == 2) { } 4 29 33
122 {
123 4 $suffix = '-verbose';
124 }
125 elsif ($params->{Verbose} == 2)
126 {
127 4 $suffix = '-debug';
128 }
129 37 ▶ $target = $import_targets{$target.$suffix} ? $target.$suffix : $target;
Branch: 1 branch
BranchTrueFalseTotal
$import_targets{$target . $suffix} ? : 37 0 37
130 37 _debug("Initialising target: $target");
131  
132 37 foreach my $export_to (@packages) {
133 # Check whether to export functions to the package
134 380 ▶ my $match = defined $params->{Match} ? $params->{Match} : '.';
Branch: 1 branch
BranchTrueFalseTotal
defined $params->{'Match'} ? : 314 66 380
135 380 ▶ next unless $export_to =~ /$match/;
Branch: 1 branch
BranchTrueFalseTotal
unless $export_to =~ /$match/ 311 69 380
136 69 my %exclude;
137 69 ▶ if (my $excl = $params->{Exclude}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $excl = $params->{"Exclude"}) 0 69 69
138 0 ▶ %exclude = map {$_ => 1} ref $excl eq 'ARRAY' ? @$excl : $excl;
Branch: 1 branch
BranchTrueFalseTotal
ref $excl eq 'ARRAY' ? : 0 0 0
139 }
140 69 $exclude{+__PACKAGE__} = 1; # exclude ourselves
141 69 ▶ next if $exclude{$export_to};
Branch: 1 branch
BranchTrueFalseTotal
if $exclude{$export_to} 0 69 69
142  
143 69 _debug("Exporting target:$target to $export_to");
144 # set up the TRACE/DUMP functions
145 69 my ($trace, $dump);
146 69 ▶ if ($target && $import_targets{$target})
Branch: 1 branch
BranchTrueFalseTotal
if ($target and $import_targets{$target}) { } 69 0 69
Condition33%1/3
$target and $import_targets{$target}
!ll&&!rl&&r
0069
MC/DC0%0/2
$target and $import_targets{$target}
$target $import_targets{$target}
Truth table33%1/3
A and B
A= $targetB= $import_targets{$target}
ABresult
0X0
100
111
147 {
148 69 $trace = _trace_maker($export_to, $params, $import_targets{$target});
149 69 $dump = _dump_maker($export_to, $params, $trace);
150 }
151 else
152 {
153 # Just export stub functions
154 0 ▶ $trace = $dump = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
155 0 ▶ carp "$pkg imported with unknown target $target" if $target;
Branch: 1 branch
BranchTrueFalseTotal
if $target 0 0 0
156 }
157  
158 # Now export ...
159 69 __replace_subroutine($export_to, 'TRACE', $trace);
160 69 __replace_subroutine($export_to, 'DUMP', $dump);
161 69 __replace_subroutine($export_to, 'TRACEF', \&TRACEF);
162 69 __replace_subroutine($export_to, 'TRACE_HERE', \&TRACE_HERE);
163  
164 69 ▶ if ($params->{AllSubs})
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"AllSubs"}) 3 66 69
165 {
166 # wrap all functions in package with calls to TRACE
167 3 _debug("wrapping all functions in $export_to");
168 3 _wrap_functions($export_to, $trace);
169 }
170 }
171 }
172  
173 sub __replace_subroutine
174 282 ▶{
Subroutine __replace_subroutine: called CC=2 SCAR=7.0
175 282 my ($package, $sub, $coderef) = @_;
176 282 ▶ if (defined \&{"${package}::$sub"})
Branch: 1 branch
BranchTrueFalseTotal
if (defined \&{"${package}::$sub";}) 282 0 282
177 {
178 # quietly remove existing stub function
179 # This avoids unsightly "subroutine foo redefined" warnings
180 # 'no warnings "redefine"' doesn't work pre perl 5.6
181 282 eval "undef \$${package}::{'$sub'}";
182 }
183 282 *{"${package}::$sub"} = $coderef;
184 }
185  
186 sub _trace_maker
187 69 ▶{
Subroutine _trace_maker: called CC=1 SCAR=0.0
188 69 my ($package, $params, $trace_sub) = @_;
189 69 my $trace_level = $params->{Level};
190 return sub
191 62 ▶ {
Subroutine __ANON__: called CC=5 SCAR=16.3
192 62 local $@; # in-case TRACE is called from &DESTROY
193 62 my $rv;
194 eval
195 62 {
196 62 ▶ my $level = shift->{Level} if ($_[0] && ref $_[0] eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] and ref $_[0] eq "HASH" 29 33 62
Condition66%2/3
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
03329
MC/DC50%1/2
$_[0] and ref $_[0] eq "HASH"
$_[0] ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
197 62 ▶ return unless _evaluate_level($package, $trace_level, $level);
Branch: 1 branch
BranchTrueFalseTotal
unless _evaluate_level($package, $trace_level, $level) 14 48 62
198 48 $rv = 1 && $trace_sub->(@_);
199 };
200 62 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 62 62
201 {
202 0 warn __PACKAGE__ . " : $@";
203 }
204 62 return $rv;
205 }
206 69 }
207  
208 sub _dump_maker
209 69 ▶{
Subroutine _dump_maker: called CC=1 SCAR=0.2
210 69 my ($package, $params, $trace_sub) = @_;
211 69 my $trace_level = $params->{Level};
212 return sub
213 3 ▶ {
Subroutine __ANON__: called CC=7 SCAR=21.5
214 # always return the dumped data regardless of level unless called in
215 # void context
216 3 my $context = wantarray();
217 3 local $@; # in-case DUMP is called from &DESTROY
218 3 my $rv;
219 eval
220 3 {
221 3 ▶ return $rv = _dump($params, @_) if defined $context;
Branch: 1 branch
BranchTrueFalseTotal
if defined $context 1 2 3
222  
223 2 my $level = undef;
224 2 ▶ if ($_[0] && ref $_[0] eq 'HASH' && defined $_[0]{Level})
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] eq "HASH" and defined $_[0]{"Level"}) 0 2 2
Condition33%2/6
$_[0] and ref $_[0] eq "HASH" and defined $_[0]{"Level"}
!ll&&!rl&&r
200
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
020
MC/DC0%0/3
$_[0] and ref $_[0] eq "HASH" and defined $_[0]{"Level"}
$_[0] ref $_[0] eq "HASH" defined $_[0]{"Level"}
Truth table25%1/4
A and B and C
A= $_[0]B= ref $_[0] eq "HASH"C= defined $_[0]{"Level"}
ABCresult
0XX0
10X0
1100
1111
225 {
226 0 $level = shift->{Level};
227 }
228 2 ▶ return unless _evaluate_level($package, $trace_level, $level);
Branch: 1 branch
BranchTrueFalseTotal
unless _evaluate_level($package, $trace_level, $level) 0 2 2
229 2 my $dumped = _dump($params, @_);
230 2 $rv = 1 && $trace_sub->($dumped);
231 };
232 3 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
233 {
234 0 warn __PACKAGE__ . " : $@";
235 }
236 3 return $rv;
237 }
238 69 };
239  
240  
241 # returns a list of packages to export trace functions to
242 sub _deep_import_packages
243 4 ▶{
Subroutine _deep_import_packages: called CC=5 SCAR=16.1
244 4 my $all_packages = shift;
245  
246 # Build the list of packages
247 4 my @packages;
248 4 foreach my $module (@{_list_all_packages()})
249 {
250 1194 ▶ next if $module eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $module eq __PACKAGE__ 4 1190 1194
251 1190 ▶ next unless $all_packages || defined (&{"$module\::TRACE"});
Branch: 1 branch
BranchTrueFalseTotal
unless $all_packages or defined &{"${module}::TRACE";} 847 343 1190
Condition100%3/3
$all_packages or defined &{"${module}::TRACE";}
l!l&&r!l&&!r
29746847
MC/DC100%2/2
$all_packages or defined &{"${module}::TRACE";}
$all_packages defined &{"${module}::TRACE";}
Truth table100%3/3
A or B
A= $all_packagesB= defined &{"${module}::TRACE";}
ABresult
1X1
011
000
252 343 push @packages, $module;
253 }
254 4 return @packages;
255 }
256  
257  
258 12 my %_autowrap;
259 3 ▶sub _wrap_functions {
Subroutine _wrap_functions: called CC=9 SCAR=26.6
260 3 my ($package, $trace) = @_;
261  
262 3 ▶ return if $_autowrap{$package};
Branch: 1 branch
BranchTrueFalseTotal
if $_autowrap{$package} 1 2 3
263 2 ▶ $_autowrap{$package} = {} unless defined $_autowrap{$package};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_autowrap{$package} 2 0 2
264  
265 2 my $symbols = \%{$package . '::'};
266 # wrap coderefs in the caller's symbol table
267 2 foreach my $typeglob (keys %$symbols) {
268  
269 # skip TRACE/DUMP and other potential deep recursions
270 16 ▶ next if $typeglob =~ /^(?:TRACE(?:F|_HERE)?|DUMP|AUTOLOAD)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $typeglob =~ /^(?:TRACE(?:F|_HERE)?|DUMP|AUTOLOAD)$/ 8 8 16
271  
272 # only wrap code references
273 8 my $sub = *{$symbols->{$typeglob}}{CODE};
274 8 ▶ next unless (defined $sub and defined &$sub);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sub and defined &$sub 2 6 8
Condition66%2/3
defined $sub and defined &$sub
!ll&&!rl&&r
206
MC/DC50%1/2
defined $sub and defined &$sub
defined $sub defined &$sub
Truth table66%2/3
A and B
A= defined $subB= defined &$sub
ABresult
0X0
100
111
275  
276 # skip if sub is already wrapped
277 6 ▶ next if $_autowrap{$package}{$typeglob}++;
Branch: 1 branch
BranchTrueFalseTotal
if $_autowrap{$package}{$typeglob}++ 0 6 6
278  
279 # define wrapped subroutine body
280 6 my $sub_body = <<'WRAPPED';
281 my ($name) = "${package}::$typeglob";
282 my ($callpkg, $file, $line) = caller(1);
283 my $arg = $_[0] && ref($_[0]) ? ref($_[0]) . ', ...' : "";
284 $trace->( "${name}( $arg )" );
285 goto &$sub
286 WRAPPED
287  
288 # wrap subroutine, preserving prototypes
289 6 my $wrapped_sub;
290 6 ▶ if(defined (my $proto = prototype($sub)))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $proto = prototype $sub)) { } 0 6 6
291 {
292 0 $wrapped_sub = eval "sub ($proto) { $sub_body }";
293 }
294 else
295 {
296 0 ▶ $wrapped_sub = eval "sub { $sub_body }";
Subroutine __ANON__: called CC=3 SCAR=14.6
Subroutine __ANON__: called CC=3 SCAR=14.6
Subroutine __ANON__: not called CC=3 SCAR=14.6
Subroutine __ANON__: not called CC=3 SCAR=14.6
Subroutine __ANON__: called CC=3 SCAR=14.6
Subroutine __ANON__: called CC=3 SCAR=14.6
Branch: 6 branches
BranchTrueFalseTotal
$_[0] && ref $_[0] ? : 0 1 1
$_[0] && ref $_[0] ? : 0 1 1
$_[0] && ref $_[0] ? : 0 0 0
$_[0] && ref $_[0] ? : 0 0 0
$_[0] && ref $_[0] ? : 0 1 1
$_[0] && ref $_[0] ? : 0 1 1
Condition22%4/18
$_[0] and ref $_[0]
!ll&&!rl&&r
100
$_[0] and ref $_[0]
!ll&&!rl&&r
100
$_[0] and ref $_[0]
!ll&&!rl&&r
000
$_[0] and ref $_[0]
!ll&&!rl&&r
000
$_[0] and ref $_[0]
!ll&&!rl&&r
100
$_[0] and ref $_[0]
!ll&&!rl&&r
100
MC/DC0%0/2
$_[0] and ref $_[0]
$_[0] ref $_[0]
MC/DC0%0/2
$_[0] and ref $_[0]
$_[0] ref $_[0]
MC/DC0%0/2
$_[0] and ref $_[0]
$_[0] ref $_[0]
MC/DC0%0/2
$_[0] and ref $_[0]
$_[0] ref $_[0]
MC/DC0%0/2
$_[0] and ref $_[0]
$_[0] ref $_[0]
MC/DC0%0/2
$_[0] and ref $_[0]
$_[0] ref $_[0]
Truth table33%1/3
A and B
A= $_[0]B= ref $_[0]
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $_[0]B= ref $_[0]
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $_[0]B= ref $_[0]
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $_[0]B= ref $_[0]
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $_[0]B= ref $_[0]
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $_[0]B= ref $_[0]
ABresult
0X0
100
111
297 }
298  
299 6 __replace_subroutine($package, $typeglob, $wrapped_sub);
300 }
301 }
302  
303  
304 # return a list of all defined packages in the symbol table
305 # we could use %INC, but we'd miss packages that are defined in other modules
306 1198 ▶sub _list_all_packages {
Subroutine _list_all_packages: called CC=8 SCAR=20.8
307 1198 my ($package) = @_;
308 1198 ▶ $package = '' unless defined $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 4 1194 1198
309 1198 my @packages;
310  
311 # this is a recursive look in the symbol table:
312 # %main::
313 # CGI::
314 # Cookie::
315 # Data::
316 # Dumper::
317 # ...
318  
319 1198 my %symbols = %{$package . "::"};
320 1198 foreach my $module (keys %symbols)
321 {
322 24798 ▶ next unless $module =~ s/::$//;
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ s/::$// 23600 1198 24798
323 # ignore 'main' (deep recursion) and all invalid package names
324 1198 ▶ next if !$package && ($module eq 'main' || $module !~ /^[a-zA-Z_]\w*$/);
Branch: 1 branch
BranchTrueFalseTotal
if not $package and $module eq "main" || !($module =~ /^[a-zA-Z_]\w*$/) 4 1194 1198
Condition83%5/6
not $package and $module eq "main" || !($module =~ /^[a-zA-Z_]\w*$/)
!ll&&!rl&&r
8803144
$module eq "main" or not $module =~ /^[a-zA-Z_]\w*$/
l!l&&r!l&&!r
40314
MC/DC66%2/3
not $package and $module eq "main" || !($module =~ /^[a-zA-Z_]\w*$/)
not $package $module eq "main" not $module =~ /^[a-zA-Z_]\w*$/
Truth table75%3/4
not(A) and B or not(C)
A= not $packageB= $module eq "main"C= not $module =~ /^[a-zA-Z_]\w*$/
ABCresult
0XX0
1000
11X1
1011
325  
326 1194 ▶ my $prefix = $package ? $package . '::' : '';
Branch: 1 branch
BranchTrueFalseTotal
$package ? : 880 314 1194
327 # Add this module
328 1194 push @packages, $prefix . $module;
329 # and recurse to sub-packages
330 1194 push @packages, @{_list_all_packages($prefix . $module)};
331 }
332 1198 return \@packages;
333 }
334  
335  
336 # Override the built-in require()
337 # This is tricky because these are treated differently by perl:
338 # 1. require CGI
339 # 2. require "CGI"
340 # We have no way of distinguishing the two, so we make a best guess
341 #
342 # This only works since perl 5.6.1
343 #
344 # See 'perlsub' for more information about overriding built-ins
345 sub _install_require
346 2 ▶{
Subroutine _install_require: called CC=1 SCAR=1.0
347 2 my ($pkg, $params, $target, @args) = @_;
348  
349 # CORE::require has prototype(;$), but we get "bareword foo not allowed"
350 # errors if we use that. prototype(*) works though
351 my $require = sub (*)
352 3 ▶ {
Subroutine __ANON__: called CC=10 SCAR=31.1
353 3 local $^W;
354 3 my $what = shift;
355 3 ▶ return 1 if $INC{$what};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$what} 2 1 3
356 1 _debug("require $what");
357  
358 1 my $package;
359 1 ▶ if ($what =~ /^v?[\d_.]+$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($what =~ /^v?[\d_.]+$/) { } 0 1 1
elsif ($what =~ /(.*)\.pm$/) { } 1 0 1
elsif ($what =~ /^[a-zA-Z_]\w*(?:::\w+)*$/i) { } 0 0 0
360 # take advantage of UNIVERSAL->VERSION($require) for a portable
361 # version check
362 0 local $_Log::Trace::PerlVersion::VERSION = $];
363 0 eval {_Log::Trace::PerlVersion->VERSION($what)};
364 0 ▶ if (my $error = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 0 0
365 0 $error =~ s/_Log::Trace::PerlVersion/Perl/;
366 0 die $error; #rethrow exception
367 }
368 0 return 1;
369 } elsif ($what =~ /(.*)\.pm$/) {
370 # looks like a module name, get the main package from the filename
371 # (perl 5.8 & ActivePerl 5.6.1)
372 1 ($package = $1) =~ s{/}{::}g;
373 } elsif ($what =~ /^[a-zA-Z_]\w*(?:::\w+)*$/i) {
374 # package name: vanilla perl 5.6.1, 5.6.2
375 0 $package = $what;
376 0 ($what = "$what.pm") =~ s{::}{/}g;
377 }
378  
379 1 my $rv = CORE::require $what;
380 1 ▶ if ($rv && $package)
Branch: 1 branch
BranchTrueFalseTotal
if ($rv and $package) 1 0 1
Condition33%1/3
$rv and $package
!ll&&!rl&&r
001
MC/DC0%0/2
$rv and $package
$rv $package
Truth table33%1/3
A and B
A= $rvB= $package
ABresult
0X0
100
111
381 {
382 # import Log::Trace into package
383 return unless $params->{Everywhere}
384 1 ▶ || defined (&{"$package\::TRACE"});
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"Everywhere"} or defined &{"${package}::TRACE";} 0 1 1
Condition33%1/3
$params->{"Everywhere"} or defined &{"${package}::TRACE";}
l!l&&r!l&&!r
010
MC/DC0%0/2
$params->{"Everywhere"} or defined &{"${package}::TRACE";}
$params->{"Everywhere"} defined &{"${package}::TRACE";}
Truth table33%1/3
A or B
A= $params->{"Everywhere"}B= defined &{"${package}::TRACE";}
ABresult
1X1
011
000
385 1 $pkg->_import($package, $target, @args, $params);
386 }
387 1 return $rv;
388 2 };
389  
390 # Override global require, silencing "... used only once" warnings
391 2 *CORE::GLOBAL::require = *CORE::GLOBAL::require = $require;
392 }
393  
394  
395 # Returns caller info for exported functions
396 sub __caller
397 13 ▶{
Subroutine __caller: called CC=6 SCAR=18.1
398 # We need to look several frames back, so we keep going until we find
399 # something from outside this package
400 13 my @caller;
401 13 for (1 .. 8) {
402 65 my @c = caller($_);
403 65 ▶ last unless defined $c[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c[0] 13 52 65
404 52 @caller = @c;
405 52 ▶ last unless $caller[0] eq __PACKAGE__
Branch: 1 branch
BranchTrueFalseTotal
unless $caller[0] eq __PACKAGE__ or $caller[3] =~ /^@{[__PACKAGE__];}\::/o 0 52 52
Condition66%2/3
$caller[0] eq __PACKAGE__ or $caller[3] =~ /^@{[__PACKAGE__];}\::/o
l!l&&r!l&&!r
39130
MC/DC0%0/2
$caller[0] eq __PACKAGE__ or $caller[3] =~ /^@{[__PACKAGE__];}\::/o
$caller[0] eq __PACKAGE__ $caller[3] =~ /^@{[__PACKAGE__];}\::/o
Truth table66%2/3
A or B
A= $caller[0] eq __PACKAGE__B= $caller[3] =~ /^@{[__PACKAGE__];}\::/o
ABresult
1X1
011
000
406 4 || $caller[3] =~ /^@{[__PACKAGE__]}\::/o;
407 }
408  
409 # because we don't seem to get a call frame for main::__ANON__
410 13 ▶ $caller[0] = 'main' if ($caller[0] eq __PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if $caller[0] eq __PACKAGE__ 0 13 13
411 13 $caller[3] =~ s/^@{[__PACKAGE__]}\::.*/main::__ANON__/;
412 13 return @caller;
413 }
414  
415 #################################################
416 # TRACE guts
417 #################################################
418  
419 sub _evaluate_level
420 64 ▶{
Subroutine _evaluate_level: called CC=12 SCAR=24.9
421 64 my ($callpkg, $imported_level, $trace_level) = @_;
422  
423 64 ▶ return 1 if ! defined $imported_level;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $imported_level 37 27 64
424  
425 27 ▶ if (ref $imported_level eq 'CODE')
Branch: 3 branches
BranchTrueFalseTotal
if (ref $imported_level eq 'CODE') { } 2 25 27
elsif (ref $imported_level eq 'ARRAY') { } 7 18 25
elsif (not ref $imported_level) { } 18 0 18
426 {
427 2 return $imported_level->($callpkg, $trace_level);
428 }
429 elsif (ref $imported_level eq 'ARRAY')
430 {
431 7 for (@$imported_level)
432 {
433 19 ▶ return 1 if (! defined($_) && ! defined($trace_level));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ or defined $trace_level 1 18 19
Condition100%3/3
defined $_ or defined $trace_level
l!l&&r!l&&!r
1621
MC/DC100%2/2
defined $_ or defined $trace_level
defined $_ defined $trace_level
Truth table100%3/3
A or B
A= defined $_B= defined $trace_level
ABresult
1X1
011
000
434 18 ▶ next unless defined($trace_level) && defined($_);;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trace_level and defined $_ 6 12 18
Condition100%3/3
defined $trace_level and defined $_
!ll&&!rl&&r
4212
MC/DC100%2/2
defined $trace_level and defined $_
defined $trace_level defined $_
Truth table100%3/3
A and B
A= defined $trace_levelB= defined $_
ABresult
0X0
100
111
435 12 ▶ return 1 if $_ == $trace_level;
Branch: 1 branch
BranchTrueFalseTotal
if $_ == $trace_level 3 9 12
436 }
437 }
438 elsif (!ref $imported_level)
439 {
440 18 ▶ return unless defined $trace_level;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trace_level 1 17 18
441 17 return $imported_level >= $trace_level;
442 }
443 }
444  
445 sub _log_normal
446 14 ▶{
Subroutine _log_normal: called CC=1 SCAR=0.0
447 14 return join(",", @_)."\n";
448 }
449  
450 sub _log_verbose
451 4 ▶{
Subroutine _log_verbose: called CC=1 SCAR=0.0
452 4 my ($pack,$file,$line,$sub) = __caller();
453 4 return "$sub ($line) :: " . join( ", ", @_ ) . "\n";
454 }
455  
456 sub _log_debug
457 4 ▶{
Subroutine _log_debug: called CC=1 SCAR=0.0
458 4 my ($pack,$file,$line,$sub) = __caller();
459 4 my $timestamp = _timestamp();
460 4 return "$file: $sub ($line) [$timestamp] " . join( ", ", @_ ) . "\n";
461 }
462  
463 sub _log_to_fh
464 7 ▶{
Subroutine _log_to_fh: called CC=2 SCAR=6.9
465 7 my ($fh, @output) = @_;
466 7 ▶ $fh = \*STDOUT unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 1 6 7
467 7 print $fh @output;
468 }
469  
470 sub _log_to_file
471 5 ▶{
Subroutine _log_to_file: called CC=3 SCAR=11.5
472 5 my $filename = shift;
473 5 my ($pack,$file,$line,$sub) = __caller();
474  
475 5 local *LOG_FILE;
476 5 ▶ if (open (LOG_FILE, ">> $filename"))
Branch: 1 branch
BranchTrueFalseTotal
if (open LOG_FILE, ">> $filename") { } 5 0 5
477 {
478 5 ▶ if (eval {flock LOG_FILE, LOCK_EX|LOCK_NB})
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { flock LOG_FILE, 6 } }) { } 5 0 5
479 {
480 5 print LOG_FILE @_;
481 5 flock LOG_FILE, LOCK_UN;
482 5 close LOG_FILE;
483 }
484 else
485 {
486 0 die "couldn't get lock on $filename : $!";
487 }
488 }
489 else
490 {
491 0 die "Cannot open $filename : $!";
492 }
493 }
494  
495 sub _log_to_syslog
496 0 ▶{
Subroutine _log_to_syslog: not called CC=3 SCAR=24.8
497 0 ▶ my ($priority) = shift || 'debug';
Condition0%0/2
shift() || 'debug'
l!l
00
MC/DC0%0/1
shift() || 'debug'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
498  
499 0 ▶ return unless eval {require Sys::Syslog};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Sys::Syslog } } 0 0 0
500 0 Sys::Syslog::openlog(__PACKAGE__, 'pid');
501 0 my $rv = Sys::Syslog::syslog($priority, join ",", @_);
502 0 Sys::Syslog::closelog();
503 0 return $rv;
504 }
505  
506 sub _dump
507 3 ▶{
Subroutine _dump: called CC=8 SCAR=22.9
508 3 my ($params, @args) = @_;
509  
510 3 ▶ my $msg = ref $args[0] ? '' : shift @args;
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 1 2 3
511 3 ▶ $msg .= ": " if($msg && @args);
Branch: 1 branch
BranchTrueFalseTotal
if $msg and @args 2 1 3
Condition66%2/3
$msg and @args
!ll&&!rl&&r
102
MC/DC50%1/2
$msg and @args
$msg @args
Truth table66%2/3
A and B
A= $msgB= @args
ABresult
0X0
100
111
512  
513 3 my $type;
514 eval
515 3 {
516 3 ▶ if ($params->{Dumper})
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'Dumper'}) { } 0 3 3
517 {
518 0 $type = 'Data::Serializer';
519 0 require Data::Serializer;
520 my $params = ref $params->{Dumper} ?
521 0 ▶ $params->{Dumper} : { serializer => $params->{Dumper} };
Branch: 1 branch
BranchTrueFalseTotal
ref $params->{'Dumper'} ? : 0 0 0
522 0 my $serialiser = Data::Serializer->new(%$params);
523 0 for (@args)
524 {
525 0 $msg .= $serialiser->raw_serialize($_) . "\n";
526 }
527 }
528 else
529 {
530 3 $type = 'Data::Dumper';
531 3 require Data::Dumper;
532 # avoid 'used $var only once' warning
533 3 local $Data::Dumper::Indent;
534 3 local $Data::Dumper::Sortkeys;
535 3 local $Data::Dumper::Quotekeys;
536 3 $Data::Dumper::Indent = 1;
537 3 $Data::Dumper::Sortkeys = 1;
538 3 $Data::Dumper::Quotekeys = 0;
539  
540 3 $msg .= Data::Dumper::Dumper(@args);
541 }
542 };
543 3 ▶ die "$type not available: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
544 3 return $msg;
545 }
546  
547 sub _gettimeofday()
548 4 ▶{
Subroutine _gettimeofday: called CC=2 SCAR=9.2
549 4 ▶ return Time::HiRes::gettimeofday() if $INC{'Time/HiRes.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"Time/HiRes.pm"} 4 0 4
550 0 return (time(), undef);
551 }
552  
553 #Provide localtime-style timestamp with microsecond resolution if Time::HiRes
554 #is available
555 sub _timestamp
556 4 ▶{
Subroutine _timestamp: called CC=2 SCAR=7.0
557 4 my ($epoch, $usec) = _gettimeofday();
558 4 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($epoch);
559 4 $year+=1900; $mon+=1;
560 4 my $stamp = sprintf("%4d-%02d-%02d %02d:%02d:%02d",$year,$mon,$mday,$hour,$min,$sec);
561 4 ▶ $stamp .= sprintf(".%.6d",$usec) if(defined $usec);
Branch: 1 branch
BranchTrueFalseTotal
if defined $usec 4 0 4
562 4 return $stamp;
563 }
564  
565 12 1;
566  
567 =head1 NAME
568  
569 Log::Trace - provides a unified approach to tracing
570  
571 =head1 SYNOPSIS
572  
573 # The tracing targets
574 use Log::Trace; # No output
575 use Log::Trace 'print'; # print to STDOUT
576 use Log::Trace log => '/var/log/foo.log'; # Output to log file
577 use Log::Trace print => { Level => 3 };
578  
579 # Switch on/off logging with a constant
580 use Log::Trace;
581 import Log::Trace ('log' => LOGFILE) if TRACING;
582  
583  
584 # Set up tracing for all packages that advertise TRACE
585 use Foo;
586 use Bar;
587 use Log::Trace warn => { Deep => 1 };
588  
589 # Sets up tracing in all subpackages excluding Foo
590 use Log::Trace warn => {Deep => 1, 'Exclude' => 'Foo'};
591  
592  
593 # Exported functions
594 TRACE("Record this...");
595 TRACE({Level => 2}, "Only shown if tracing level is 2 or higher");
596 TRACEF("A la printf: %d-%.2f", 1, 2.9999);
597 TRACE_HERE(); # Record where we are (file, line, sub, args)
598 DUMP(\@loh, \%hoh); # Trace out via Data::Dumper
599 DUMP("Title", \@loh); # Trace out via Data::Dumper
600 my $dump = DUMP(@args); # Dump is returned without being traced
601  
602 =head1 DESCRIPTION
603  
604 A module to provide a unified approach to tracing. A script can C<use
605 Log::Trace qw( E<lt> mode E<gt> )> to set the behaviour of the TRACE function.
606  
607 By default, the trace functions are exported to the calling package only. You
608 can export the trace functions to other packages with the C<Deep> option. See
609 L<"OPTIONS"> for more information.
610  
611 All exports are in uppercase (to minimise collisions with "real" functions).
612  
613 =head1 FUNCTIONS
614  
615 =over 4
616  
617 =item TRACE(@args)
618  
619 Output a message. Where the message actually goes depends on how you imported
620 Log::Trace (See L<"Importing/enabling Log::Trace">)
621  
622 The first argument is an optional hashref of options:
623  
624 TRACE('A simple message');
625  
626 vs:
627  
628 TRACE({ Level => 2.1 }, 'A message at a specified trace level');
629  
630 =item TRACEF($format, @args)
631  
632 C<printf()> equivalent of TRACE. Also accepts an optional hashref:
633  
634 TRACEF('%d items', scalar @items);
635 TRACEF({ Level => 5 }, '$%1.2d', $value);
636  
637 =item DUMP([$message,] @args)
638  
639 Serialises each of @args, optionally prepended with $message. If called in a
640 non-void context, DUMP will return the serialised data rather than TRACE
641 it. This is useful if you want to DUMP a datastructure at a specific tracing
642 level.
643  
644 DUMP('colours', [qw(red green blue)]); # outputs via TRACE
645 my $dump = DUMP('colours', [qw(red green blue)]); # output returned
646  
647 =item TRACE_HERE()
648  
649 TRACEs the current position on the call stack (file, line number, subroutine
650 name, subroutine args).
651  
652 TRACE_HERE();
653 TRACE_HERE({Level => 99});
654  
655 =back
656  
657 =head1 Importing/enabling Log::Trace
658  
659 =over 4
660  
661 =item import($target, [$arg], [\%params])
662  
663 Controls where TRACE messages go. This method is called automatically when you
664 call C<'use Log::Trace;'>, but you may explicitly call this method at
665 runtime. Compare the following:
666  
667 use Log::Trace 'print';
668  
669 which is the same as
670  
671 BEGIN {
672 require Log::Trace;
673 Log::Trace->import('print');
674 }
675  
676 Valid combinations of C<$target> and C<arg> are:
677  
678 =over 4
679  
680 =item print =E<gt> $filehandle
681  
682 Prints trace messages to the supplied C<$filehandle>. Defaults to C<STDOUT>
683 if no file handle is specified.
684  
685 =item warn
686  
687 Prints trace messages via C<warn()>s to C<STDERR>.
688  
689 =item buffer =E<gt> \$buffer
690  
691 Appends trace messages to a string reference.
692  
693 =item file =E<gt> $filename
694  
695 Append trace messages to a file. If the file doesn't exist, it will be created.
696  
697 =item log =E<gt> $filename
698  
699 This is equivalent to:
700  
701 use Log::Trace file => $filename, {Verbose => 2};
702  
703 =item syslog =E<gt> $priority
704  
705 Logs trace messages to syslog via C<Sys::Syslog>, if available.
706  
707 You should consult your syslog configuration before using this option.
708  
709 The default C<$priority> is 'C<debug>', and the C<ident> is set to
710 C<Log::Trace>. You can configure the C<priority>, but beyond that, you can
711 implement your own syslogging via the C<custom> trace target.
712  
713 =item custom => \&custom_trace_sub
714  
715 Trace messages are processed by a custom subroutine. E.g.
716  
717 use Log::Trace custom => \&mylogger;
718  
719 sub mylogger {
720 my @messages = @_;
721 foreach (@messages) {
722 # highly sensitive trace messages!
723 tr/a-zA-Z/n-za-mN-ZA-M/;
724 print;
725 }
726 }
727  
728 =back
729  
730 The import C<\%params> are optional. These two statements are functionally the
731 same:
732  
733 import Log::Trace print => {Level => undef};
734 import Log::Trace 'print';
735  
736 See L<"OPTIONS"> for more information.
737  
738 B<Note:> If you use the C<custom> tracing option, you should be careful about
739 supplying a subroutine named C<TRACE>.
740  
741 =back
742  
743 =head1 OPTIONS
744  
745 =over 4
746  
747 =item AllSubs =E<gt> BOOL
748  
749 Attaches a C<TRACE> statement to all subroutines in the package. This can be
750 used to track the execution path of your code. It is particularly useful when
751 used in conjunction with C<Deep> and C<Everywhere> options.
752  
753 B<Note:> Anonymous subroutines and C<AUTOLOAD> are not C<TRACE>d.
754  
755 =item AutoImport =E<gt> BOOL
756  
757 By default, C<Log::Trace> will only set up C<TRACE> routines in modules that
758 have already been loaded. This option overrides C<require()> so that modules
759 loaded after C<Log::Trace> can automatically be set up for tracing.
760  
761 B<Note>: This is an experimental feature. See the ENVIRONMENT NOTES
762 for information about behaviour under different versions of perl.
763  
764 This option has no effect on perl E<lt> 5.6
765  
766 =item Deep =E<gt> BOOL
767  
768 Attaches C<Log::Trace> to all packages (that define a TRACE function). Any
769 TRACEF, DUMP and TRACE_HERE routines will also be overridden in these packages.
770  
771 =item Dumper =E<gt> Data::Serializer backend
772  
773 Specify a serialiser to be used for DUMPing data structures.
774  
775 This should either be a string naming a Data::Serializer backend (e.g. "YAML")
776 or a hashref of parameters which will be passed to Data::Serializer, e.g.
777  
778 {
779 serializer => 'XML::Dumper',
780 options => {
781 dtd => 'path/to/my.dtd'
782 }
783 }
784  
785 Note that the raw_serialise() method of Data::Serializer is used. See L<Data::Serializer>
786 for more information.
787
788 If you do not have C<Data::Serializer> installed, leave this option undefined to use the
789 C<Data::Dumper> natively.
790  
791 Default: undef (use standalone Data::Dumper)
792  
793 =item Everywhere =E<gt> BOOL
794  
795 When used in conjunction with the C<Deep> option, it will override the
796 standard behaviour of only enabling tracing in packages that define C<TRACE>
797 stubs.
798  
799 Default: false
800  
801 =item Exclude =E<gt> STRING|ARRAY
802  
803 Exclude a module or list of modules from tracing.
804  
805 =item Level =E<gt> NUMBER|LIST|CODE
806  
807 Specifies which trace levels to display.
808  
809 If no C<Level> is defined, all TRACE statements will be output.
810  
811 If the value is numeric, only TRACEs that are at the specified level or below
812 will be output.
813  
814 If the value is a list of numbers, only TRACEs that match the specified levels
815 are output.
816  
817 The level may also be a code reference which is passed the package name and the
818 TRACE level. It mst return a true value if the TRACE is to be output.
819  
820 Default: undef
821  
822 =item Match =E<gt> REGEX
823  
824 Exports trace functions to packages that match the supplied regular
825 expression. Can be used in conjunction with C<Exclude>. You can also use
826 C<Match> as an exclusion method if you give it a negative look-ahead.
827  
828 For example:
829  
830 Match => qr/^(?!Acme::)/ # will exclude every module beginning with Acme::
831  
832 and
833  
834 Match => qr/^Acme::/ # does the reverse
835  
836 Default: '.' # everything
837  
838 =item Verbose =E<gt> 0|1|2
839  
840 You can use this option to prepend extra information to each trace message. The
841 levels represent increasing levels of verbosity:
842  
843 0: the default*, don't add anything
844 1: adds subroutine name and line number to the trace output
845 2: As [1], plus a filename and timestamp (in ISO 8601 : 2000 format)
846  
847 This setting has no effect on the C<custom> or C<log> targets.
848  
849 * I<the log target uses 'Verbose' level 2>
850  
851 =back
852  
853 =head1 ENVIRONMENT NOTES
854  
855 The AutoImport feature overrides C<CORE::require()> which requires perl 5.6, but you may see unexpected errors if you aren't using at
856 least perl 5.8. The AutoImport option has no effect on perl E<lt> 5.6.
857  
858 In mod_perl or other persistent interpreter environments, different applications could trample on each other's
859 C<TRACE> routines if they use Deep (or Everywhere) option. For example application A could route all the trace output
860 from Package::Foo into "appA.log" and then application B could import Log::Trace over the top, re-routing all the trace output from Package::Foo
861 to "appB.log" for evermore. One way around this is to ensure you always import Log::Trace on every run in a persistent environment from all your
862 applications that use the Deep option. We may provide some more tools to work around this in a later version of C<Log::Trace>.
863  
864 C<Log::Trace> has not been tested in a multi-threaded application.
865  
866 =head1 DEPENDENCIES
867  
868 Carp
869 Time::HiRes (used if available)
870 Data::Dumper (used if available - necessary for meaningful DUMP output)
871 Data::Serializer (optional - to customise DUMP output)
872 Sys::Syslog (loaded on demand)
873  
874 =head1 RELATED MODULES
875  
876 =over 4
877  
878 =item Log::TraceMessages
879  
880 C<Log::TraceMessages> is similar in design and purpose to C<Log::Trace>.
881 However, it only offers a subset of this module's functionality. Most notably,
882 it doesn't offer a mechanism to control the tracing output of an entire
883 application - tracing must be enabled on a module-by-module
884 basis. C<Log::Trace> also offers control over the output with the trace
885 levels and supports more output targets.
886  
887 =item Log::Agent
888  
889 C<Log::Agent> offers a procedural interface to logging. It strikes a good
890 balance between configurability and ease of use. It differs to C<Log::Trace> in
891 a number of ways. C<Log::Agent> has a concept of channels and priorities, while
892 C<Log::Trace> only offers levels. C<Log::Trace> also supports tracing code
893 execution path and the C<Deep> import option. C<Log::Trace> trades a certain
894 amount of configurability for increased ease-of use.
895  
896 =item Log::Log4Perl
897  
898 A feature rich perl port of the popular C<log4j> library for Java. It is
899 object-oriented and comprised of more than 30 modules. It has an impressive
900 feature set, but some people may be frightened of its complexity. In contrast,
901 to use C<Log::Trace> you need only remember up to 4 simple functions and a
902 handful of configuration options.
903  
904 =back
905  
906 =head1 SEE ALSO
907  
908 L<Log::Trace::Manual> - A guide to using Log::Trace
909  
910 =head1 VERSION
911  
912 $Revision: 1.70 $ on $Date: 2005/11/01 11:32:59 $ by $Author: colinr $
913  
914 =head1 AUTHOR
915  
916 John Alden and Simon Flack with some additions by Piers Kent and Wayne Myers
917 <cpan _at_ bbc _dot_ co _dot_ uk>
918  
919 =head1 COPYRIGHT
920  
921 (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL.
922  
923 See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
924  
925 =cut
↑ Summary