| 1 | package Inferno::RegMgr::TCP; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | # update POD & Changes & README | ||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use version; our $VERSION = qv('0.1.3'); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | # update DEPENDENCIES in POD & Makefile.PL & README | ||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use IO::Stream; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Inferno::RegMgr::Utils qw( run_callback quote attr parse_svc ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use constant PORT_NEW => 6701; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use constant PORT_FIND => 6702; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use constant PORT_EVENT => 6703; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use constant KiB => 1024; ## no critic (Capitalization) | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | sub new { | ||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my ($class, $opt) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | croak '{host} required' if !defined $opt->{host}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | my $self = { | ||||||||||||||||||||||||||||||||
| 26 | host => $opt->{host}, | ||||||||||||||||||||||||||||||||
| 27 | port_new => $opt->{port_new} || PORT_NEW, | ||||||||||||||||||||||||||||||||
| 28 | port_find => $opt->{port_find} || PORT_FIND, | ||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | port_event => $opt->{port_event} || PORT_EVENT, | ||||||||||||||||||||||||||||||
|
Condition0%0/6
$opt->{'port_new'} || 6701
$opt->{'port_find'} || 6702
$opt->{'port_event'} || 6703
MC/DC0%0/1
$opt->{'port_new'} || 6701
$opt->{'port_new'}
MC/DC0%0/1
$opt->{'port_find'} || 6702
$opt->{'port_find'}
MC/DC0%0/1
$opt->{'port_event'} || 6703
$opt->{'port_event'}
Truth table0%0/2
A
A= $opt->{'port_new'}
Truth table0%0/2
A
A= $opt->{'port_find'}
Truth table0%0/2
A
A= $opt->{'port_event'}
| |||||||||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||||||
| 31 | 0 | return bless $self, $class; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | sub open_event { | ||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my ($self, $opt) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
open_event: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | croak '{cb} required' if !defined $opt->{cb}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | my $io = IO::Stream->new({ | ||||||||||||||||||||||||||||||||
| 38 | host => $self->{host}, | ||||||||||||||||||||||||||||||||
| 39 | port => $self->{port_event}, | ||||||||||||||||||||||||||||||||
| 40 | cb => \&_cb_event, | ||||||||||||||||||||||||||||||||
| 41 | wait_for => IN|EOF, | ||||||||||||||||||||||||||||||||
| 42 | 0 | User_cb => [ $opt->{cb}, $opt->{method} ], | |||||||||||||||||||||||||||||||
| 43 | Is_connected=> 0, | ||||||||||||||||||||||||||||||||
| 44 | }); | ||||||||||||||||||||||||||||||||
| 45 | 0 | return $io; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | sub _cb_event { | ||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my ($io, $e, $err) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_cb_event: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (!$io->{Is_connected}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($e & IN) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($io->{in_buf} =~ s/\AREADY\n//xms) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 0 | $io->{Is_connected} = 1; | |||||||||||||||||||||||||||||||
| 54 | 0 | $e |= CONNECTED; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||||
| 57 | 0 | $err = "Bug in registry: expected 'READY\\n', got '$io->{in_buf}'"; | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 0 | $e |= EOF; | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($e & IN && $io->{in_buf} !~ s/.*\n//xms) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$e & 4 and not $io->{"in_buf"} =~ s/.*\n//msx
MC/DC0%0/2
$e & 4 and not $io->{"in_buf"} =~ s/.*\n//msx
$e & 4
not $io->{"in_buf"} =~ s/.*\n//msx
Truth table0%0/3
A and not(B)
A= $e & 4B= not $io->{"in_buf"} =~ s/.*\n//msx
| |||||||||||||||||||||||||||||||||
| 67 | 0 | $e &= ~IN; | |||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if (length $io->{in_buf} > KiB) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 0 | $err = 'Bug in registry: got 1 KiB without \\n'; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($e & EOF || $err) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$e & 16 or $err
MC/DC0%0/2
$e & 16 or $err
$e & 16
$err
Truth table0%0/3
A or B
A= $e & 16B= $err
| |||||||||||||||||||||||||||||||||
| 73 | 0 | $io->close(); | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ($e || $err) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$e or $err
MC/DC0%0/2
$e or $err
$e
$err
Truth table0%0/3
A or B
A= $eB= $err
| |||||||||||||||||||||||||||||||||
| 76 | 0 | run_callback( @{ $io->{User_cb} }, $e, $err ); | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | 0 | return; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | sub open_new { | ||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my ($self, $opt) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
open_new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | croak '{name} required' if !defined $opt->{name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | croak '{cb} required' if !defined $opt->{cb}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | my $io = IO::Stream->new({ | ||||||||||||||||||||||||||||||||
| 86 | host => $self->{host}, | ||||||||||||||||||||||||||||||||
| 87 | port => $self->{port_new}, | ||||||||||||||||||||||||||||||||
| 88 | cb => \&_cb_new, | ||||||||||||||||||||||||||||||||
| 89 | wait_for => 0, | ||||||||||||||||||||||||||||||||
| 90 | 0 | User_cb => [ $opt->{cb}, $opt->{method} ], | |||||||||||||||||||||||||||||||
| 91 | }); | ||||||||||||||||||||||||||||||||
| 92 | 0 | $io->write(sprintf "%s %s\n", quote($opt->{name}), attr($opt->{attr})); | |||||||||||||||||||||||||||||||
| 93 | 0 | return $io; | |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | sub _cb_new { | ||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my ($io, $e, $err) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_cb_new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 98 | 0 | $io->close(); | |||||||||||||||||||||||||||||||
| 99 | 0 | run_callback( @{ $io->{User_cb} }, $err ); | |||||||||||||||||||||||||||||||
| 100 | 0 | return; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | sub update { | ||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my ($self, $io, $attr) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 105 | 0 | $io->write(sprintf "%s\n", attr($attr)); | |||||||||||||||||||||||||||||||
| 106 | 0 | return; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | sub open_find { | ||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my ($self, $opt) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
open_find: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | croak '{cb} required' if !defined $opt->{cb}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | my $io = IO::Stream->new({ | ||||||||||||||||||||||||||||||||
| 113 | host => $self->{host}, | ||||||||||||||||||||||||||||||||
| 114 | port => $self->{port_find}, | ||||||||||||||||||||||||||||||||
| 115 | cb => \&_cb_find, | ||||||||||||||||||||||||||||||||
| 116 | wait_for => EOF, | ||||||||||||||||||||||||||||||||
| 117 | in_buf_limit=> KiB*KiB, | ||||||||||||||||||||||||||||||||
| 118 | 0 | User_cb => [ $opt->{cb}, $opt->{method} ], | |||||||||||||||||||||||||||||||
| 119 | }); | ||||||||||||||||||||||||||||||||
| 120 | 0 | $io->write(sprintf "%s\n", attr($opt->{attr})); | |||||||||||||||||||||||||||||||
| 121 | 0 | return $io; | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | sub _cb_find { | ||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my ($io, $e, $err) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_cb_find: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 126 | 0 | my $svc; | |||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($e & EOF && !$err) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$e & 16 and not $err
MC/DC0%0/2
$e & 16 and not $err
$e & 16
not $err
Truth table0%0/3
A and not(B)
A= $e & 16B= not $err
| |||||||||||||||||||||||||||||||||
| 128 | 0 | ($svc, $err) = parse_svc($io->{in_buf}); | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | 0 | $io->close(); | |||||||||||||||||||||||||||||||
| 131 | 0 | run_callback( @{ $io->{User_cb} }, $svc, $err ); | |||||||||||||||||||||||||||||||
| 132 | 0 | return; | |||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 2 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||||||
| 137 | __END__ | ||||||||||||||||||||||||||||||||