File Coverage

blib/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 68     68   92155 use strict;
  68         183  
  68         1530  
10 68     68   209 use warnings;
  68         77  
  68         1475  
11 68     68   1072 use utf8;
  68         86  
  68         256  
12              
13             package Devel::PerlySense::Util::Log;
14             $Devel::PerlySense::Util::Log::VERSION = '0.0217';
15 68     68   2518 use base "Exporter";
  68         70  
  68         433  
16              
17             our @EXPORT = (
18             qw/
19             debug
20             /);
21              
22              
23              
24              
25              
26              
27 68     68   5530 use Carp;
  68         109  
  68         3030  
28 68     68   259 use Data::Dumper;
  68         74  
  68         2275  
29 68     68   238 use File::Basename;
  68         104  
  68         2793  
30 68     68   563 use Path::Class;
  68         26843  
  68         2313  
31              
32 68     68   15840 use Devel::PerlySense::Home;
  68         104  
  68         524  
33              
34              
35              
36              
37              
38             =head1 ROUTINES
39              
40             =head2 debug($message)
41              
42             Log debug $message to a log file in the HOME log directory.
43              
44             Return 1.
45              
46             =cut
47             my $fileDebug;
48             my @aHistoryMessage;
49             my $maxCountHistory = 200;
50             sub debug {
51 172     172 1 2093 my ($message) = @_;
52              
53 172         4919 my $messageLog = localtime() . ": $message\n";
54              
55             #Keep recent messages in memory for test diagnostics
56 172         299 push(@aHistoryMessage, $messageLog);
57 172 50       398 @aHistoryMessage > $maxCountHistory and shift(@aHistoryMessage);
58              
59            
60 172 50       978 $0 =~ /\.t$/ and return 1; #Don't log when running tests
61              
62 0 0 0       $fileDebug ||= do {
63 0           my $oHome = Devel::PerlySense::Home->new();
64 0           file($oHome->dirHomeLog, "debug.log");
65            
66             } or return 0;
67              
68 0 0         open(my $fh, ">>", $fileDebug) or return 0;
69 0           $fh->print($messageLog);
70            
71 0           return(1);
72             }
73              
74              
75              
76              
77              
78             #Debugging aid during CPAN testers failures
79             #This is a hack, please ignore
80             sub _textTailDebug {
81 0     0     my $class = shift;
82 0           return join("\n", @aHistoryMessage);
83             }
84              
85              
86              
87              
88              
89             1;
90              
91              
92              
93              
94              
95             __END__
96              
97             =encoding utf8
98              
99             =head1 AUTHOR
100              
101             Johan Lindstrom, C<< <johanl@cpan.org> >>
102              
103             =head1 BUGS
104              
105             Please report any bugs or feature requests to
106             C<bug-devel-perlysense@rt.cpan.org>, or through the web interface at
107             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-PerlySense>.
108             I will be notified, and then you'll automatically be notified of progress on
109             your bug as I make changes.
110              
111             =head1 ACKNOWLEDGEMENTS
112              
113             =head1 COPYRIGHT & LICENSE
114              
115             Copyright 2005 Johan Lindstrom, All Rights Reserved.
116              
117             This program is free software; you can redistribute it and/or modify it
118             under the same terms as Perl itself.
119              
120             =cut