blib/lib/Sys/Syslog/OO.pm

filter: Statementstmt 26.8% 11 / 41 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 3 / 12 Podpod 0.0% 0 / 9 totaltotal 18.6% 14 / 75 CC 6 SCAR 27.7
CC
6
Cov
21%
new
42.0
debug
2.0
verbose
2.0
CRAP 15.9
↑ Summary
1 package Sys::Syslog::OO;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Sys::Syslog qw(:DEFAULT setlogsock);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '1.00';
8  
9 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod undocumented
10  
11 0 my ($class, $opts) = (@_);
12  
13 0 ▶ croak "Sys::Syslog::OO - Must pass in a hash ref of options!"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts eq "HASH" 0 0 0
14 unless ref($opts) eq 'HASH';
15  
16 croak "Sys::Syslog::OO - Missing logging facility!"
17 0 ▶ if ! defined $opts->{'facility'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"facility"} 0 0 0
18  
19 0 my $label = "";
20  
21 0 ▶ if (exists $opts->{'label'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'label'}) { } 0 0 0
22 0 $label = $opts->{'label'};
23 }
24 else {
25 0 $label = $0;
26 0 $label =~ s#.*/##;
27 }
28  
29 0 ▶ if ((exists $opts->{'host'}->{'ip'}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'host'}{'ip'} and defined $opts->{'host'}{'ip'}) { } 0 0 0
Condition0%0/3
exists $opts->{"host"}{"ip"} and defined $opts->{"host"}{"ip"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"host"}{"ip"} and defined $opts->{"host"}{"ip"}
exists $opts->{"host"}{"ip"} defined $opts->{"host"}{"ip"}
Truth table0%0/3
A and B
A= exists $opts->{"host"}{"ip"}B= defined $opts->{"host"}{"ip"}
ABresult
0X0
100
111
30 (defined $opts->{'host'}->{'ip'})) {
31  
32 0 setlogsock($opts->{'host'}->{'proto'});
33 0 $Sys::Syslog::host = $opts->{'host'}->{'ip'};
34 0 openlog($label, 'ndelay pid', $opts->{'facility'});
35  
36 }
37 else {
38 0 openlog($label, 'pid', $opts->{'facility'});
39 }
40  
41 0 return bless $opts, $class;
42  
43 }
44  
45 0 ▶sub debug {
Subroutine debug: not called CC=1 SCAR=6.9
Pod undocumented
46 0 my ($self, $msg) = @_;
47 0 $self->logger('debug', $msg);
48 }
49  
50 0 ▶sub verbose {
Subroutine verbose: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my ($self, $msg) = @_;
52 0 $self->info($msg);
53 }
54  
55 0 ▶sub info {
Subroutine info: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ($self, $msg) = @_;
57 0 $self->logger('info', $msg);
58 }
59  
60 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my ($self, $msg) = @_;
62 0 $self->logger('err', $msg);
63 }
64  
65 0 ▶sub warn {
Subroutine warn: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my ($self, $msg) = @_;
67 0 $self->logger('warn', $msg);
68 }
69  
70 0 ▶sub notice {
Subroutine notice: not called CC=1 SCAR=6.9
Pod undocumented
71 0 my ($self, $msg) = @_;
72 0 $self->logger('notice', $msg);
73 }
74  
75 0 ▶sub alert {
Subroutine alert: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my ($self, $msg) = @_;
77 0 $self->logger('alert', $msg);
78 }
79  
80 0 ▶sub logger {
Subroutine logger: not called CC=1 SCAR=6.9
Pod undocumented
81 0 my ($self, $level, $msg) = (@_);
82 0 syslog("${level}|$self->{'facility'}", '%s', "\U$level\E $msg");
83  
84 }
85  
86 1 1;
87  
88 =pod
89  
90 =head1 NAME
91  
92 Sys::Syslog::OO - Thin object-oriented wrapper around Sys::Syslog::OO
93  
94 =head1 SYNOPSIS
95  
96 package My::Cool::Package;
97  
98 use Sys::Syslog::OO;
99 use base qw(Sys::Syslog::OO);
100  
101 sub new {
102  
103 my ($class, $cfg) = @_;
104  
105 my $facility = 'LOG_LOCAL7';
106  
107 if (exists $cfg->{'syslog_facility'}) {
108 $facility = $cfg->{'syslog_facility'};
109 }
110  
111 my $self = $class->SUPER::new({'label' => 'mycoolprogram',
112 'facility' => $facility });
113 # ... other initialization code ...
114  
115 return $self;
116 }
117  
118 =head1 DESCRIPTION
119  
120 Thin OO-wrapper around Sys::Syslog. Why? Less chance of mis-typing
121 log levels and less noisy code. Can also be used with multiple-inheritence
122 to add logging to a new or existing class.
123  
124 =head1 THANKS
125  
126 Special thanks to Mike Fischer, Jason Livingood, and Comcast for allowing
127 me to contribute this code to the OSS community.
128  
129 =head1 AUTHOR
130  
131 Max Schubert E<lt>maxschube@cpan.orgE<gt>
132  
133 =head1 COPYRIGHT
134  
135 Copyright (C) 2009 by Max Schubert / Comcast
136  
137 This library is free software; you can redistribute it and/or modify
138 it under the same terms as Perl itself, either Perl version 5.8.8 or,
139 at your option, any later version of Perl 5 you may have available.
140  
141 =cut
↑ Summary