Gnutella/Packet/Push.pm

filter: Statementstmt 25.9% 14 / 54 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 5 totaltotal 21.6% 18 / 83 CC 9 SCAR 26.4
CC
9
Cov
21%
ip
30.0
AUTOLOAD
20.0
new
6.0
CRAP 14.0
« Gnutella/Packet/Reply.pm ↑ Summary Gnutella/Packet/Pong.pm »
1 package Net::Gnutella::Packet::Push;
2 1 ▶use Socket qw(inet_aton inet_ntoa);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw/$VERSION $AUTOLOAD/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 $VERSION = $VERSION = "0.1";
8
9 # Use AUTOHANDLER to supply generic attribute methods
10 #
11 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
12 0 my $self = shift;
13 0 my $attr = $AUTOLOAD;
14 0 $attr =~ s/.*:://;
15 0 ▶ return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /[^A-Z]/ 0 0 0
16 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
17 0 ▶ $self->{_attr}->{lc $attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
18 0 return $self->{_attr}->{lc $attr};
19 }
20
21 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my $proto = shift;
23 0 my %args = @_;
24
25 0 my $self = {
26 _attr => {
27 msgid => [],
28 ttl => 7,
29 hops => 1,
30 function => 64,
31
32 guid => [],
33 index => 0,
34 ip => [],
35 port => 0,
36 },
37 };
38
39 0 bless $self, $proto;
40
41 0 foreach my $key (keys %args) {
42 0 my $lkey = lc $key;
43
44 0 $self->$lkey($args{$key});
45 }
46
47 0 return $self;
48 }
49
50 0 ▶sub ip {
Subroutine ip: not called CC=5 SCAR=34.0
Pod undocumented
51 0 my $self = shift;
52
53 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
54 0 ▶ if (ref($_[0]) eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
elsif ($_[0] =~ /^[\d.]+$/) { } 0 0 0
elsif ($_[0] =~ /\D/) { } 0 0 0
55 0 $self->{_attr}->{ip} = $_[0];
56 } elsif ($_[0] =~ /^[\d.]+$/) {
57 0 $self->{_attr}->{ip} = [ split(/\./, $_[0]) ];
58 } elsif ($_[0] =~ /\D/) {
59 0 $self->{_attr}->{ip} = [ split(/\./, inet_ntoa(inet_aton($_[0]))) ];
60 }
61 }
62
63 0 return @{ $self->{_attr}->{ip} };
64 }
65
66 0 ▶sub ip_as_string {
Subroutine ip_as_string: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my $self = shift;
68
69 0 return join('.', @{ $self->{_attr}->{ip} });
70 }
71
72 0 ▶sub parse {
Subroutine parse: not called CC=1 SCAR=6.9
Pod undocumented
73 0 my $self = shift;
74 0 my $data = shift;
75
76 0 my @guid = unpack("L4", substr($data, 0, 16, ''));
77 0 my $index = unpack("L", substr($data, 0, 4, ''));
78 0 my @ip = unpack("C4", substr($data, 0, 4, ''));
79 0 my $port = unpack("S", substr($data, 0, 2, ''));
80
81 0 $self->guid(\@guid);
82 0 $self->index($index);
83 0 $self->ip(\@ip);
84 0 $self->port($port);
85 }
86
87 0 ▶sub format {
Subroutine format: not called CC=1 SCAR=6.9
Pod undocumented
88 0 my $self = shift;
89
90 0 my $data = pack("L4LC4S", @{ $self->guid }, $self->index, $self->ip, $self->port);
91
92 0 return $data;
93 }
94
95 1 1;
« Gnutella/Packet/Reply.pm ↑ Summary Gnutella/Packet/Pong.pm »