| 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
| |||||||||||||||||||||||||||||
| 52 | 3 | my $vset = $set{lc($arg)}; | |||||||||||||||||||||||||||
| 53 | 3 | ▶ | next unless ref $vset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 3 | $$vset = $val; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | unless (defined $callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $callback and $callback->isa("Callback")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||