Gnutella/Event.pm

filter: Statementstmt 35.2% 12 / 34 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 3 totaltotal 23.8% 15 / 63 CC 10 SCAR 25.8
CC
10
Cov
24%
AUTOLOAD
20.0
trans
20.0
type
12.0
CRAP 13.2
« Gnutella/Packet/Pong.pm ↑ Summary Gnutella/Client.pm »
1 package Net::Gnutella::Event;
2 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw/$VERSION %trans $AUTOLOAD/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 1 $VERSION = $VERSION = "0.1";
7
8 1 %trans = (
9 0 => "ping",
10 1 => "pong",
11 64 => "push",
12 128 => "query",
13 129 => "reply",
14 );
15
16 # Use AUTOHANDLER to supply generic attribute methods
17 #
18 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
19 0 my $self = shift;
20 0 my $attr = $AUTOLOAD;
21 0 $attr =~ s/.*:://;
22 0 ▶ return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /[^A-Z]/ 0 0 0
23 0 ▶ croak sprintf "invalid attribute method: %s->%s()", ref($self), $attr unless exists $self->{_attr}->{lc $attr};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_attr"}{lc $attr} 0 0 0
24 0 ▶ $self->{_attr}->{lc $attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
25 0 return $self->{_attr}->{lc $attr};
26 }
27
28 # Instantiate an object, parent to all others
29 #
30 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
31 0 my $class = shift;
32 0 my %args = @_;
33
34 0 my $self = {
35 _attr => {
36 packet => undef,
37 from => undef,
38 type => undef,
39 },
40 };
41
42 0 bless $self, $class;
43
44 0 foreach my $key (keys %args) {
45 0 my $lkey = lc $key;
46
47 0 $self->$lkey($args{$key});
48 }
49
50 0 return $self;
51 }
52
53 0 ▶sub type {
Subroutine type: not called CC=3 SCAR=24.8
Pod undocumented
54 0 my $self = shift;
55
56 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
57 0 ▶ $self->{_attr}->{type} = $_[0] =~ /^\d/ ? $self->trans($_[0]) : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\d/ ? : 0 0 0
58 }
59
60 0 return $self->{_attr}->{type};
61 }
62
63
64 0 ▶sub trans {
Subroutine trans: not called CC=4 SCAR=30.0
Pod undocumented
65 0 ▶ shift if (ref($_[0]) || $_[0]) =~ /^Net::Gnutella/;
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] || $_[0]) =~ /^Net::Gnutella/ 0 0 0
Condition0%0/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
66
67 0 my $event = shift;
68
69 0 ▶ return (exists $trans{$event} ? $trans{$event} : undef);
Branch: 1 branch
BranchTrueFalseTotal
exists $Net::Gnutella::Event::trans{$event} ? : 0 0 0
70 }
71
72 1 1;
« Gnutella/Packet/Pong.pm ↑ Summary Gnutella/Client.pm »