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