Agent/Message.pm

filter: Statementstmt 66.1% 41 / 62 Branchbran 45.0% 9 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 86.6% 13 / 15 Podpod 53.8% 7 / 13 totaltotal 63.6% 70 / 110 CC 11 SCAR 13.3
CC
11
Cov
61%
clone
9.5
prepend_first
6.0
append_last
6.0
CRAP 3.8
« Agent/Driver/Fork.pm ↑ Summary Agent/Tag/Caller.pm »
1 ###########################################################################
2 #
3 # Message.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 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ########################################################################
17 package Log::Agent::Message;
18  
19 use overload
20 16 ▶ qw("" stringify);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 #
23 # ->make
24 #
25 # Creation routine.
26 #
27 # Attributes:
28 # str formatted message string coming from user
29 # prepend_list list of strings to prepend to `str'
30 # append_list list of strings to append to `str'
31 #
32 113 ▶sub make {
Subroutine make: called CC=1 SCAR=0.0
Pod documented
33 113 my $self = bless [], shift; # Array for minimal overhead
34 113 $self->[0] = $_[0];
35 113 return $self;
36 }
37  
38 #
39 # Attribute access
40 #
41  
42 108 ▶sub str { $_[0]->[0] }
Subroutine str: called CC=1 SCAR=0.0
Pod undocumented
43 65 ▶sub prepend_list { $_[0]->[1] }
Subroutine prepend_list: called CC=1 SCAR=0.0
Pod undocumented
44 39 ▶sub append_list { $_[0]->[2] }
Subroutine append_list: called CC=1 SCAR=0.0
Pod undocumented
45  
46 #
47 # Attribute setting
48 #
49  
50 74 ▶sub set_str { $_[0]->[0] = $_[1] }
Subroutine set_str: called CC=1 SCAR=0.0
Pod undocumented
51 31 ▶sub set_prepend_list { $_[0]->[1] = $_[1] }
Subroutine set_prepend_list: called CC=1 SCAR=0.0
Pod undocumented
52 5 ▶sub set_append_list { $_[0]->[2] = $_[1] }
Subroutine set_append_list: called CC=1 SCAR=0.0
Pod undocumented
53  
54 #
55 # ->prepend
56 #
57 # Add string to the prepend list, at its TAIL.
58 # (i.e. the first to prepend gets output first)
59 #
60 31 ▶sub prepend {
Subroutine prepend: called CC=2 SCAR=7.0
Pod documented
61 31 my $self = shift;
62 31 my ($str) = @_;
63  
64 31 my $array = $self->prepend_list;
65 31 ▶ $array = $self->set_prepend_list([]) unless $array;
Branch: 1 branch
BranchTrueFalseTotal
unless $array 31 0 31
66  
67 31 push(@{$array}, $str);
68 }
69  
70 #
71 # ->prepend_first
72 #
73 # Add string to the prepend list, at its HEAD.
74 #
75 0 ▶sub prepend_first {
Subroutine prepend_first: not called CC=2 SCAR=17.9
Pod documented
76 0 my $self = shift;
77 0 my ($str) = @_;
78  
79 0 my $array = $self->prepend_list;
80 0 ▶ $array = $self->set_prepend_list([]) unless $array;
Branch: 1 branch
BranchTrueFalseTotal
unless $array 0 0 0
81  
82 0 unshift(@{$array}, $str);
83 }
84  
85 #
86 # ->append
87 #
88 # Add string to the append list, at its HEAD.
89 # (i.e. the first to append gets output last)
90 #
91 5 ▶sub append {
Subroutine append: called CC=2 SCAR=7.0
Pod documented
92 5 my $self = shift;
93 5 my ($str) = @_;
94  
95 5 my $array = $self->append_list;
96 5 ▶ $array = $self->set_append_list([]) unless $array;
Branch: 1 branch
BranchTrueFalseTotal
unless $array 5 0 5
97  
98 5 unshift(@{$array}, $str);
99 }
100  
101 #
102 # ->append_last
103 #
104 # Add string to the append list, at its TAIL.
105 #
106 0 ▶sub append_last {
Subroutine append_last: not called CC=2 SCAR=17.9
Pod documented
107 0 my $self = shift;
108 0 my ($str) = @_;
109  
110 0 my $array = $self->append_list;
111 0 ▶ $array = $self->set_append_list([]) unless $array;
Branch: 1 branch
BranchTrueFalseTotal
unless $array 0 0 0
112  
113 0 push(@{$array}, $str);
114 }
115  
116 #
117 # ->stringify
118 # (stringify)
119 #
120 # Returns complete string, with all prepended strings first, then the
121 # original string followed by all the appended strings.
122 #
123 141 ▶sub stringify {
Subroutine stringify: called CC=4 SCAR=13.9
Pod documented
124 141 my $self = shift;
125 141 ▶ return $self->[0] if @{$self} == 1; # Optimize usual case
Branch: 1 branch
BranchTrueFalseTotal
if @{$self;} == 1 107 34 141
126  
127 34 my $prepend = $self->prepend_list;
128 34 my $append = $self->append_list;
129  
130 return
131 31 ▶ ($prepend ? join('', @{$prepend}) : '') .
Branch: 1 branch
BranchTrueFalseTotal
$append ? : 5 29 34
132 $self->str .
133 34 ▶ ($append ? join('', @{$append}) : '');
Branch: 1 branch
BranchTrueFalseTotal
$prepend ? : 31 3 34
134 }
135  
136 #
137 # ->clone
138 #
139 # Clone object
140 # (not a deep clone, but prepend and append lists are also shallow-cloned.)
141 #
142 6 ▶sub clone {
Subroutine clone: called CC=4 SCAR=22.5
Pod documented
143 6 my $self = shift;
144 6 my $other = bless [], ref $self;
145 6 $other->[0] = $self->[0];
146 6 ▶ return $other if @{$self} == 1; # Optimize usual case
Branch: 1 branch
BranchTrueFalseTotal
if @{$self;} == 1 6 0 6
147  
148 0 ▶ if (defined $self->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1]) 0 0 0
149 0 my @array = @{$self->[1]};
150 0 $other->[1] = \@array;
151 }
152 0 ▶ if (defined $self->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[2]) 0 0 0
153 0 my @array = @{$self->[2]};
154 0 $other->[2] = \@array;
155 }
156  
157 0 return $other;
158 }
159  
160 16 1; # for require
161 __END__
« Agent/Driver/Fork.pm ↑ Summary Agent/Tag/Caller.pm »