| 1 | package Net::Gnutella::Client; | ||||||||||
| 2 | 1 | ▶ | use IO::Socket; | ||||||||
|
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
| |||||||||||
| 16 | 0 | ▶ | croak sprintf "invalid attribute method: %s->%s()", ref($self), $attr unless exists $self->{_attr}->{lc $attr}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 0 | ▶ | $self->{_attr}->{lc $attr} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 $parent = shift; | |||||||||
| 24 | 0 | my %args = @_; | |||||||||
| 25 | |||||||||||
| 26 | 0 | my $self = { | |||||||||
| 27 | _attr => { | ||||||||||
| 28 | proto => $proto, | ||||||||||
| 29 | parent => $parent, | ||||||||||
| 30 | debug => $parent->debug, | ||||||||||
| 31 | timeout=> $parent->timeout, | ||||||||||
| 32 | error => '', | ||||||||||
| 33 | server => '', | ||||||||||
| 34 | port => 6346, | ||||||||||
| 35 | }, | ||||||||||
| 36 | }; | ||||||||||
| 37 | |||||||||||
| 38 | 0 | bless $self, $proto; | |||||||||
| 39 | |||||||||||
| 40 | 0 | foreach my $key (keys %args) { | |||||||||
| 41 | 0 | my $lkey = lc $key; | |||||||||
| 42 | |||||||||||
| 43 | 0 | $self->$lkey($args{$key}); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | return $self->connect; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub connect { | ||||||||
|
Subroutine
connect: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 50 | 0 | my $self = shift; | |||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | unless ($self->server) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | $self->error("No server specified!"); | |||||||||
| 54 | 0 | return $self; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | my $sock = new IO::Socket::INET | |||||||||
| 58 | PeerAddr => $self->server, | ||||||||||
| 59 | PeerPort => $self->port, | ||||||||||
| 60 | Proto => "tcp"; | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | unless ($sock) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $self->error("Connect failed: $!"); | |||||||||
| 64 | 0 | return $self; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 0 | my $conn = Net::Gnutella::Connection->new($self->parent, | |||||||||
| 68 | Debug => $self->debug, | ||||||||||
| 69 | Timeout => $self->timeout, | ||||||||||
| 70 | Socket => $sock, | ||||||||||
| 71 | Ip => $sock->peerhost, | ||||||||||
| 72 | Connected => 1, | ||||||||||
| 73 | ); | ||||||||||
| 74 | |||||||||||
| 75 | 0 | $conn->_write_wrapper("GNUTELLA CONNECT/0.4\n\n"); | |||||||||
| 76 | |||||||||||
| 77 | 0 | return $conn; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 1 | 1; | |||||||||