blib/lib/Froody/Logger.pm

filter: Statementstmt 83.0% 44 / 53 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod n/a totaltotal 78.5% 55 / 70 CC 1 SCAR 0.9
CC
1
Cov
81%
__ANON__
1.3
__ANON__
1.3
__ANON__
1.3
CRAP 1.1
« blib/lib/Froody/ErrorType.pm ↑ Summary blib/lib/Froody.pm »
1 package Froody::Logger;
2  
3 60 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 60 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 60 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 60 our @EXPORT = qw(get_logger);
8  
9 =head1 NAME
10  
11 Froody::Logger - logging wrapper
12  
13 =head1 SYNOPSIS
14  
15 use Froody::Logger;
16 my $logger = get_logger;
17  
18 =head1 DESCRIPTION
19  
20 Fotango internally use a Log4perl subclass, Logger. We don't want to
21 impose this on the world when we release our external modules. So we have
22 this module that uses Logger if it can, otherwise, it warns on warnings,
23 dies on error or fatal, and ignores everything else.
24  
25 =head2 METHODS
26  
27 =over
28  
29 =item get_logger
30  
31 =back
32  
33 =cut
34  
35 # try to load logger
36 0 eval { require Logger; require Test::Logger };
37  
38 # if that didn't work, pretend with the compat module
39 356 ▶*Logger::get_logger = sub { 'Froody::Logger::Compat' }
Subroutine __ANON__: called CC=1 SCAR=0.0
40 60 ▶ unless Logger->can('get_logger');
Branch: 1 branch
BranchTrueFalseTotal
unless "Logger"->can("get_logger") 60 0 60
41  
42 60 ▶use List::Util 'sum';
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 60 ▶unless (Test::Logger->can('expect')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Test::Logger"->can("expect")) 60 0 60
45 *Test::Logger::expect =
46 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
47 2 my $class = shift;
48 2 my $Tester = Test::Builder->new();
49 2 $Tester->skip('Logger not available');
50 60 };
51 60 $INC{'Test/Logger.pm'} = __FILE__;
52 }
53 # our get logger is the same as whatever Logger's is
54 60 *get_logger = *Logger::get_logger;
55  
56 ########
57 # compat package.
58  
59 package Froody::Logger::Compat;
60 60 require Carp;
61  
62 60 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.3
63  
64 60 ▶my $ignore = sub { return };
Subroutine __ANON__: called CC=1 SCAR=0.0
65 60 ▶my $warn = sub { shift; goto \&Carp::carp };
Subroutine __ANON__: called CC=1 SCAR=0.0
66 0 ▶my $carp = sub { shift; goto \&Carp::carp };
Subroutine __ANON__: not called CC=1 SCAR=2.6
67 0 ▶my $die = sub { shift; goto \&CORE::die };
Subroutine __ANON__: not called CC=1 SCAR=2.6
68 0 ▶my $confess = sub { shift; goto \&Carp::confess };
Subroutine __ANON__: not called CC=1 SCAR=2.6
69 0 ▶my $croak = sub { shift; goto \&Carp::croak };
Subroutine __ANON__: not called CC=1 SCAR=2.6
70  
71 60 *debug = $ignore;
72 60 *info = $ignore;
73 60 *warn = $warn;
74 60 *error = $die;
75 60 *fatal = $die;
76 60 *logconfess = $confess;
77 60 *logdie = $die;
78 60 *logcarp = $carp;
79 60 *logcroak = $croak;
80  
81 }
82  
83 =head1 BUGS
84  
85 None known.
86  
87 Please report any bugs you find via the CPAN RT system.
88 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody>
89  
90 =head1 AUTHOR
91  
92 Copyright Fotango 2005. All rights reserved.
93  
94 Please see the main L<Froody> documentation for details of who has worked
95 on this project.
96  
97 This module is free software; you can redistribute it and/or modify it under
98 the same terms as Perl itself.
99  
100 =head1 SEE ALSO
101  
102 L<Froody>
103  
104 =cut
105  
106 60 1;
107  
« blib/lib/Froody/ErrorType.pm ↑ Summary blib/lib/Froody.pm »