Agent/Driver/Default.pm

filter: Statementstmt 78.5% 44 / 56 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 76.9% 10 / 13 Podpod 100% 11 / 11 totaltotal 80.4% 70 / 87 CC 3 SCAR 4.7
CC
3
Cov
79%
prefix_msg
3.0
channel_eq
2.0
logconfess
2.0
CRAP 1.6
« Agent/Tag.pm ↑ Summary Agent/Driver/Silent.pm »
1 ###########################################################################
2 #
3 # Default.pm
4 #
5 # Copyright (C) 1999 Raphael Manfredi.
6 # Copyright (C) 2002-2017 Mark Rogaski, mrogaski@cpan.org;
7 # all rights reserved.
8 #
9 # See the README file included with the
10 # distribution for license information.
11 #
12 ##########################################################################
13  
14 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 require Log::Agent::Driver;
16  
17 ########################################################################
18 package Log::Agent::Driver::Default;
19  
20 6 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 6 @ISA = qw(Log::Agent::Driver);
23  
24 #
25 # ->make -- defined
26 #
27 # Creation routine.
28 #
29 6 ▶sub make {
Subroutine make: called CC=1 SCAR=0.0
Pod documented
30 6 my $self = bless {}, shift;
31 6 my ($prefix) = @_;
32 6 $self->_init($prefix, 0); # 0 is the skip Carp penalty
33 6 select((select(main::STDERR), $| = 1)[0]); # Autoflush
34 6 return $self;
35 }
36  
37 #
38 # ->prefix_msg -- defined
39 #
40 # Prepend "prefix: " to the error string, or nothing if no prefix, in which
41 # case we capitalize the very first letter of the string.
42 #
43 33 ▶sub prefix_msg {
Subroutine prefix_msg: called CC=3 SCAR=11.0
Pod documented
44 33 my $self = shift;
45 33 my ($str) = @_;
46 33 my $prefix = $self->prefix;
47 33 ▶ return ucfirst($str) if !defined($prefix) || $prefix eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $prefix or $prefix eq "" 21 12 33
Condition66%2/3
not defined $prefix or $prefix eq ""
l!l&&r!l&&!r
21012
MC/DC50%1/2
not defined $prefix or $prefix eq ""
not defined $prefix $prefix eq ""
Truth table66%2/3
not(A) or B
A= not defined $prefixB= $prefix eq ""
ABresult
1X1
011
000
48 12 return "$prefix: " . $str;
49 }
50  
51 #
52 # ->write -- defined
53 #
54 11 ▶sub write {
Subroutine write: called CC=1 SCAR=0.0
Pod documented
55 11 my $self = shift;
56 11 my ($channel, $priority, $logstring) = @_;
57 11 local $\ = undef;
58 11 print main::STDERR "$logstring\n";
59 }
60  
61 #
62 # ->channel_eq -- defined
63 #
64 # All channels equals here
65 #
66 0 ▶sub channel_eq {
Subroutine channel_eq: not called CC=1 SCAR=6.9
Pod documented
67 0 my $self = shift;
68 0 return 1;
69 }
70  
71 #
72 # ->logconfess -- redefined
73 #
74 # Fatal error, with stack trace
75 #
76 0 ▶sub logconfess {
Subroutine logconfess: not called CC=1 SCAR=6.9
Pod documented
77 0 my $self = shift;
78 0 my ($str) = @_;
79 0 require Carp;
80 0 my $msg = $self->carpmess(0, $str, \&Carp::longmess);
81 0 die $self->prefix_msg("$msg\n");
82 }
83  
84 #
85 # ->logcluck -- redefined
86 #
87 # Warning, with stack trace
88 #
89 0 ▶sub logcluck {
Subroutine logcluck: not called CC=1 SCAR=6.9
Pod documented
90 0 my $self = shift;
91 0 my ($str) = @_;
92 0 require Carp;
93 0 my $msg = $self->carpmess(0, $str, \&Carp::longmess);
94 0 warn $self->prefix_msg("$msg\n");
95 }
96  
97 #
98 # ->logxcroak -- redefined
99 #
100 # Fatal error, from perspective of caller
101 #
102 1 ▶sub logxcroak {
Subroutine logxcroak: called CC=1 SCAR=0.0
Pod documented
103 1 my $self = shift;
104 1 my ($offset, $str) = @_;
105 1 require Carp;
106 1 my $msg = $self->carpmess($offset, $str, \&Carp::shortmess);
107 1 die $self->prefix_msg("$msg\n");
108 }
109  
110 #
111 # ->logdie -- redefined
112 #
113 # Fatal error
114 #
115 8 ▶sub logdie {
Subroutine logdie: called CC=1 SCAR=0.0
Pod documented
116 8 my $self = shift;
117 8 my ($str) = @_;
118 8 die $self->prefix_msg("$str\n");
119 }
120  
121 #
122 # ->logerr -- redefined
123 #
124 # Signal error on stderr
125 #
126 2 ▶sub logerr {
Subroutine logerr: called CC=1 SCAR=0.0
Pod documented
127 2 my $self = shift;
128 2 my ($str) = @_;
129 2 warn $self->prefix_msg("$str\n");
130 }
131  
132 #
133 # ->logwarn -- redefined
134 #
135 # Warn, with "WARNING" clearly emphasized
136 #
137 1 ▶sub logwarn {
Subroutine logwarn: called CC=1 SCAR=0.0
Pod documented
138 1 my $self = shift;
139 1 my ($str) = @_;
140 1 $str->prepend("WARNING: ");
141 1 warn $self->prefix_msg("$str\n");
142 }
143  
144 #
145 # ->logxcarp -- redefined
146 #
147 # Warn from perspective of caller, with "WARNING" clearly emphasized.
148 #
149 11 ▶sub logxcarp {
Subroutine logxcarp: called CC=1 SCAR=0.0
Pod documented
150 11 my $self = shift;
151 11 my ($offset, $str) = @_;
152 11 $str->prepend("WARNING: ");
153 11 require Carp;
154 11 my $msg = $self->carpmess($offset, $str, \&Carp::shortmess);
155 11 warn $self->prefix_msg("$msg\n");
156 }
157  
158 6 1; # for require
159 __END__
« Agent/Tag.pm ↑ Summary Agent/Driver/Silent.pm »