File Coverage

blib/lib/Log/Agent/Tag.pm
Criterion Covered Total %
statement 20 26 76.9
branch 4 4 100.0
condition n/a
subroutine 5 8 62.5
pod 5 6 83.3
total 34 44 77.2


line stmt bran cond sub pod time code
1             ###########################################################################
2             #
3             # Tag.pm
4             #
5             # Copyright (C) 1999 Raphael Manfredi.
6             # Copyright (C) 2002-2015 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     4   18 use strict;
  4         7  
  4         1207  
15              
16             ########################################################################
17             package Log::Agent::Tag;
18              
19             #
20             # ->make
21             #
22             # Creation routine.
23             #
24             sub make {
25 0     0 0 0 my $self = bless {}, shift;
26 0         0 require Carp;
27 0         0 Carp::confess("deferred");
28             }
29              
30             #
31             # Attribute access
32             #
33              
34 10     10 1 81 sub postfix { $_[0]->{'postfix'} }
35 0     0 1 0 sub name { $_[0]->{'name'} }
36 17     17 1 37 sub separator { $_[0]->{'separator'} }
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             sub _init {
50 11     11   17 my $self = shift;
51 11         19 my ($name, $postfix, $separator) = @_;
52 11 100       36 $separator = " " unless defined $separator;
53 11         30 $self->{name} = $name;
54 11         19 $self->{postfix} = $postfix;
55 11         16 $self->{separator} = $separator;
56 11         29 return;
57             }
58              
59             #
60             # ->string -- deferred
61             #
62             # Build tag string.
63             # Must be implemented by heirs.
64             #
65             sub string {
66 0     0 1 0 require Carp;
67 0         0 Carp::confess("deferred");
68             }
69              
70             #
71             # ->insert -- frozen
72             #
73             # Merge string into the log message, according to our configuration.
74             #
75             sub insert {
76 17     17 1 26 my $self = shift;
77 17         24 my ($str) = @_; # A Log::Agent::Message object
78              
79 17         53 my $string = $self->string;
80 17         54 my $separator = $self->separator;
81              
82             #
83             # Merge into the Log::Agent::Message object string.
84             #
85              
86 17 100       48 if ($self->postfix) {
87 5         26 $str->append($separator . $string);
88             } else {
89 12         53 $str->prepend($string . $separator);
90             }
91              
92 17         50 return;
93             }
94              
95             1; # for "require"
96             __END__