Agent/Tag/Callback.pm

filter: Statementstmt 87.8% 29 / 33 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 33.3% 1 / 3 totaltotal 75.0% 42 / 56 CC 7 SCAR 15.2
CC
7
Cov
78%
make
7.2
string
2.0
BEGIN
1.0
CRAP 4.6
« Agent/Formatting.pm ↑ Summary Agent/Driver/Mail.pm »
1 ###########################################################################
2 #
3 # Callback.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 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ########################################################################
17 package Log::Agent::Tag::Callback;
18  
19 1 require Log::Agent::Tag;
20 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 @ISA = qw(Log::Agent::Tag);
22  
23 #
24 # ->make
25 #
26 # Creation routine.
27 #
28 # Calling arguments: a hash table list.
29 #
30 # The keyed argument list may contain:
31 # -POSTFIX whether to postfix log message or prefix it.
32 # -SEPARATOR separator string to use between tag and message
33 # -NAME tag's name (optional)
34 # -CALLBACK Callback object
35 #
36 # Attributes:
37 # callback the Callback object
38 #
39 2 ▶sub make {
Subroutine make: called CC=6 SCAR=19.7
Pod undocumented
40 2 my $self = bless {}, shift;
41 2 my (%args) = @_;
42 2 my ($name, $postfix, $separator, $callback);
43  
44 2 my %set = (
45 -name => \$name,
46 -callback => \$callback,
47 -postfix => \$postfix,
48 -separator => \$separator,
49 );
50  
51 2 ▶ while (my ($arg, $val) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 3 2 5
52 3 my $vset = $set{lc($arg)};
53 3 ▶ next unless ref $vset;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $vset 0 3 3
54 3 $$vset = $val;
55 }
56  
57 2 ▶ unless (defined $callback) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $callback) 0 2 2
58 0 require Carp;
59 0 Carp::croak("Argument -callback is mandatory");
60 }
61  
62 2 ▶ unless (ref $callback && $callback->isa("Callback")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $callback and $callback->isa("Callback")) 0 2 2
Condition33%1/3
ref $callback and $callback->isa("Callback")
!ll&&!rl&&r
002
MC/DC0%0/2
ref $callback and $callback->isa("Callback")
ref $callback $callback->isa("Callback")
Truth table33%1/3
A and B
A= ref $callbackB= $callback->isa("Callback")
ABresult
0X0
100
111
63 0 require Carp;
64 0 Carp::croak("Argument -callback needs a Callback object");
65 }
66  
67 2 $self->_init($name, $postfix, $separator);
68 2 $self->{callback} = $callback;
69  
70 2 return $self;
71 }
72  
73 #
74 # Attribute access
75 #
76  
77 3 ▶sub callback { $_[0]->{callback} }
Subroutine callback: called CC=1 SCAR=0.0
Pod undocumented
78  
79 #
80 # Defined routines
81 #
82  
83 #
84 # ->string -- defined
85 #
86 # Build tag string by invoking callback.
87 #
88 3 ▶sub string {
Subroutine string: called CC=2 SCAR=7.0
Pod documented
89 3 my $self = shift;
90  
91 #
92 # Avoid recursion, which could happen if another logxxx() call is made
93 # whilst within the callback.
94 #
95 # Assumes mono-threaded application.
96 #
97  
98 3 ▶ return sprintf 'callback "%s" busy', $self->name if $self->{busy};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"busy"} 0 3 3
99  
100 3 $self->{busy} = 1;
101 3 my $string = $self->callback->call();
102 3 $self->{busy} = 0;
103  
104 3 return $string;
105 }
106  
107 1 1; # for "require"
108 __END__
« Agent/Formatting.pm ↑ Summary Agent/Driver/Mail.pm »