Framed/Write.pm

filter: Statementstmt 74.1% 46 / 62 Branchbran 62.5% 10 / 16 Conditioncond 35.7% 5 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 80.0% 12 / 15 Podpod 0.0% 0 / 8 totaltotal 59.3% 73 / 123 CC 14 SCAR 16.7
CC
14
Cov
66%
disable_write_queue
12.0
_write_now_then_callback
11.3
_write_now
3.0
CRAP 5.3
« Framed/Read.pm ↑ Summary Framed.pm »
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
BranchTrueFalseTotal
if ($_[0]{"_write_queue"} and @{$_[0]{"_write_queue"};}) 0 0 0
Condition0%0/3
$_[0]{"_write_queue"} and @{$_[0]{"_write_queue"};}
!ll&&!rl&&r
000
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"};}
ABresult
0X0
100
111
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"} ||= []
l!l
01
MC/DC0%0/1
$_[0]{"_write_queue"} ||= []
$_[0]{"_write_queue"}
Truth table50%1/2
A
A= $_[0]{"_write_queue"}
Aresult
11
00
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
BranchTrueFalseTotal
IO::SigGuard::syswrite($_[0]{"_out_fh"}, $_[1]) or do { die "IO::Framed::X"->create("WriteError", $!) } 1 65536 65537
50 1 die IO::Framed::X->create('WriteError', $!);
51 };
52  
53 65536 ▶ $_[2]->() if $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 0 65536 65536
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
BranchTrueFalseTotal
if (my $qi = $self->{"_write_queue"}[0]) 4097 2 4099
76 4097 ▶ return 0 if !$self->_write_now_then_callback( @$qi );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_write_now_then_callback(@$qi) 4095 2 4097
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 }
l!l&&r!l&&!r
240950
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 }
ABresult
1X1
011
000
106 4095 ▶ if ($! && !$!{'EAGAIN'} && !$!{'EWOULDBLOCK'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! and not $!{"EAGAIN"} and not $!{"EWOULDBLOCK"}) 0 4095 4095
Condition33%2/6
$! and not $!{"EAGAIN"} and not $!{"EWOULDBLOCK"}
!ll&&!rl&&r
409500
$! and not $!{"EAGAIN"}
!ll&&!rl&&r
040950
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"}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ($wrote == length $_[1]) 2 0 2
114 2 $_[0]->{'_write_queue_partial'} = 0;
115 2 ▶ $_[2]->() if $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 2 0 2
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;
« Framed/Read.pm ↑ Summary Framed.pm »