lib/POE/Component/MessageQueue/Logger.pm

filter: Statementstmt 68.1% 15 / 22 Branchbran 20.0% 2 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 0.0% 0 / 2 totaltotal 52.6% 20 / 38 CC 6 SCAR 20.4
CC
6
Cov
53%
log
11.1
shutdown
6.0
BEGIN
1.0
CRAP 7.7
« lib/POE/Component/MessageQueue/Statistics/Publish/YAML.pm ↑ Summary lib/POE/Component/MessageQueue/Storage/Throttled.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 23 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 23 ▶use POE::Kernel;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 23 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 23 has 'level' => (
34 is => 'rw',
35 default => 3,
36 );
37  
38 23 has 'logger_alias' => (
39 is => 'rw',
40 writer => 'set_logger_alias',
41 predicate => 'has_logger_alias',
42 );
43  
44 23 has 'log_function' => (
45 is => 'rw',
46 writer => 'set_log_function',
47 predicate => 'has_log_function',
48 );
49  
50 sub log
51 {
52 162 ▶ my ($self, $type, $msg) = @_;
Subroutine log: called CC=5 SCAR=24.1
Pod undocumented
53  
54 162 ▶ if ( not defined $msg )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $msg) 0 162 162
55 {
56 0 $msg = $type;
57 0 $type = 'info';
58 }
59  
60 162 ▶ if ( $self->has_log_function )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->has_log_function) { } 162 0 162
elsif ($self->has_logger_alias) { } 0 0 0
elsif ($LEVELS->{$type} >= $self->level) { } 0 0 0
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 0 ▶ my $self = shift;
Subroutine shutdown: not called CC=2 SCAR=17.9
Pod undocumented
77  
78 0 ▶ if ($self->has_logger_alias)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_logger_alias) 0 0 0
79 {
80 0 $poe_kernel->signal( $self->logger_alias, 'TERM' );
81 }
82 }
83  
84 23 1;
85  
« lib/POE/Component/MessageQueue/Statistics/Publish/YAML.pm ↑ Summary lib/POE/Component/MessageQueue/Storage/Throttled.pm »