| 1 | ########################################################################### | ||||||||||
| 2 | # | ||||||||||
| 3 | # Tag.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 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | ######################################################################## | ||||||||||
| 17 | package Log::Agent::Tag; | ||||||||||
| 18 | |||||||||||
| 19 | # | ||||||||||
| 20 | # ->make | ||||||||||
| 21 | # | ||||||||||
| 22 | # Creation routine. | ||||||||||
| 23 | # | ||||||||||
| 24 | 0 | ▶ | sub make { | ||||||||
|
Subroutine
make: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 25 | 0 | my $self = bless {}, shift; | |||||||||
| 26 | 0 | require Carp; | |||||||||
| 27 | 0 | Carp::confess("deferred"); | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | # | ||||||||||
| 31 | # Attribute access | ||||||||||
| 32 | # | ||||||||||
| 33 | |||||||||||
| 34 | 11 | ▶ | sub postfix { $_[0]->{'postfix'} } | ||||||||
|
Subroutine
postfix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | 0 | ▶ | sub name { $_[0]->{'name'} } | ||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 36 | 18 | ▶ | sub separator { $_[0]->{'separator'} } | ||||||||
|
Subroutine
separator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | |||||||||||
| 38 | # | ||||||||||
| 39 | # ->_init | ||||||||||
| 40 | # | ||||||||||
| 41 | # Initialization routine for common attributes: | ||||||||||
| 42 | # | ||||||||||
| 43 | # postfix if true, appends tag to message, otherwise prepends | ||||||||||
| 44 | # name the tag name | ||||||||||
| 45 | # separator the string to use before or after tag (defaults to " ") | ||||||||||
| 46 | # | ||||||||||
| 47 | # Called by each creation routine in heirs. | ||||||||||
| 48 | # | ||||||||||
| 49 | 12 | ▶ | sub _init { | ||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||
| 50 | 12 | my $self = shift; | |||||||||
| 51 | 12 | my ($name, $postfix, $separator) = @_; | |||||||||
| 52 | 12 | ▶ | $separator = " " unless defined $separator; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 12 | $self->{name} = $name; | |||||||||
| 54 | 12 | $self->{postfix} = $postfix; | |||||||||
| 55 | 12 | $self->{separator} = $separator; | |||||||||
| 56 | 12 | return; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | # | ||||||||||
| 60 | # ->string -- deferred | ||||||||||
| 61 | # | ||||||||||
| 62 | # Build tag string. | ||||||||||
| 63 | # Must be implemented by heirs. | ||||||||||
| 64 | # | ||||||||||
| 65 | 0 | ▶ | sub string { | ||||||||
|
Subroutine
string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | 0 | require Carp; | |||||||||
| 67 | 0 | Carp::confess("deferred"); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | # | ||||||||||
| 71 | # ->insert -- frozen | ||||||||||
| 72 | # | ||||||||||
| 73 | # Merge string into the log message, according to our configuration. | ||||||||||
| 74 | # | ||||||||||
| 75 | 18 | ▶ | sub insert { | ||||||||
|
Subroutine
insert: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 76 | 18 | my $self = shift; | |||||||||
| 77 | 18 | my ($str) = @_; # A Log::Agent::Message object | |||||||||
| 78 | |||||||||||
| 79 | 18 | my $string = $self->string; | |||||||||
| 80 | 18 | my $separator = $self->separator; | |||||||||
| 81 | |||||||||||
| 82 | # | ||||||||||
| 83 | # Merge into the Log::Agent::Message object string. | ||||||||||
| 84 | # | ||||||||||
| 85 | |||||||||||
| 86 | 18 | ▶ | if ($self->postfix) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 5 | $str->append($separator . $string); | |||||||||
| 88 | } else { | ||||||||||
| 89 | 13 | $str->prepend($string . $separator); | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 18 | return; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 4 | 1; # for "require" | |||||||||
| 96 | __END__ | ||||||||||