line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Gnutella::Event;
|
2
|
1
|
|
|
1
|
|
5
|
use Carp;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict;
|
|
1
|
|
|
|
|
24
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw/$VERSION %trans $AUTOLOAD/;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
480
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = $VERSION = "0.1";
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
%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
|
|
|
|
|
|
|
sub AUTOLOAD {
|
19
|
0
|
|
|
0
|
|
|
my $self = shift;
|
20
|
0
|
|
|
|
|
|
my $attr = $AUTOLOAD;
|
21
|
0
|
|
|
|
|
|
$attr =~ s/.*:://;
|
22
|
0
|
0
|
|
|
|
|
return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods
|
23
|
0
|
0
|
|
|
|
|
croak sprintf "invalid attribute method: %s->%s()", ref($self), $attr unless exists $self->{_attr}->{lc $attr};
|
24
|
0
|
0
|
|
|
|
|
$self->{_attr}->{lc $attr} = shift if @_;
|
25
|
0
|
|
|
|
|
|
return $self->{_attr}->{lc $attr};
|
26
|
|
|
|
|
|
|
}
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Instantiate an object, parent to all others
|
29
|
|
|
|
|
|
|
#
|
30
|
|
|
|
|
|
|
sub new {
|
31
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub type {
|
54
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if (@_) {
|
57
|
0
|
0
|
|
|
|
|
$self->{_attr}->{type} = $_[0] =~ /^\d/ ? $self->trans($_[0]) : $_[0];
|
58
|
|
|
|
|
|
|
}
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $self->{_attr}->{type};
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub trans {
|
65
|
0
|
0
|
0
|
0
|
0
|
|
shift if (ref($_[0]) || $_[0]) =~ /^Net::Gnutella/;
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $event = shift;
|
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
return (exists $trans{$event} ? $trans{$event} : undef);
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1;
|