| 1 | ########################################################################### | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Prefixer.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 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | ######################################################################## | ||||||||||||||||||||||||||||
| 17 | package Log::Agent::Prefixer; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | # Ancestor for logging channels wishing to implement native prefixing | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||
| 24 | # Attribute access: those attributes must be filled by our heirs | ||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub prefix { $_[0]->{'prefix'} } | ||||||||||||||||||||||||||
|
Subroutine
prefix: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 64 | ▶ | sub stampfmt { $_[0]->{'stampfmt'} } | ||||||||||||||||||||||||||
|
Subroutine
stampfmt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub showpid { $_[0]->{'showpid'} } | ||||||||||||||||||||||||||
|
Subroutine
showpid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub no_ucfirst { $_[0]->{'no_ucfirst'} } | ||||||||||||||||||||||||||
|
Subroutine
no_ucfirst: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub no_prefixing { $_[0]->{'no_prefixing'} } | ||||||||||||||||||||||||||
|
Subroutine
no_prefixing: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub no_newline { $_[0]->{'no_newline'} } | ||||||||||||||||||||||||||
|
Subroutine
no_newline: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub crlf { $_[0]->{'crlf'} } | ||||||||||||||||||||||||||
|
Subroutine
crlf: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||
| 36 | # ->prefixing_string | ||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||
| 38 | # Compute prefixing string: stamping and "prefix: " to be emitted before | ||||||||||||||||||||||||||||
| 39 | # the logged string. | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | # Usage: | ||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||
| 43 | # $str = $self->prefixing_string(); # no ucfirst support possible | ||||||||||||||||||||||||||||
| 44 | # $str = $self->prefixing_string(\$log_message); | ||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||
| 46 | # Leading char of to-be-logged string is upper-cased in-place if | ||||||||||||||||||||||||||||
| 47 | # neither prefix nor pid are present, and behaviour was not disabled | ||||||||||||||||||||||||||||
| 48 | # via a -no_ucfirst, and the second call form with a scalar ref is used. | ||||||||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||||||||
| 50 | 77 | ▶ | sub prefixing_string { | ||||||||||||||||||||||||||
|
Subroutine
prefixing_string: called CC=9 SCAR=22.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 77 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||
| 54 | # This routine is called often... | ||||||||||||||||||||||||||||
| 55 | # Bypass the attribute access routines. | ||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 77 | my $prefix = $self->{prefix}; | |||||||||||||||||||||||||||
| 59 | 77 | ▶ | $prefix = '' unless defined $prefix; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 77 | ▶ | if ($self->{showpid}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 61 | 19 | ▶ | if ($prefix eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $prefix = $$; | |||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||
| 64 | 19 | $prefix .= "[$$]"; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } elsif ($prefix eq '') { | ||||||||||||||||||||||||||||
| 67 | 14 | my $rstr = $_[0]; | |||||||||||||||||||||||||||
| 68 | 14 | ▶ | $$rstr =~ s/^(.)/\u$1/ if ref $rstr && !$self->{no_ucfirst}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $rstr and not $self->{"no_ucfirst"}
MC/DC0%0/2
ref $rstr and not $self->{"no_ucfirst"}
ref $rstr
not $self->{"no_ucfirst"}
Truth table33%1/3
A and not(B)
A= ref $rstrB= not $self->{"no_ucfirst"}
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 77 | my $stamp = &{$self->{stampfmt}}; | |||||||||||||||||||||||||||
| 71 | return | ||||||||||||||||||||||||||||
| 72 | 77 | ▶ | ($stamp eq '' ? '' : "$stamp ") . | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 73 | ($prefix eq '' ? '' : "$prefix: "); | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 8 | 1; # for require | |||||||||||||||||||||||||||