blib/lib/POE/Component/Logger.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 2 / 2 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 52 / 52 CC 3 SCAR 2.9
CC
3
Cov
100%
_start_logger
2.0
_poe_log
2.0
BEGIN
1.0
CRAP 1.3
↑ Summary
1 package POE::Component::Logger;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Log::Dispatch::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use vars qw($VERSION $DefaultLevel);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 $VERSION = '1.10';
10  
11 4 $DefaultLevel = 'warning';
12  
13 3 ▶sub spawn {
Subroutine spawn: called CC=1 SCAR=0.0
Pod documented
14 3 my $class = shift;
15 POE::Session->create(
16 inline_states => {
17 _start => \&_start_logger,
18 _stop => \&_stop_logger,
19  
20 # Log at the $DefaultLevel
21 4 ▶ log => sub { my @args = @_; $args[STATE] = $DefaultLevel; _poe_log(@args) },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 # Log at a specific level
23 3 debug => \&_poe_log,
24 info => \&_poe_log,
25 notice => \&_poe_log,
26 warning => \&_poe_log,
27 error => \&_poe_log,
28 critical => \&_poe_log,
29 alert => \&_poe_log,
30 emergency => \&_poe_log,
31 },
32 args => [ @_ ],
33 );
34 }
35  
36 3 ▶sub _start_logger {
Subroutine _start_logger: called CC=2 SCAR=6.9
37 3 my ($kernel, $heap, %args) = @_[KERNEL, HEAP, ARG0 .. $#_];
38  
39 3 ▶ $args{Alias} ||= 'logger';
Condition100%2/2
$args{"Alias"} ||= "logger"
l!l
12
MC/DC100%1/1
$args{"Alias"} ||= "logger"
$args{"Alias"}
Truth table100%2/2
A
A= $args{"Alias"}
Aresult
11
00
40  
41 3 Log::Dispatch::Config->configure($args{ConfigFile});
42  
43 3 $heap->{_logger} = Log::Dispatch::Config->instance;
44 3 $heap->{_alias} = $args{Alias};
45 3 $kernel->alias_set($args{Alias});
46 }
47  
48 3 ▶sub _stop_logger {
Subroutine _stop_logger: called CC=1 SCAR=0.0
49 3 my ($kernel, $heap) = @_[KERNEL, HEAP];
50  
51 3 $kernel->alias_remove($heap->{_alias});
52 3 delete $heap->{_logger};
53 }
54  
55  
56 27 ▶sub _poe_log {
Subroutine _poe_log: called CC=2 SCAR=6.9
57 27 my ($heap, $level, $arg0, @args) = @_[HEAP, STATE, ARG0..$#_];
58  
59 $heap->{_logger}->log(
60 # The default level is the POE event name ($_[STATE])
61 # (may be overriden in given hashref)
62 level => $level,
63 # If we get a HASHREF, expand it
64 # If we get a scalar, concatenate args as the message
65 27 ▶ (ref $arg0) ? (%{$arg0})
Branch: 1 branch
BranchTrueFalseTotal
ref $arg0 ? : 7 20 27
66 : (message => join('', $arg0, @args))
67 );
68 }
69  
70  
71 12 ▶sub log {
Subroutine log: called CC=1 SCAR=0.0
Pod documented
72 12 my ($class, @args) = @_;
73 12 POE::Kernel->post(logger => $DefaultLevel => @args);
74 }
75  
76 4 *Logger::log = \&log;
77  
78 4 1;
79 __END__
↑ Summary