| 1 | package IO::Socket::CLI; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | IO::Socket::CLI - CLI for IO::Socket::INET6 and IO::Socket::SSL | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 VERSION | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | Version 0.04 | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | use IO::Socket::CLI; | ||||||||||||||||||||||||||||
| 14 | @ISA = ("IO::Socket::CLI"); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | C<IO::Socket::CLI> provides a command-line interface to L<IO::Socket::INET6> and | ||||||||||||||||||||||||||||
| 19 | L<IO::Socket::SSL>. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =for comment | ||||||||||||||||||||||||||||
| 22 | =head1 EXPORT | ||||||||||||||||||||||||||||
| 23 | None by default. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use IO::Socket::SSL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use IO::Socket::INET6; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | BEGIN { | ||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use Exporter (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 2 | $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 38 | 2 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 39 | 2 | @EXPORT = qw(); # qw( ); | |||||||||||||||||||||||||||
| 40 | 2 | @EXPORT_OK = qw(); # ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 41 | 2 | %EXPORT_TAGS = (); # ( 'all' => [ qw( ) ] ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # defaults | ||||||||||||||||||||||||||||
| 45 | 2 | my $DEBUG = 0; # boolean? | |||||||||||||||||||||||||||
| 46 | 2 | my $DELAY = 10; # number of milliseconds between each attempt at reading the response from the server. | |||||||||||||||||||||||||||
| 47 | 2 | my $TIMEOUT = 5; # number of seconds to wait for a response from server before returning an empty list. | |||||||||||||||||||||||||||
| 48 | 2 | my $PRINT_RESPONSE = 1; # boolean | |||||||||||||||||||||||||||
| 49 | 2 | my $PREPEND = 1; # boolean | |||||||||||||||||||||||||||
| 50 | 2 | our $SSL = 0; # boolean | |||||||||||||||||||||||||||
| 51 | 2 | my $HOST = '127.0.0.1'; # IP or domain | |||||||||||||||||||||||||||
| 52 | 2 | our $PORT = '143'; # port | |||||||||||||||||||||||||||
| 53 | 2 | our $BYE = qr'^\* BYE( |\r?$)'; # string server sends when it hangs up. | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 METHODS | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =over 2 | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item new(...) | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Creates a new IO::Socket::CLI object, returning its reference. Has the following options: | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =over 2 | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item HOST | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Hostname or IP address. Default is C<'127.0.0.1'>. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =item PORT | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Port of the service. Default is C<'143'>. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =item SSL | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Boolean value for if an SSL connection. Default is C<0>. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =item BYE | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | String server sends when it hangs up. Default is C<qr'^\* BYE( |\r?$)'>. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item TIMEOUT | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Timeout in seconds for reading from the socket before returning an empty list. Default is C<5>. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =item DELAY | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Delay in milliseconds between read attempts if nothing is returned. Default is C<10>. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =item PRINT_RESPONSE | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Boolean value for if to automatically print the server response on L</read()>. Default is C<1>. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =item PREPEND | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | Boolean value for if to pretend client commands and server responses with C<"C: "> and C<"S: ">, respectively. Default is C<1>. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =item DEBUG | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Boolean value for if to give verbose debugging info. Default is C<0>. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =back | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub new { | ||||||||||||||||||||||||||||
| 106 | 1 | ▶ | my $this = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=15 SCAR=36.4
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 1 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||
| 108 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 109 | 1 | ▶ | my $args = (ref($_[0]) eq 'HASH') ? $_[0] : {@_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | $self->{_HOST} = ($args->{HOST}) ? $args->{HOST} : $HOST; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | $self->{_PORT} = ($args->{PORT}) ? $args->{PORT} : $PORT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 1 | ▶ | $self->{_BYE} = ($args->{BYE}) ? $args->{BYE} : $BYE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 1 | ▶ | $self->{_DELAY} = ($args->{DELAY}) ? $args->{DELAY} : $DELAY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 1 | ▶ | $self->{_TIMEOUT} = ($args->{TIMEOUT}) ? $args->{TIMEOUT} : $TIMEOUT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | $self->{_PRINT_RESPONSE} = (defined $args->{PRINT_RESPONSE}) ? $args->{PRINT_RESPONSE} : $PRINT_RESPONSE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | $self->{_PREPEND} = (defined $args->{PREPEND}) ? $args->{PREPEND} : $PREPEND; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 1 | ▶ | $self->{_DEBUG} = (defined $args->{DEBUG}) ? $args->{DEBUG} : $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 1 | ▶ | $self->{_SSL} = (defined $args->{SSL}) ? $args->{SSL} : $SSL; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | $self->{_SOCKET} = IO::Socket::INET6->new(PeerAddr => $self->{_HOST}, | ||||||||||||||||||||||||||||
| 121 | PeerPort => $self->{_PORT}, | ||||||||||||||||||||||||||||
| 122 | 1 | ▶ | Blocking => 0) || | ||||||||||||||||||||||||||
|
Condition50%1/2
'IO::Socket::INET6'->new('PeerAddr', $self->{'_HOST'}, 'PeerPort', $self->{'_PORT'}, 'Blocking', 0) || die("Can't bind : $@\n")
MC/DC0%0/1
'IO::Socket::INET6'->new('PeerAddr', $self->{'_HOST'}, 'PeerPort', $self->{'_PORT'}, 'Blocking', 0) || die("Can't bind : $@\n")
'IO::Socket::INET6'->new('PeerAddr', $self->{'_HOST'}, 'PeerPort', $self->{'_PORT'}, 'Blocking', 0)
Truth table50%1/2
A
A= 'IO::Socket::INET6'->new('PeerAddr', $self->{'_HOST'}, 'PeerPort', $self->{'_PORT'}, 'Blocking', 0)
| |||||||||||||||||||||||||||||
| 123 | die "Can't bind : $@\n"; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | ($self->{_SSL}) and IO::Socket::SSL->start_SSL($self->{_SOCKET}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $self->{_OPEN} = ($self->{_SOCKET}->connected()) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | $self->{_COMMAND} = ''; | |||||||||||||||||||||||||||
| 128 | 0 | $self->{_SERVER_RESPONSE} = []; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | bless ($self, $class); | |||||||||||||||||||||||||||
| 131 | 0 | return $self; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =item read() | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | Reads the response from the server, returning it as a list. Tries every | ||||||||||||||||||||||||||||
| 137 | C<DELAY> milliseconds until C<TIMEOUT> seconds. Optionally prints the | ||||||||||||||||||||||||||||
| 138 | response to C<STDOUT> if C<PRINT_RESPONSE>. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub read { | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 145 | 0 | my $max_i = $self->{_TIMEOUT} / ($self->{_DELAY} / 1000); | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | do { | ||||||||||||||||||||||||||||
| 148 | 0 | select(undef, undef, undef, $self->{_DELAY} / 1000); | |||||||||||||||||||||||||||
| 149 | 0 | @{$self->{_SERVER_RESPONSE}} = $self->{_SOCKET}->getlines; | |||||||||||||||||||||||||||
| 150 | 0 | $i++; | |||||||||||||||||||||||||||
| 151 | 0 | ▶ | } while (!@{$self->{_SERVER_RESPONSE}} && $i < $max_i); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @{$self->{"_SERVER_RESPONSE"};} and $i < $max_i
MC/DC0%0/2
not @{$self->{"_SERVER_RESPONSE"};} and $i < $max_i
not @{$self->{"_SERVER_RESPONSE"};}
$i < $max_i
Truth table0%0/3
not(A) and B
A= not @{$self->{"_SERVER_RESPONSE"};}B= $i < $max_i
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ($DEBUG || $self->{_DEBUG}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$DEBUG or $self->{"_DEBUG"}
MC/DC0%0/2
$DEBUG or $self->{"_DEBUG"}
$DEBUG
$self->{"_DEBUG"}
Truth table0%0/3
A or B
A= $DEBUGB= $self->{"_DEBUG"}
| |||||||||||||||||||||||||||||
| 154 | 0 | print STDOUT "D: response took roughly " . ($i * $self->{_DELAY}) . " milliseconds\n"; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | $self->print_resp() if ($self->{_PRINT_RESPONSE}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | return @{$self->{_SERVER_RESPONSE}}; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =item response() | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Returns the last stored response from the server as a list. | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | sub response { | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
response: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | 0 | return @{$self->{_SERVER_RESPONSE}}; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =item print_resp() | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Prints each line of server response to C<STDOUT>, optionally prepending with C<"S: "> if C<PREPEND>. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | sub print_resp { | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_resp: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 181 | 0 | foreach (@{$self->{_SERVER_RESPONSE}}) { | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | print STDOUT "" . (($self->{_PREPEND}) ? "S: " : "") . "$_"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =item is_open() | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Returns if the server hung up according to the last server response. | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =cut | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | sub is_open { | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_open: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 194 | 0 | my $bye = $self->{_BYE}; | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | $self->{_OPEN} = ($self->{_SOCKET}->connected()) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | foreach (@{$self->{_SERVER_RESPONSE}}) { | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | $self->{_OPEN} = 0 if (/$bye/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 0 | last; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | 0 | return $self->{_OPEN}; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =item send($command) | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | Sends C<$command> to the server. Optionally echoes C<$command> if C<PRINT_RESPONSE>. | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =cut | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | sub send($) { | ||||||||||||||||||||||||||||
| 210 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
send: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 0 | chomp (my $command = shift); | |||||||||||||||||||||||||||
| 212 | 0 | $self->{_COMMAND} = $command; | |||||||||||||||||||||||||||
| 213 | 0 | ▶ | print STDOUT "" . ($self->{_PREPEND} ? "C: " : "") . "$command\r\n" if ($self->{_PRINT_RESPONSE}); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 214 | 0 | $self->{_SOCKET}->syswrite("$command\r\n"); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =item prompt() | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | Reads command from C<STDIN> and sends it to the server. | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =cut | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | sub prompt { | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
prompt: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | 0 | ▶ | print STDOUT "C: " if ($self->{_PREPEND}); # client prompt | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | chomp(my $command = <STDIN>); | |||||||||||||||||||||||||||
| 227 | 0 | $self->{_COMMAND} = $command; | |||||||||||||||||||||||||||
| 228 | 0 | $self->{_SOCKET}->syswrite("$command\r\n"); | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =item command() | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | Returns last command sent. | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =cut | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | sub command() { | ||||||||||||||||||||||||||||
| 238 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
command: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 239 | 0 | return $self->{_COMMAND}; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =item print_response(), print_response($boolean) | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | Optionally turns C<PRINT_RESPONSE> on/off. Returns value. | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =cut | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | sub print_response { | ||||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_response: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 0 | my $boolean = shift; | |||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ($boolean and $boolean != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$boolean and $boolean != 1
MC/DC0%0/2
$boolean and $boolean != 1
$boolean
$boolean != 1
Truth table0%0/3
A and B
A= $booleanB= $boolean != 1
| |||||||||||||||||||||||||||||
| 253 | 0 | carp "warning: valid settings for print_response() are 0 or 1 -- setting to $PRINT_RESPONSE"; | |||||||||||||||||||||||||||
| 254 | 0 | $boolean = $PRINT_RESPONSE; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | 0 | $self->{_PRINT_RESPONSE} = $boolean; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | 0 | return $self->{_PRINT_RESPONSE}; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =item prepend(), prepend($boolean) | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | Optionally turns C<PREPEND> on/off. Returns value. | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =cut | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | sub prepend { | ||||||||||||||||||||||||||||
| 268 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
prepend: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 0 | my $boolean = shift; | |||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ($boolean and $boolean != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$boolean and $boolean != 1
MC/DC0%0/2
$boolean and $boolean != 1
$boolean
$boolean != 1
Truth table0%0/3
A and B
A= $booleanB= $boolean != 1
| |||||||||||||||||||||||||||||
| 272 | 0 | carp "warning: valid settings for prepend() are 0 or 1 -- setting to $PREPEND"; | |||||||||||||||||||||||||||
| 273 | 0 | $boolean = $PREPEND; | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | 0 | $self->{_PREPEND} = $boolean; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | 0 | return $self->{_PREPEND}; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =item timeout(), timeout($seconds) | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | Optionally sets C<TIMEOUT> in seconds. Must be non-negative. Returns value. | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | =cut | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | sub timeout { | ||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
timeout: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | my $seconds = shift; | |||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ($seconds < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 0 | carp "warning: timeout() must be non-negative -- setting to $TIMEOUT"; | |||||||||||||||||||||||||||
| 292 | 0 | $seconds = $TIMEOUT; | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | 0 | $self->{_TIMEOUT} = $seconds; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | 0 | return $self->{_TIMEOUT}; | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | =item delay(), delay($milliseconds) | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | Optionally sets C<DELAY> in milliseconds. Must be positive. Returns value. | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =cut | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | sub delay { | ||||||||||||||||||||||||||||
| 306 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delay: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 0 | my $milliseconds = shift; | |||||||||||||||||||||||||||
| 309 | 0 | ▶ | if ($milliseconds < 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | carp "warning: delay() must be positive -- setting to $DELAY"; | |||||||||||||||||||||||||||
| 311 | 0 | $milliseconds = $DELAY; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | 0 | $self->{_DELAY} = $milliseconds; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | 0 | return $self->{_DELAY}; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | =item bye(), bye($bye) | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | Optionally sets C<BYE>. Must be a regexp-like quote: C<qr/STRING/>. Returns value. | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | =cut | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | sub bye { | ||||||||||||||||||||||||||||
| 325 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
bye: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | 0 | my $bye = shift; | |||||||||||||||||||||||||||
| 328 | 0 | ▶ | unless ($bye =~ /\(\?(?:-xism|\^):.*\)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 0 | carp "warning: bye() must be a regexp-like quote: qr/STRING/ -- setting to '$BYE' instead of '$bye'"; | |||||||||||||||||||||||||||
| 330 | 0 | $bye = $BYE; | |||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | 0 | $self->{_BYE} = $bye; | |||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | 0 | return $self->{_BYE}; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | =item debug(), debug($boolean) | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | Optionally turns debugging info/verbosity on/off. Returns value. | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | =cut | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | sub debug { | ||||||||||||||||||||||||||||
| 344 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | 0 | my $boolean = shift; | |||||||||||||||||||||||||||
| 347 | 0 | ▶ | if ($boolean and $boolean != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$boolean and $boolean != 1
MC/DC0%0/2
$boolean and $boolean != 1
$boolean
$boolean != 1
Truth table0%0/3
A and B
A= $booleanB= $boolean != 1
| |||||||||||||||||||||||||||||
| 348 | 0 | carp "warning: valid settings for debug() are 0 or 1 -- setting to 1"; | |||||||||||||||||||||||||||
| 349 | 0 | $boolean = 1; | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | 0 | $self->{_DEBUG} = $boolean; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | 0 | return $self->{_DEBUG}; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | #sub debug { | ||||||||||||||||||||||||||||
| 357 | # my $self = shift; | ||||||||||||||||||||||||||||
| 358 | # confess 'error: thing->debug($level)' unless @_ == 1; | ||||||||||||||||||||||||||||
| 359 | # my $level = shift; | ||||||||||||||||||||||||||||
| 360 | # if (ref($self)) { | ||||||||||||||||||||||||||||
| 361 | # $self->{_DEBUG} = $level; # just myself | ||||||||||||||||||||||||||||
| 362 | # } else { | ||||||||||||||||||||||||||||
| 363 | # $DEBUG = $level; # whole class | ||||||||||||||||||||||||||||
| 364 | # } | ||||||||||||||||||||||||||||
| 365 | #} | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | =item socket() | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | Returns the underlying socket. | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | =cut | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | sub socket { | ||||||||||||||||||||||||||||
| 374 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
socket: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 375 | 0 | return $self->{_SOCKET}; | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | =item errstr() | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | Returns C<errstr()> from the socket. Only for SSL - returns C<undef> otherwise. | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | =cut | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | sub errstr { | ||||||||||||||||||||||||||||
| 385 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
errstr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 386 | 0 | ▶ | if ($self->{_SSL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 0 | return $self->{_SOCKET}->errstr(); | |||||||||||||||||||||||||||
| 388 | } else { | ||||||||||||||||||||||||||||
| 389 | 0 | return undef; | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | =item close() | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | Closes the socket. Returns true on success. This method needs to be overridden for SSL connections. | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | =cut | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | sub close { | ||||||||||||||||||||||||||||
| 400 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 401 | 0 | return $self->{_SOCKET}->close(); | |||||||||||||||||||||||||||
| 402 | 0 | ▶ | if ($self->{_SSL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | 0 | return $self->{_SOCKET}->stop_SSL(SSL_ctx_free => 1); | |||||||||||||||||||||||||||
| 404 | } else { | ||||||||||||||||||||||||||||
| 405 | 0 | return $self->{_SOCKET}->close(); | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | # object destructor | ||||||||||||||||||||||||||||
| 410 | sub DESTROY { | ||||||||||||||||||||||||||||
| 411 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 412 | 0 | ▶ | if ($DEBUG || $self->{"_DEBUG"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$DEBUG or $self->{"_DEBUG"}
MC/DC0%0/2
$DEBUG or $self->{"_DEBUG"}
$DEBUG
$self->{"_DEBUG"}
Truth table0%0/3
A or B
A= $DEBUGB= $self->{"_DEBUG"}
| |||||||||||||||||||||||||||||
| 413 | 0 | carp "Destroying $self " . $self->{_HOST} . ":" . $self->{_PORT}; | |||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | 0 | $self->close(); | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | # class destructor | ||||||||||||||||||||||||||||
| 419 | sub END { | ||||||||||||||||||||||||||||
| 420 | 2 | ▶ | if ($DEBUG) { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=9.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | 0 | print STDOUT "class destroyed.\n"; | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | =back | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | =head1 BUGS | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | Does not verify SSL connections. Has not been tried with STARTTLS. | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | =over 2 | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | =item * CPAN Bug Tracker | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-Socket-CLI> | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | =item * Code, Pull Requests, alternative Issues Tracker | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | L<https://gitable.org/ashley/IO-Socket-CLI.git> | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | =back | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | Copyright (C) 2012 by Ashley Willis E<lt>ashleyw@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 450 | it under the same terms as Perl itself, either Perl version 5.12.4 or, | ||||||||||||||||||||||||||||
| 451 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | L<IO::Socket::INET6>, L<IO::Socket::INET>, L<IO::Socket::SSL>, L<IO::Socket> | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | =cut | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 2 | 1; | |||||||||||||||||||||||||||