| 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
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | croak sprintf "invalid attribute method: %s->%s()", ref($self), $attr unless exists $self->{_attr}->{lc $attr}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $self->{_attr}->{lc $attr} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $self->{_attr}->{type} = $_[0] =~ /^\d/ ? $self->trans($_[0]) : $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $event = shift; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return (exists $trans{$event} ? $trans{$event} : undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | 1; | |||||||||||||||||||||||||||