DJabberd/Callback.pm

filter: Statementstmt 62.8% 22 / 35 Branchbran 43.7% 7 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 4 totaltotal 53.2% 33 / 62 CC 9 SCAR 21.4
CC
9
Cov
57%
AUTOLOAD
13.5
already_fired
6.0
reset
2.0
CRAP 8.5
« DJabberd/DialbackParams.pm ↑ Summary DJabberd/Connection/ServerIn.pm »
1 package DJabberd::Callback;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 our $AUTOLOAD;
5  
6 20 our $logger = DJabberd::Log->get_logger();
7  
8 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 #my ($class, $meths) = @_;
10 # TODO: track where it was defined at, in debug mode?
11 5 return bless $_[1], $_[0];
12 }
13  
14 0 ▶sub reset { $_[0]{_has_been_called} = 0; }
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
15  
16 #sub DESTROY {
17 # my $self = shift;
18 # DJabberd->track_destroyed_obj($self);
19 #}
20  
21 0 ▶sub desc {
Subroutine desc: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my $self = shift;
23 0 return $self; # TODO: change to "Callback defined at Djabberd.pm, line 23423"
24 }
25  
26 0 ▶sub already_fired {
Subroutine already_fired: not called CC=2 SCAR=17.9
Pod undocumented
27 0 my $self = shift;
28 0 ▶ return $self->{_has_been_called} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_has_been_called'} ? : 0 0 0
29 }
30  
31 9 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=8 SCAR=26.0
32 9 my $self = shift;
33 9 my $meth = $AUTOLOAD;
34 9 $meth =~ s/.+:://;
35  
36 # ignore perl-generated methods
37 9 ▶ return unless $meth =~ /[a-z]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $meth =~ /[a-z]/ 5 4 9
38  
39 # conditional debug statement -- computing this is costly, so only do this
40 # when we are actually running in debug mode --kane
41 4 ▶ if ($logger->is_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DJabberd::Callback::logger->is_debug) 0 4 4
42 # show who (file:linenumber) called which method on the callback
43 # and what it's arguments were
44 0 my @c = caller;
45 0 $logger->debug( '$callback->'."$meth( @_ ) has been called from $c[1]:$c[2]" );
46 }
47  
48 4 ▶ if ($self->{_has_been_called}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_has_been_called"}++) 0 4 4
49 0 warn "Callback called twice. ignoring.\n";
50 0 return;
51 }
52  
53 4 ▶ if (my $pre = $self->{_pre}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pre = $self->{"_pre"}) 0 4 4
54 0 ▶ $pre->($self, $meth, @_) or return;
Branch: 1 branch
BranchTrueFalseTotal
&$pre($self, $meth, @_) or return 0 0 0
55 }
56 4 my $func = $self->{$meth};
57 4 ▶ unless ($func) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($func) 0 4 4
58 0 my $avail = join(", ", grep { $_ !~ /^_/ } keys %$self);
59 0 croak("unknown method ($meth) called on " . $self->desc . "; available methods: $avail");
60 }
61 4 $func->($self, @_);
62  
63 # let our creator know we've fired
64 4 ▶ if (my $postfire = $self->{_post_fire}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $postfire = $self->{"_post_fire"}) 4 0 4
65 4 $postfire->($meth);
66 }
67 }
68  
69 20 1;
« DJabberd/DialbackParams.pm ↑ Summary DJabberd/Connection/ServerIn.pm »