Dispatch/Syslog.pm

filter: Statementstmt 87.9% 51 / 58 Branchbran 37.5% 6 / 16 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 71.1% 69 / 97 CC 11 SCAR 14.1
CC
11
Cov
72%
log_message
6.8
new
6.7
__ANON__
4.4
CRAP 4.1
« Dispatch/Email.pm ↑ Summary Dispatch.pm »
1 package Log::Dispatch::Syslog;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '2.71';
7  
8 2 ▶use Log::Dispatch::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Params::ValidationCompiler qw( validation_for );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Sys::Syslog 0.28 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use base qw( Log::Dispatch::Output );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 my $thread_lock;
17  
18 {
19 2 my ($DefaultIdent) = $0 =~ /(.+)/;
20  
21 2 my $validator = validation_for(
22 params => {
23 ident => {
24  
25 # It's weird to allow an empty string but that's how this
26 # worked pre-PVC.
27 type => t('Str'),
28 default => $DefaultIdent
29 },
30 logopt => {
31 type => t('Str'),
32 default => q{},
33 },
34 facility => {
35 type => t('NonEmptyStr'),
36 default => 'user'
37 },
38 socket => {
39 type => t('SyslogSocket'),
40 default => undef,
41 },
42 lock => {
43 type => t('Bool'),
44 default => 0,
45 },
46 },
47 slurpy => 1,
48 );
49  
50 2 my $threads_loaded;
51  
52 3 ▶ sub new {
Subroutine new: called CC=4 SCAR=19.1
Pod undocumented
53 3 my $class = shift;
54 3 my %p = $validator->(@_);
55  
56 3 my $self = bless { map { $_ => delete $p{$_} }
57 qw( ident logopt facility socket lock ) },
58 $class;
59  
60 3 ▶ if ( $self->{lock} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lock"}) 0 3 3
61 0 ▶ unless ($threads_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($threads_loaded) 0 0 0
62 0 local ( $@, $SIG{__DIE__} ) = ( undef, undef );
63  
64 ## no critic (BuiltinFunctions::ProhibitStringyEval)
65 # These need to be loaded with use, not require.
66 0 ▶ die $@ unless eval 'use threads; use threads::shared; 1;';
Branch: 1 branch
BranchTrueFalseTotal
unless eval "use threads; use threads::shared; 1;" 0 0 0
67 0 $threads_loaded = 1;
68 }
69 0 &threads::shared::share( \$thread_lock );
70 }
71  
72 3 $self->_basic_init(%p);
73  
74 3 return $self;
75 }
76 }
77  
78 {
79 2 my @priorities = (
80 'DEBUG',
81 'INFO',
82 'NOTICE',
83 'WARNING',
84 'ERR',
85 'CRIT',
86 'ALERT',
87 'EMERG',
88 );
89  
90 3 ▶ sub log_message {
Subroutine log_message: called CC=5 SCAR=19.1
Pod undocumented
91 3 my $self = shift;
92 3 my %p = @_;
93  
94 3 my $pri = $self->_level_as_number( $p{level} );
95  
96 3 ▶ lock($thread_lock) if $self->{lock};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lock"} 0 3 3
97  
98 return
99 3 ▶ if try {
Subroutine __ANON__: called CC=4 SCAR=14.8
100 3 ▶ if ( defined $self->{socket} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"socket"}) 2 1 3
101 Sys::Syslog::setlogsock(
102 ref $self->{socket}
103 && reftype( $self->{socket} ) eq 'ARRAY'
104 0 ? @{ $self->{socket} }
105 : $self->{socket}
106 2 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'socket'} && builtin::reftype($self->{'socket'}) eq 'ARRAY' ? : 0 2 2
Condition33%1/3
ref $self->{"socket"} and builtin::reftype($self->{"socket"}) eq "ARRAY"
!ll&&!rl&&r
020
MC/DC0%0/2
ref $self->{"socket"} and builtin::reftype($self->{"socket"}) eq "ARRAY"
ref $self->{"socket"} builtin::reftype($self->{"socket"}) eq "ARRAY"
Truth table33%1/3
A and B
A= ref $self->{"socket"}B= builtin::reftype($self->{"socket"}) eq "ARRAY"
ABresult
0X0
100
111
107 }
108  
109 Sys::Syslog::openlog(
110 $self->{ident},
111 $self->{logopt},
112 $self->{facility}
113 3 );
114 3 Sys::Syslog::syslog( $priorities[$pri], $p{message} );
115 3 Sys::Syslog::closelog();
116  
117 3 1;
118 3 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
if &try(sub { if (defined $self->{"socket"}) { Sys::Syslog::setlogsock(ref $self->{"socket"} && builtin::reftype($self->{"socket"}) eq "ARRAY" ? @{$$self{"socket"};} : $self->{"socket"}); } ; Sys::Syslog::openlog($self->{"ident"}, $self->{"logopt"}, $self->{"facility"}); Sys::Syslog::syslog($priorities[$pri], $p{"message"}); Sys::Syslog::closelog(); 1; } ) 3 0 3
119  
120 0 ▶ warn $@ if $@ and $^W;
Branch: 1 branch
BranchTrueFalseTotal
if $@ and $^W 0 0 0
Condition0%0/3
$@ and $^W
!ll&&!rl&&r
000
MC/DC0%0/2
$@ and $^W
$@ $^W
Truth table0%0/3
A and B
A= $@B= $^W
ABresult
0X0
100
111
121 }
122 }
123  
124 2 1;
125  
126 # ABSTRACT: Object for logging to system log.
127  
128 __END__
« Dispatch/Email.pm ↑ Summary Dispatch.pm »