lib/POE/Component/MessageQueue/Logger.pm

filter: Statementstmt 77.2% 17 / 22 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 71.0% 27 / 38 CC 6 SCAR 15.4
CC
6
Cov
72%
log
7.1
shutdown
2.3
BEGIN
1.0
CRAP 4.7
« lib/POE/Component/MessageQueue/Storage/BigMemory.pm ↑ Summary lib/POE/Component/MessageQueue/Storage/Memory.pm »
1 #
2 # Copyright 2007-2010 David Snopek <dsnopek@gmail.com>
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17  
18 package POE::Component::MessageQueue::Logger;
19 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 27 ▶use POE::Kernel;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 27 my $LEVELS = {
23 debug => 0,
24 info => 1,
25 notice => 2,
26 warning => 3,
27 error => 4,
28 critical => 5,
29 alert => 6,
30 emergency => 7
31 };
32  
33 27 has 'level' => (
34 is => 'rw',
35 default => 3,
36 );
37  
38 27 has 'logger_alias' => (
39 is => 'rw',
40 writer => 'set_logger_alias',
41 predicate => 'has_logger_alias',
42 );
43  
44 27 has 'log_function' => (
45 is => 'rw',
46 writer => 'set_log_function',
47 predicate => 'has_log_function',
48 );
49  
50 sub log
51 {
52 8666 ▶ my ($self, $type, $msg) = @_;
Subroutine log: called CC=5 SCAR=19.6
Pod undocumented
53  
54 8666 ▶ if ( not defined $msg )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $msg) 0 8666 8666
55 {
56 0 $msg = $type;
57 0 $type = 'info';
58 }
59  
60 8666 ▶ if ( $self->has_log_function )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->has_log_function) { } 162 8504 8666
elsif ($self->has_logger_alias) { } 0 8504 8504
elsif ($LEVELS->{$type} >= $self->level) { } 0 8504 8504
61 {
62 162 $self->log_function->( $type, $msg );
63 }
64 elsif ( $self->has_logger_alias )
65 {
66 0 $poe_kernel->post($self->logger_alias, $type, "$msg\n" );
67 }
68 elsif ($LEVELS->{$type} >= $self->level )
69 {
70 0 print STDERR "$msg\n";
71 }
72 }
73  
74 sub shutdown
75 {
76 4 ▶ my $self = shift;
Subroutine shutdown: called CC=2 SCAR=8.1
Pod undocumented
77  
78 4 ▶ if ($self->has_logger_alias)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_logger_alias) 0 4 4
79 {
80 0 $poe_kernel->signal( $self->logger_alias, 'TERM' );
81 }
82 }
83  
84 27 1;
85  
« lib/POE/Component/MessageQueue/Storage/BigMemory.pm ↑ Summary lib/POE/Component/MessageQueue/Storage/Memory.pm »