File Coverage

blib/lib/Prancer/Logger.pm
Criterion Covered Total %
statement 12 21 57.1
branch 0 4 0.0
condition 0 2 0.0
subroutine 4 7 57.1
pod 0 1 0.0
total 16 35 45.7


line stmt bran cond sub pod time code
1             package Prancer::Logger;
2              
3 4     4   12 use strict;
  4         4  
  4         126  
4 4     4   9 use warnings FATAL => 'all';
  4         4  
  4         106  
5              
6 4     4   19 use Module::Load ();
  4         3  
  4         58  
7 4     4   8 use Try::Tiny;
  4         26  
  4         679  
8              
9             sub load {
10 0     0 0       my ($class, $config) = @_;
11 0   0           my $module = $config->{'driver'} || "Prancer::Logger::Console";
12              
13                 try {
14 0     0             Module::Load::load($module);
15                 } catch {
16 0 0   0             my $error = (defined($_) ? $_ : "unknown");
17 0                   die "could not initialize logger: not able to load ${module}: ${error}\n";
18 0               };
19              
20             # make sure the module implements our required logging levels
21 0               for (qw(debug info warn error fatal)) {
22 0 0                 die "could not initialize logger: ${module} doesn't implement '${_}'\n" unless $module->can($_);
23                 }
24              
25             # now create and load the module
26 0               return $module->new($config->{'options'});
27             }
28              
29             1;
30              
31             =head1 NAME
32            
33             Prancer::Logger
34            
35             =head1 SYNOPSIS
36            
37             This module should not be used directly to access the logger. Instead, one
38             should use L<Prancer>. For configuration options, please refer to the
39             documentation for the specific logger you wish to use.
40            
41             =head1 SEE ALSO
42            
43             =over 4
44            
45             =item L<Prancer::Logger::Console>
46            
47             =back
48            
49             =cut
50