File Coverage

lib/Devel/PerlySense/Util/Log.pm
Criterion Covered Total %
statement 32 40 80.0
branch 2 8 25.0
condition 0 3 0.0
subroutine 10 11 90.9
pod 1 1 100.0
total 45 63 71.4


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Devel::PerlySense::Util::Log - Log routines
4              
5             =cut
6              
7              
8              
9 63     63   261 use strict;
  63         68  
  63         1651  
10 63     63   209 use warnings;
  63         69  
  63         2451  
11 63     63   1074 use utf8;
  63         104  
  63         2512  
12              
13             package Devel::PerlySense::Util::Log;
14 63     63   1979 use base "Exporter";
  63         70  
  63         1188  
15              
16             our @EXPORT = (
17             qw/
18             debug
19             /);
20              
21              
22              
23              
24              
25              
26 63     63   8996 use Carp;
  63         74  
  63         2930  
27 63     63   242 use Data::Dumper;
  63         57  
  63         6644  
28 63     63   235 use File::Basename;
  63         67  
  63         3102  
29 63     63   505 use Path::Class;
  63         55359  
  63         2446  
30              
31 63     63   43919 use Devel::PerlySense::Home;
  63         127  
  63         460  
32              
33              
34              
35              
36              
37             =head1 ROUTINES
38              
39             =head2 debug($message)
40              
41             Log debug $message to a log file in the HOME log directory.
42              
43             Return 1.
44              
45             =cut
46             my $fileDebug;
47             my @aHistoryMessage;
48             my $maxCountHistory = 200;
49             sub debug {
50 166     166 1 3000 my ($message) = @_;
51              
52 166         9836 my $messageLog = localtime() . ": $message\n";
53              
54             #Keep recent messages in memory for test diagnostics
55 166         744 push(@aHistoryMessage, $messageLog);
56 166 50       357 @aHistoryMessage > $maxCountHistory and shift(@aHistoryMessage);
57              
58            
59 166 50       1639 $0 =~ /\.t$/ and return 1; #Don't log when running tests
60              
61 0 0 0       $fileDebug ||= do {
62 0           my $oHome = Devel::PerlySense::Home->new();
63 0           file($oHome->dirHomeLog, "debug.log");
64            
65             } or return 0;
66              
67 0 0         open(my $fh, ">>", $fileDebug) or return 0;
68 0           $fh->print($messageLog);
69            
70 0           return(1);
71             }
72              
73              
74              
75              
76              
77             #Debugging aid during CPAN testers failures
78             #This is a hack, please ignore
79             sub _textTailDebug {
80 0     0     my $class = shift;
81 0           return join("\n", @aHistoryMessage);
82             }
83              
84              
85              
86              
87              
88             1;
89              
90              
91              
92              
93              
94             __END__
95              
96             =encoding utf8
97              
98             =head1 AUTHOR
99              
100             Johan Lindström, C<< <johanl[ÄT]DarSerMan.com> >>
101              
102             =head1 BUGS
103              
104             Please report any bugs or feature requests to
105             C<bug-devel-perlysense@rt.cpan.org>, or through the web interface at
106             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-PerlySense>.
107             I will be notified, and then you'll automatically be notified of progress on
108             your bug as I make changes.
109              
110             =head1 ACKNOWLEDGEMENTS
111              
112             =head1 COPYRIGHT & LICENSE
113              
114             Copyright 2005 Johan Lindström, All Rights Reserved.
115              
116             This program is free software; you can redistribute it and/or modify it
117             under the same terms as Perl itself.
118              
119             =cut