blib/lib/Net/Partty.pm

filter: Statementstmt 31.5% 23 / 73 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 6 / 15 Podpod 20.0% 1 / 5 totaltotal 26.3% 30 / 114 CC 14 SCAR 35.0
CC
14
Cov
25%
connect
90.0
new
20.0
_sock_open
6.0
CRAP 33.2
↑ Summary
1 package Net::Partty;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 __PACKAGE__->mk_accessors(qw/ sock host port select /);
7 1 our $VERSION = '0.03';
8  
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::Socket::Telnet;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 my $DefaultOpts = {
14 host => 'www.partty.org',
15 port => 2750,
16 };
17  
18 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
19 0 my($class, %opts) = @_;
20  
21 0 my $self = bless {}, $class;
22  
23 0 for my $opt (qw/ sock host port /) {
24 0 ▶ $self->{$opt} = delete $opts{$opt} || $DefaultOpts->{$opt};
Condition0%0/3
delete $opts{$opt} || $DefaultOpts->{$opt}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{$opt} || $DefaultOpts->{$opt}
delete $opts{$opt} $DefaultOpts->{$opt}
Truth table0%0/3
A || B
A= delete $opts{$opt}B= $DefaultOpts->{$opt}
ABresult
1X1
011
000
25 }
26  
27 0 $self->{select} = IO::Select->new;
28 0 ▶ $self->{sock} or $self->_sock_open;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"sock"} or $self->_sock_open 0 0 0
29  
30 0 $self;
31 }
32  
33 0 ▶sub _sock_open {
Subroutine _sock_open: not called CC=2 SCAR=17.9
34 0 my $self = shift;
35 0 ▶ $self->{sock} = IO::Socket::Telnet->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->{"sock"} = "IO::Socket::Telnet"->new("PeerAddr", $self->host, "PeerPort", $self->port, "Proto", "tcp") or croak($!) 0 0 0
36 PeerAddr => $self->host,
37 PeerPort => $self->port,
38 Proto => 'tcp',
39 ) or croak $!;
40 0 $self->select->add($self->{sock});
41 0 $self->{sock};
42 }
43  
44 0 ▶sub _sock_close {
Subroutine _sock_close: not called CC=2 SCAR=17.9
45 0 my $self = shift;
46 0 ▶ return unless $self->{sock};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sock"} 0 0 0
47 0 close $self->{sock};
48 0 $self->select->remove($self->{sock});
49 0 delete $self->{sock};
50 }
51  
52 0 ▶sub _send_uint8 {
Subroutine _send_uint8: not called CC=1 SCAR=6.9
53 0 my($self, $int) = @_;
54 0 my $data = pack 'C', $int;
55 0 $self->sock->send($data);
56 }
57 0 ▶sub _send_uint16 {
Subroutine _send_uint16: not called CC=1 SCAR=6.9
58 0 my($self, $int) = @_;
59 0 my $data = pack 'n', $int;
60 0 $self->sock->send($data);
61 }
62  
63 0 ▶sub connect {
Subroutine connect: not called CC=9 SCAR=45.0
Pod undocumented
64 0 my($self, %opts) = @_;
65  
66 0 my @params = qw( message session_name writable_password readonly_password );
67 0 my @error;
68 0 for my $param (@params) {
69 0 ▶ push @error, $param unless exists $opts{$param};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{$param} 0 0 0
70 }
71 0 ▶ croak join(', ', @error) . ' parameters is required.' if @error;
Branch: 1 branch
BranchTrueFalseTotal
if @error 0 0 0
72  
73 0 ▶ croak 'session time out' unless $self->can_write(10);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can_write(10) 0 0 0
74 0 $self->sock->send('Partty!');
75 0 $self->_send_uint8(2);
76 0 for my $param (@params) {
77 0 $self->_send_uint16(length $opts{$param});
78 }
79 0 for my $param (@params) {
80 0 $self->sock->send($opts{$param});
81 }
82  
83  
84 0 ▶ croak 'session time out' unless $self->can_read(10);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can_read(10) 0 0 0
85 0 my $sock = $self->sock;
86 0 my $buf;
87 0 $self->sock->read($buf, 2);
88 0 my $retcode = unpack 'n', $buf;
89 0 $self->sock->read($buf, 2);
90 0 my $retmessage_len = unpack 'n', $buf;
91 0 $self->sock->read(my $retmessage, $retmessage_len);
92 0 ▶ croak $retmessage if $retcode;
Branch: 1 branch
BranchTrueFalseTotal
if $retcode 0 0 0
93 }
94  
95 0 ▶sub can_read {
Subroutine can_read: not called CC=1 SCAR=6.9
Pod undocumented
96 0 my($self, $time) = @_;
97 0 $self->select->can_read($time);
98 }
99  
100 0 ▶sub can_write {
Subroutine can_write: not called CC=1 SCAR=6.9
Pod undocumented
101 0 my($self, $time) = @_;
102 0 $self->select->can_write($time);
103 }
104  
105 {
106 package #
107 IO::Socket::Telnet;
108 0 ▶ sub sb {
Subroutine sb: not called CC=1 SCAR=6.9
Pod undocumented
109 0 my($self, $cmd, $opt) = @_;
110 0 $self->send(chr(255) . chr(250) . $cmd . $opt . chr(255) . chr(240));
111 }
112 }
113  
114 1 1;
115 __END__
↑ Summary