File Coverage

blib/lib/MooX/Role/Logger.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 25 25 100.0


line stmt bran cond sub pod time code
1 2     2   82275 use strict;
  2         6  
  2         63  
2 2     2   10 use warnings;
  2         5  
  2         86  
3              
4             package MooX::Role::Logger;
5             # ABSTRACT: Provide logging via Log::Any
6             our $VERSION = '0.004'; # VERSION
7              
8 2     2   9 use Moo::Role;
  2         4  
  2         9  
9 2     2   2462 use Types::Standard qw/Str/;
  2         140573  
  2         22  
10              
11 2     2   1998 use Log::Any ();
  2         5  
  2         358  
12              
13             #pod =method _logger
14             #pod
15             #pod Returns a logging object. See L for a list of logging methods it accepts.
16             #pod
17             #pod =cut
18              
19             has _logger => (
20             is => 'lazy',
21             isa => sub { ref( $_[0] ) =~ /^Log::Any/ }, # XXX too many options
22             init_arg => undef,
23             );
24              
25             sub _build__logger {
26 2     2   6556 my ($self) = @_;
27 2         11 return Log::Any->get_logger( category => $self->_logger_category );
28             }
29              
30             has _logger_category => (
31             is => 'lazy',
32             isa => Str,
33             );
34              
35             #pod =method _build__logger_category
36             #pod
37             #pod Override to set the category used for logging. Defaults to the class name of
38             #pod the object (which could be a subclass). You can override to lock it to a
39             #pod particular name:
40             #pod
41             #pod sub _build__logger_category { __PACKAGE__ }
42             #pod
43             #pod =cut
44              
45 2     2   1376 sub _build__logger_category { return ref $_[0] }
46              
47             1;
48              
49              
50             # vim: ts=4 sts=4 sw=4 et:
51              
52             __END__