| 1 | package Log::Any::Adapter::Daemontools::Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 29 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 29 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Dynamic configuration settings used by Daemontools logging adapters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 29 | our $VERSION = '0.102'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 29 | ▶ | use Log::Any::Adapter::Util 'numeric_level', ':levels'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # At top of file where lexical scope is the cleanest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 53 | ▶ | sub _build_writer_eval_in_clean_scope { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_writer_eval_in_clean_scope: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Args: $self, $code, \$err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 53 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 53 | my $output= $_[0]->output; # Needs to be in scope | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 53 | my $format= $_[0]->format; # of the eval | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 53 | my $coderef= eval $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 53 | ▶ | ${ $_[2] }= $@ if defined $_[0]; # Save error because $@ is localized | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 53 | return $coderef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 29 | ▶ | use Scalar::Util 'weaken', 'refaddr'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Lazy-load carp, and also remove any Log::Any infrastructure from the trace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 29 | our @CARP_NOT= qw( Log::Any::Adapter::Base Log::Any::Adapter Log::Any::Proxy Log::Any ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | sub _carp_exclude { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_carp_exclude: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | my $i= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | ++$i while caller($i) =~ /^Log::Any/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | return $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | sub carp { require Carp; local $Carp::CarpLevel= _carp_exclude; &Carp::carp; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
carp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub croak { require Carp; local $Carp::CarpLevel= _carp_exclude; &Carp::croak; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
croak: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 29 | my (%log_level_name, %log_level_num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 29 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 29 | %log_level_num= ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | none => EMERGENCY-1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | emergency => EMERGENCY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | alert => ALERT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | critical => CRITICAL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | error => ERROR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | warning => WARNING, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | notice => NOTICE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | info => INFO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | debug => DEBUG, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | trace => TRACE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | all => TRACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 29 | %log_level_name= reverse %log_level_num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # Add the aliases to the name-to-value mapping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 29 | my %aliases= Log::Any::Adapter::Util::log_level_aliases(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 29 | for (keys %aliases) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 145 | $log_level_num{$_}= $log_level_num{ $aliases{$_} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 42 | ▶ | sub _parse_log_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_log_level: called CC=8 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 42 | my ($spec, $base, $min, $max)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | my $lev= $spec =~ /^-?\d+$/? $spec # plain level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | : $spec =~ /^([-+])= (-?\d+)$/? $base + "${1}1" * $2 # += notation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 42 | ▶ | : $log_level_num{$spec}; # else a level name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 42 | ▶ | defined $lev or croak "Invalid log level '$spec'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 42 | ▶ | $min= EMERGENCY-1 unless defined $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 42 | ▶ | $lev= $min unless $lev >= $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 42 | ▶ | $max= TRACE unless defined $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 42 | ▶ | $lev= $max unless $lev <= $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 42 | return $lev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 45 | ▶ | sub log_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_level: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 45 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 45 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 42 | ▶ | croak "extra arguments" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 42 | my $l= _parse_log_level($_[0], $self->{log_level_num}, $self->{log_level_min_num}, $self->{log_level_max_num}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # If log level changes, reset the cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 42 | ▶ | if ($l != $self->{log_level_num}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 37 | $self->{log_level_num}= $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 37 | $self->_reset_cached_adapters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 45 | $log_level_name{ $self->{log_level_num} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub log_level_min { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_level_min: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | croak "extra arguments" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # If log level changes as a result, reset the cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->{log_level_min_num}= _parse_log_level($_[0], $self->{log_level_min_num}, EMERGENCY-1, $self->{log_level_max_num}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($self->{log_level_min_num} > $self->{log_level_num}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->{log_level_num}= $self->{log_level_min_num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->_reset_cached_adapters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $log_level_name{ $self->{log_level_min_num} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub log_level_max { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_level_max: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | croak "extra arguments" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $self->{log_level_max_num}= _parse_log_level($_[0], $self->{log_level_max_num}, $self->{log_level_min_num}, TRACE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # If log level changes as a result, reset the cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ($self->{log_level_max_num} < $self->{log_level_num}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->{log_level_num}= $self->{log_level_max_num}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->_reset_cached_adapters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $log_level_name{ $self->{log_level_max_num} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 139 | ▶ | sub output { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output: called CC=9 SCAR=22.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 139 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 139 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | ▶ | croak "extra arguments" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | ▶ | defined $_[0] && (ref $_[0] eq 'GLOB' || ref $_[0] eq 'CODE' || ref($_[0])->can('print')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
defined $_[0] and ref $_[0] eq "GLOB" || ref $_[0] eq "CODE" || ref($_[0])->can("print")
ref $_[0] eq "GLOB" or ref $_[0] eq "CODE" or ref($_[0])->can("print")
ref $_[0] eq "GLOB" or ref $_[0] eq "CODE"
MC/DC0%0/4
defined $_[0] and ref $_[0] eq "GLOB" || ref $_[0] eq "CODE" || ref($_[0])->can("print")
defined $_[0]
ref $_[0] eq "GLOB"
ref $_[0] eq "CODE"
ref($_[0])->can("print")
Truth table60%3/5
A and B or C or D
A= defined $_[0]B= ref $_[0] eq "GLOB"C= ref $_[0] eq "CODE"D= ref($_[0])->can("print")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | or croak "Argument must be file handle or coderef"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 6 | $self->{output}= $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | delete $self->{_writer_cache}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | ▶ | $self->_reset_cached_adapters unless $self->{writer}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 139 | ▶ | return defined $self->{output}? $self->{output} : \*STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 107 | ▶ | sub format { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format: called CC=11 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 107 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 107 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 14 | ▶ | @_ == 1 && defined $_[0] && (!ref $_[0] or ref $_[0] eq 'CODE') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
@_ == 1 and defined $_[0] and !ref($_[0]) || ref $_[0] eq "CODE"
@_ == 1 and defined $_[0]
not ref $_[0] or ref $_[0] eq "CODE"
MC/DC0%0/4
@_ == 1 and defined $_[0] and !ref($_[0]) || ref $_[0] eq "CODE"
@_ == 1
defined $_[0]
not ref $_[0]
ref $_[0] eq "CODE"
Truth table40%2/5
A and B and not(C) or D
A= @_ == 1B= defined $_[0]C= not ref $_[0]D= ref $_[0] eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | or croak "Expected string or coderef"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 14 | ▶ | if (!ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # Test their supplied code right away, so the error happens in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # place where its easy to fix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 13 | my $x= $self->_build_writer_eval_in_clean_scope( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | "sub { " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | .' my ($category, $level, $level_prefix, $file, $file_brief, $line, $package);' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ." $_[0]; " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ."}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | \my $err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 13 | ▶ | defined $x && ref $x eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $x and ref $x eq "CODE"
MC/DC0%0/2
defined $x and ref $x eq "CODE"
defined $x
ref $x eq "CODE"
Truth table33%1/3
A and B
A= defined $xB= ref $x eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | or croak "Invalid format (make sure you wrote *code* that returns a string): $err"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 14 | $self->{format}= $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 14 | delete $self->{_writer_cache}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 14 | ▶ | $self->_reset_cached_adapters unless $self->{writer}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 107 | ▶ | defined $self->{format}? $self->{format} : '"$level_prefix$_\n"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | sub writer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writer: called CC=5 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | @_ == 1 && (!defined $_[0] || ref $_[0] eq 'CODE') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@_ == 1 and !defined($_[0]) || ref $_[0] eq "CODE"
not defined $_[0] or ref $_[0] eq "CODE"
MC/DC0%0/3
@_ == 1 and !defined($_[0]) || ref $_[0] eq "CODE"
@_ == 1
not defined $_[0]
ref $_[0] eq "CODE"
Truth table25%1/4
A and not(B) or C
A= @_ == 1B= not defined $_[0]C= ref $_[0] eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | or croak "Expected coderef or undef"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | $self->{writer}= $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | $self->_reset_cached_adapters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Yes, I should use Moo, but in the spirit of Log::Any having no non-core deps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # I decided to do the same. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 31 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 31 | my $class= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 31 | my $self= bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | log_level_num => INFO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | log_level_min_num => EMERGENCY-1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | log_level_max_num => TRACE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Convert hashref to plain key/value list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | unshift @_, %{ shift @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | if @_ == 1 && ref $_[0] eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # Iterate key/value pairs and call the accessor method for each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 31 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my ($k, $v)= (shift, shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $self->$k($v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 31 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 29 | our (%env_profile, %argv_profile); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 29 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 29 | $env_profile{1}= { debug => 'DEBUG' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 29 | $argv_profile{1}= { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | bundle => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | verbose => qr/^(--verbose|-v)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | quiet => qr/^(--quiet|-q)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | stop => '--' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | $argv_profile{consume}= { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 29 | bundle => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | verbose => qr/^(--verbose|-v)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | quiet => qr/^(--quiet|-q)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | stop => '--', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | remove => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 29 | my %_init_args= map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | level log_level min level_min log_level_min max level_max log_level_max | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | env argv signals handle_signals install_signal_handlers format out output writer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 21 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=27 SCAR=38.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 21 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 21 | ▶ | my $cfg= (@_ == 1 and ref $_[0] eq 'HASH')? $_[0] : { @_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Warn on unknown arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 21 | my @unknown= grep { !$_init_args{$_} } keys %$cfg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 21 | ▶ | carp "Invalid arguments: ".join(', ', @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | defined $cfg->{$_} and $self->log_level($cfg->{$_}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 21 | ▶ | for qw: level log_level :; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | defined $cfg->{$_} and $self->log_level_min($cfg->{$_}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 21 | ▶ | for qw: min level_min log_level_min :; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | defined $cfg->{$_} and $self->log_level_max($cfg->{$_}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 21 | ▶ | for qw: max level_max log_level_max :; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # Optional ENV processing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | defined $cfg->{$_} and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $v= $cfg->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | $self->process_env( %{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | ref $v eq 'HASH'? $v : $env_profile{$v} || croak "Unknown \"$_\" value $v" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$Log::Any::Adapter::Daemontools::Config::env_profile{$v} or croak(qq[Unknown "$_" value $v])
MC/DC0%0/1
$Log::Any::Adapter::Daemontools::Config::env_profile{$v} or croak(qq[Unknown "$_" value $v])
$Log::Any::Adapter::Daemontools::Config::env_profile{$v}
Truth table0%0/2
A
A= $Log::Any::Adapter::Daemontools::Config::env_profile{$v}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 21 | ▶ | } for qw: env process_env :; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # Optional ARGV parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | defined $cfg->{$_} and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 6 | my $v= $cfg->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | $self->process_argv( %{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 6 | ▶ | ref $v eq 'HASH'? $v : $argv_profile{$v} || croak "Unknown \"$_\" value $v" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$Log::Any::Adapter::Daemontools::Config::argv_profile{$v} or croak(qq[Unknown "$_" value $v])
MC/DC0%0/1
$Log::Any::Adapter::Daemontools::Config::argv_profile{$v} or croak(qq[Unknown "$_" value $v])
$Log::Any::Adapter::Daemontools::Config::argv_profile{$v}
Truth table50%1/2
A
A= $Log::Any::Adapter::Daemontools::Config::argv_profile{$v}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 21 | ▶ | } for qw: argv process_argv :; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # Optional installation of signal handlers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | defined $cfg->{$_} and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | ▶ | my $rt= ref($cfg->{$_}) || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $cfg->{$_} || ''
MC/DC0%0/1
ref $cfg->{$_} || ''
ref $cfg->{$_}
Truth table50%1/2
A
A= ref $cfg->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | $self->install_signal_handlers( %{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | $rt eq 'HASH'? $cfg->{$_} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | : $rt eq 'ARRAY'? { verbose => $cfg->{$_}[0], quiet => $cfg->{$_}[1] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | : croak "Unknown \"$_\" value $cfg->{$_}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 21 | ▶ | } for qw: signals handle_signals install_signal_handlers :; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | $self->format($cfg->{format}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 21 | ▶ | if defined $cfg->{format}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | defined $cfg->{$_} and $self->output($cfg->{$_}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 21 | ▶ | for qw: out output :; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | $self->writer($cfg->{writer}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 21 | ▶ | if defined $cfg->{writer}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 21 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # We lied. This is the actual attribute in the implementation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 73 | ▶ | sub log_level_num { shift->{log_level_num} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_level_num: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub log_level_min_num { shift->{log_level_min_num} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_level_min_num: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub log_level_max_num { shift->{log_level_max_num} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_level_max_num: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 12 | ▶ | sub log_level_adjust { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_level_adjust: called CC=4 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 12 | my ($self, $offset)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 12 | ▶ | defined $offset && ($offset =~ /^-?\d+$/) && @_ == 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $offset and $offset =~ /^-?\d+$/ and @_ == 2
defined $offset and $offset =~ /^-?\d+$/
MC/DC0%0/3
defined $offset and $offset =~ /^-?\d+$/ and @_ == 2
defined $offset
$offset =~ /^-?\d+$/
@_ == 2
Truth table25%1/4
A and B and C
A= defined $offsetB= $offset =~ /^-?\d+$/C= @_ == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | or die "Expected offset integer"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 12 | $self->log_level( $self->log_level_num + $offset ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 29 | my %_process_env_args= ( debug => 1, log_level => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 11 | ▶ | sub process_env { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_env: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 11 | my ($self, %spec)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # Warn on unknown arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 11 | my @unknown= grep { !$_process_env_args{$_} } keys %spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 11 | ▶ | carp "Invalid arguments: ".join(', ', @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 11 | ▶ | if (defined $spec{log_level} && defined $ENV{$spec{log_level}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $spec{"log_level"} and defined $ENV{$spec{"log_level"}}
MC/DC50%1/2
defined $spec{"log_level"} and defined $ENV{$spec{"log_level"}}
defined $spec{"log_level"}
defined $ENV{$spec{"log_level"}}
Truth table66%2/3
A and B
A= defined $spec{"log_level"}B= defined $ENV{$spec{"log_level"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 4 | $self->log_level($ENV{$spec{log_level}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 11 | ▶ | if (defined $spec{debug} && defined $ENV{$spec{debug}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $spec{"debug"} and defined $ENV{$spec{"debug"}}
MC/DC50%1/2
defined $spec{"debug"} and defined $ENV{$spec{"debug"}}
defined $spec{"debug"}
defined $ENV{$spec{"debug"}}
Truth table66%2/3
A and B
A= defined $spec{"debug"}B= defined $ENV{$spec{"debug"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 7 | $self->log_level( $self->debug_level_to_log_level($ENV{$spec{debug}}) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 7 | ▶ | sub debug_level_to_log_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug_level_to_log_level: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 7 | my ($class, $level)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | ▶ | $level+= 6 if $level =~ /^-?\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 7 | $level; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 29 | my %_process_argv_args= ( bundle => 1, verbose => 1, quiet => 1, stop => 1, array => 1, remove => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 12 | ▶ | sub process_argv { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_argv: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 12 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 12 | my $ofs= $self->parse_log_level_opts(array => \@ARGV, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 12 | ▶ | $self->log_level_adjust($ofs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | if $ofs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 218 | ▶ | sub _make_regex_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_regex_list: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 218 | ▶ | return () unless defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 212 | ▶ | return qr/^\Q$_[0]\E$/ unless ref $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 68 | ▶ | return map { _make_regex_list($_) } @{ $_[0] } if ref $_[0] eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 10 | ▶ | return $_[0] if ref $_[0] eq 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | croak "Not a regular expression, string, or array: $_[0]" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 102 | ▶ | sub _combine_regex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_combine_regex: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 102 | my @list= _make_regex_list(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 102 | ▶ | return @list == 0? qr/\0^/ # a regex that doesn't match anything | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | : @list == 1? $list[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 58 | : qr/@{[ join '|', @list ]}/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 34 | ▶ | sub parse_log_level_opts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_log_level_opts: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 34 | my ($class, %spec)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Warn on unknown arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 34 | my @unknown= grep !$_process_argv_args{$_}, keys %spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 34 | ▶ | carp "Invalid arguments: ".join(', ', @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 34 | ▶ | defined $spec{array} or croak "Parameter 'array' is required"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 34 | $spec{$_}= _combine_regex($spec{$_}) for qw( stop verbose quiet ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 34 | return _parse_log_level_opts( $spec{array}, \%spec ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 44 | ▶ | sub _parse_log_level_opts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_log_level_opts: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 44 | my ($array, $spec)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 44 | my $level_ofs= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 44 | ▶ | for (my $i= 0; $i < @$array; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 92 | ▶ | last if $array->[$i] =~ $spec->{stop}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 89 | ▶ | if ($array->[$i] =~ /^-[^-=][^-=]+$/ and $spec->{bundle}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$array->[$i] =~ /^-[^-=][^-=]+$/ and $spec->{"bundle"}
MC/DC100%2/2
$array->[$i] =~ /^-[^-=][^-=]+$/ and $spec->{"bundle"}
$array->[$i] =~ /^-[^-=][^-=]+$/
$spec->{"bundle"}
Truth table100%3/3
A and B
A= $array->[$i] =~ /^-[^-=][^-=]+$/B= $spec->{"bundle"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # Un-bundle the arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 10 | my @un_bundled= map "-$_", split //, substr($array->[$i], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 10 | my $len= @un_bundled; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # Then filter them as usual | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 10 | $level_ofs += _parse_log_level_opts(\@un_bundled, $spec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # Then re-bundle them, if altered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 10 | ▶ | if ($spec->{remove} && $len != @un_bundled) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$spec->{"remove"} and $len != @un_bundled
MC/DC50%1/2
$spec->{"remove"} and $len != @un_bundled
$spec->{"remove"}
$len != @un_bundled
Truth table66%2/3
A and B
A= $spec->{"remove"}B= $len != @un_bundled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | ▶ | if (@un_bundled) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | $array->[$i]= '-' . join('', map substr($_,1), @un_bundled); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 4 | splice( @$array, $i--, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | elsif ($array->[$i] =~ $spec->{verbose}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 34 | $level_ofs++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 34 | ▶ | splice( @$array, $i--, 1 ) if $spec->{remove}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | elsif ($array->[$i] =~ $spec->{quiet}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 22 | $level_ofs--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 22 | ▶ | splice( @$array, $i--, 1 ) if $spec->{remove}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 44 | return $level_ofs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 29 | my %_handle_signal_args= ( verbose => 1, quiet => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | ▶ | sub install_signal_handlers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
install_signal_handlers: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | my ($self, %spec)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # Warn on unknown arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | my @unknown= grep { !$_handle_signal_args{$_} } keys %spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ▶ | carp "Invalid arguments: ".join(', ', @unknown) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | ▶ | $SIG{ $spec{verbose} }= sub { $self->log_level_adjust(1); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | ▶ | if $spec{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | ▶ | $SIG{ $spec{quiet} }= sub { $self->log_level_adjust(-1); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | ▶ | if $spec{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 44 | ▶ | sub compiled_writer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compiled_writer: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 44 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 44 | ▶ | $self->{writer} || ($self->{_writer_cache} ||= $self->_build_writer_cache) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_writer_cache"} ||= $self->_build_writer_cache
MC/DC0%0/2
$self->{"_writer_cache"} ||= $self->_build_writer_cache
$self->{"_writer_cache"}
$self->_build_writer_cache
Truth table66%2/3
A ||= B
A= $self->{"_writer_cache"}B= $self->_build_writer_cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # This method combines the output and format settings into a writer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # It also ensures the output is using autoflush | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 40 | ▶ | sub _build_writer_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_writer_cache: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 40 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 40 | my $code= "sub { \n" . $self->_build_writer_code . "\n}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 40 | my $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 40 | ▶ | my $writer= $self->_build_writer_eval_in_clean_scope( $code, \$err ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | or croak "Compilation of log writer failed: $err\nSource code is: $code"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 40 | $self->_enable_autoflush($self->output); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 40 | return $writer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # separate from _build_writer_cache so that test cases (and maybe subclasses) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # can inspect the generated code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 40 | ▶ | sub _build_writer_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_writer_code: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 40 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 40 | my $format= $self->format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 40 | my $code= ' my ($adapter, $level, $message)= @_;'."\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | . ' $message =~ s/\n+$//;'."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 40 | ▶ | if ($format =~ /\$\{?category(\W|$)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | $code .= ' my $category= $adapter->category;'."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 40 | ▶ | if ($format =~ /\$\{?(package|file|line|file_brief)(\W|$)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | $code .= ' my ($package,$file,$line);'."\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | .' { my $i= 0; do { ($package, $file, $line)= caller(++$i) } while $package =~ /^Log::Any/; };'."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | ▶ | $code .= ' my $file_brief= $file;'."\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | .' $file_brief =~ s|.*[\\/]lib[\\/]||;'."\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | if $format =~ /\$\{?file_brief(\W|$)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 40 | ▶ | if ($format =~ /\$\{?level_prefix(\W|$)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 27 | $code .= ' my $level_prefix= ($level eq "info")? "" : "$level: ";'."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 40 | my $output= $self->output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 40 | ▶ | if (ref $output eq 'GLOB') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 36 | $code .= ' print $output ('; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } elsif (ref($output)->can('print')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 2 | $code .= ' $output->print('; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } elsif (ref $output eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | $code .= ' $output->('; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | croak "Unhandled type of output: $output"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 40 | ▶ | if (ref $format eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # Closure over '$format', rather than deparsing the coderef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | $code .= ' map {; $format->($adapter, $level) } split /\n/, $message)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 39 | $code .= ' map {; '.$format.' } split /\n/, $message)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 40 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 40 | ▶ | sub _enable_autoflush { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enable_autoflush: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 40 | my ($self, $thing)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # This module tries to be very backward-compatible, and not force people to use IO::Handle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # if they didn't intend to... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 40 | ▶ | if (ref $thing eq 'GLOB') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 36 | my $prev= select($thing); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 36 | $|= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 36 | select($prev); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 36 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | elsif (ref($thing)->can('autoflush')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | $thing->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 3 | 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # "Cached Adapters" is conceptually a field of the config object, but then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # it shows a giant mess if/when you Dump() the object, so I'm using this trick | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # to keep the list attached to the package instead of the object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # Object destructor cleans up the list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 29 | our %_cached_adapters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # Holds a list of weak references to Adapter instances which have cached values from this config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 102 | ▶ | sub _cached_adapters { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cached_adapters: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # Use refaddr in case someone subclasses and gets creative with re-blessing objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 102 | ▶ | $_cached_adapters{refaddr $_[0]} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$Log::Any::Adapter::Daemontools::Config::_cached_adapters{builtin::refaddr($_[0])} ||= []
MC/DC100%1/1
$Log::Any::Adapter::Daemontools::Config::_cached_adapters{builtin::refaddr($_[0])} ||= []
$Log::Any::Adapter::Daemontools::Config::_cached_adapters{builtin::refaddr($_[0])}
Truth table100%2/2
A
A= $Log::Any::Adapter::Daemontools::Config::_cached_adapters{builtin::refaddr($_[0])}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 2 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 2 | delete $_cached_adapters{refaddr $_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # Called by an adapter after it caches things from this config to ask that it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # be notified about any changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 44 | ▶ | sub _register_cached_adapter { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_cached_adapter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 44 | my ($self, $adapter)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 44 | my $cache= $self->_cached_adapters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 44 | push @$cache, $adapter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 44 | weaken( $cache->[-1] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # Inform all the Adapters who have cached our settings that the cache is invalid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 58 | ▶ | sub _reset_cached_adapters { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_cached_adapters: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 58 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 58 | my $cache= $self->_cached_adapters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 58 | $_->_uncache_config for grep { defined } @$cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 58 | @$cache= (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 29 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||