| 1 | package Device::TLSPrinter::Network; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | { | ||||||||||||||||||||||||||||
| 8 | 2 | ▶ | no strict "vars"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | @ISA = qw< Device::TLSPrinter >; | |||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # init() | ||||||||||||||||||||||||||||
| 15 | # ---- | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # check arguments | ||||||||||||||||||||||||||||
| 20 | 0 | my ($host, $port) = split /:/, $self->_device; | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | $port = getservbyname($port, "tcp") || $port; | ||||||||||||||||||||||||||
|
Condition0%0/3
getservbyname($port, 'tcp') || $port
MC/DC0%0/2
getservbyname($port, 'tcp') || $port
getservbyname($port, 'tcp')
$port
Truth table0%0/3
A || B
A= getservbyname($port, 'tcp')B= $port
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | croak "error: Please specify a host and a port" if not $host or not $port; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$host and $port
MC/DC0%0/2
$host and $port
$host
$port
Truth table0%0/3
A and B
A= $hostB= $port
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # connect to the specified host and port | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $sock = IO::Socket::INET->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | PeerHost => $host, Proto => "tcp", PeerPort => $port, | ||||||||||||||||||||||||||||
| 27 | autoflush => 1, Timeout => $self->_timeout | ||||||||||||||||||||||||||||
| 28 | ) or croak "error: Can't connect to <$host\:$port>: $!"; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # set socket options | ||||||||||||||||||||||||||||
| 31 | 0 | $sock->sockopt(SO_RCVLOWAT, 1); # receiving buffer size | |||||||||||||||||||||||||||
| 32 | 0 | $sock->sockopt(SO_SNDLOWAT, 1); # sending buffer size | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # store the socket in the object | ||||||||||||||||||||||||||||
| 35 | 0 | $self->_socket($sock); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | return $self | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||
| 42 | # read() | ||||||||||||||||||||||||||||
| 43 | # ---- | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 46 | 0 | my $n = $self->{_socket}->sysread(my $buff, $args{expect}); | |||||||||||||||||||||||||||
| 47 | 0 | return ($n, $buff) | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||
| 52 | # write() | ||||||||||||||||||||||||||||
| 53 | # ----- | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub write { | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | my $n = $self->{_socket}->syswrite($args{data}); | |||||||||||||||||||||||||||
| 57 | 0 | return $n | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||
| 62 | # connected() | ||||||||||||||||||||||||||||
| 63 | # --------- | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub connected { | ||||||||||||||||||||||||||
|
Subroutine
connected: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $self->{_socket}->connected ? 1 : 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||