| 1 | package IO::Framed::Write; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use IO::SigGuard (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use IO::Framed::X (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | my ( $class, $out_fh ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 14 | _out_fh => $out_fh, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | _writer => \&_write_now, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub get_write_fh { return $_[0]->{'_out_fh'} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_write_fh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub disable_write_queue { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ( $_[0]->{'_write_queue'} && @{ $_[0]->{'_write_queue'} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable_write_queue: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 1 branch
Condition0%0/3
$_[0]{"_write_queue"} and @{$_[0]{"_write_queue"};}
MC/DC0%0/2
$_[0]{"_write_queue"} and @{$_[0]{"_write_queue"};}
$_[0]{"_write_queue"}
@{$_[0]{"_write_queue"};}
Truth table0%0/3
A and B
A= $_[0]{"_write_queue"}B= @{$_[0]{"_write_queue"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | die 'Refuse to disable non-empty write queue!'; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $_[0]->{'_writer'} = \&_write_now; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | sub enable_write_queue { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $_[0]->{'_write_queue'} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable_write_queue: called CC=2 SCAR=7.1
Pod
undocumented
Condition50%1/2
$_[0]{"_write_queue"} ||= []
MC/DC0%0/1
$_[0]{"_write_queue"} ||= []
$_[0]{"_write_queue"}
Truth table50%1/2
A
A= $_[0]{"_write_queue"}
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $_[0]->{'_writer'} = \&_enqueue_write; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | sub write { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 65539 | ▶ | $_[0]->{'_writer'}->(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 43 | #blocking | ||||||||||||||||||||||||||||||||||||||||||
| 44 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | sub _write_now { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 65537 | ▶ | local $!; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_now: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 65537 | ▶ | IO::SigGuard::syswrite( $_[0]->{'_out_fh'}, $_[1] ) or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | die IO::Framed::X->create('WriteError', $!); | |||||||||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 65536 | ▶ | $_[2]->() if $_[2]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 65536 | return; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 59 | #non-blocking | ||||||||||||||||||||||||||||||||||||||||||
| 60 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | sub _enqueue_write { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enqueue_write: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | push @{ $self->{'_write_queue'} }, \@_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | sub flush_write_queue { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 4097 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush_write_queue: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4097 | ▶ | while ( my $qi = $self->{'_write_queue'}[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 4097 | ▶ | return 0 if !$self->_write_now_then_callback( @$qi ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | shift @{ $self->{'_write_queue'} }; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | sub get_write_queue_count { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_write_queue_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | return 0 + @{ $self->{'_write_queue'} }; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub forget_write_queue { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
forget_write_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $count = @{ $self->{'_write_queue'} }; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | @{ $self->{'_write_queue'} } = (); | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | sub _write_now_then_callback { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 4097 | ▶ | local $!; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_now_then_callback: called CC=7 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 4097 | ▶ | my $wrote = IO::SigGuard::syswrite( $_[0]->{'_out_fh'}, $_[1] ) || do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
IO::SigGuard::syswrite($_[0]{'_out_fh'}, $_[1]) || do {
if ($! and not $!{'EAGAIN'} and not $!{'EWOULDBLOCK'}) {
die 'IO::Framed::X'->create('WriteError', $!);
};
return undef
}
MC/DC0%0/2
IO::SigGuard::syswrite($_[0]{'_out_fh'}, $_[1]) || do {
if ($! and not $!{'EAGAIN'} and not $!{'EWOULDBLOCK'}) {
die 'IO::Framed::X'->create('WriteError', $!);
};
return undef
}
IO::SigGuard::syswrite($_[0]{'_out_fh'}, $_[1])
do {
if ($! and not $!{'EAGAIN'} and not $!{'EWOULDBLOCK'}) {
die 'IO::Framed::X'->create('WriteError', $!);
};
return undef
}
Truth table66%2/3
A || B
A= IO::SigGuard::syswrite($_[0]{'_out_fh'}, $_[1])B= do {
if ($! and not $!{'EAGAIN'} and not $!{'EWOULDBLOCK'}) {
die 'IO::Framed::X'->create('WriteError', $!);
};
return undef
}
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 4095 | ▶ | if ($! && !$!{'EAGAIN'} && !$!{'EWOULDBLOCK'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$! and not $!{"EAGAIN"} and not $!{"EWOULDBLOCK"}
$! and not $!{"EAGAIN"}
MC/DC0%0/3
$! and not $!{"EAGAIN"} and not $!{"EWOULDBLOCK"}
$!
not $!{"EAGAIN"}
not $!{"EWOULDBLOCK"}
Truth table25%1/4
A and not(B) and not(C)
A= $!B= not $!{"EAGAIN"}C= not $!{"EWOULDBLOCK"}
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | die IO::Framed::X->create('WriteError', $!); | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 4095 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | if ($wrote == length $_[1]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | $_[0]->{'_write_queue_partial'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | ▶ | $_[2]->() if $_[2]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | #Trim the bytes that we did send. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | substr( $_[1], 0, $wrote ) = q<>; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | #This seems useful to track … ?? | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $_[0]->{'_write_queue_partial'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||