blib/lib/Linux/Event/_ByteStream/Descriptor.pm

filter: Statementstmt 95.2% 159 / 167 Branchbran 76.2% 122 / 160 Conditioncond 67.4% 29 / 43 MC/DCmcdc 38.4% 10 / 26 Subroutinesub 90.9% 20 / 22 Podpod 0.0% 0 / 11 totaltotal 79.2% 340 / 429 CC 106 SCAR 27.6
CC
106
Cov
84%
validate_modes
40.3
declare_consumer
26.4
for_class
22.1
CRAP 15.9
« blib/lib/Linux/Event/_SocketConfig.pm ↑ Summary bench/run-stream-lifecycle-bench.pl »
1 package Linux::Event::_ByteStream::Descriptor;
2 127 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 127 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 127 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 127 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 127 ▶use mro ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 127 my %FRAMER_DEFINITION;
10 my %CONSUMER_DEFINITION;
11 127 my %CLASS_DESCRIPTOR;
12 127 my %CONSTRUCTION_DESCRIPTOR;
13  
14 127 my @TUNING_NAME = qw(
15 read_size read_budget_bytes read_batch_bytes message_batch_size
16 high_watermark low_watermark max_pending_bytes max_buffer
17 idle_timeout read_timeout write_timeout
18 );
19 127 my %TUNING_NAME = map { $_ => 1 } @TUNING_NAME;
20 127 my @NATIVE_TUNING_NAME = qw(
21 read_size read_budget_bytes read_batch_bytes message_batch_size
22 high_watermark low_watermark max_pending_bytes max_buffer
23 );
24  
25 127 my @NATIVE_SPEC_FIELD = qw(
26 read_size read_budget_bytes read_batch_bytes message_batch_size
27 high_watermark low_watermark max_pending_bytes max_buffer read_mode
28 deliver_cb message_cb message_batch_cb drain_cb eof_cb read_error_cb
29 write_error_cb output_limit_cb write_empty_cb framing_error_cb delimiter
30 include_delimiter max_frame fixed_size prefix_bytes prefix_little
31 include_prefix consumer_provider consumer_abi_version
32 consumer_ops_address
33 );
34 127 my %NATIVE_SPEC_FIELD = map { $_ => 1 } @NATIVE_SPEC_FIELD;
35  
36 0 ▶sub tuning_names () { @TUNING_NAME }
Subroutine tuning_names: not called CC=1 SCAR=6.9
Pod undocumented
37 9 ▶sub native_tuning_names () { @NATIVE_TUNING_NAME }
Subroutine native_tuning_names: called CC=1 SCAR=0.0
Pod undocumented
38  
39 313 ▶sub _validate_native_spec ($spec) {
Subroutine _validate_native_spec: called CC=10 SCAR=23.0
40 313 ▶ croak 'native descriptor requires a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec ne "HASH" 1 312 313
41 if ref($spec) ne 'HASH';
42 312 my @unknown = grep { !$NATIVE_SPEC_FIELD{$_} } keys %$spec;
43 312 ▶ croak "unknown ordered-byte descriptor field '$unknown[0]'"
Branch: 1 branch
BranchTrueFalseTotal
if @unknown == 1 1 311 312
44 if @unknown == 1;
45 311 ▶ croak 'unknown ordered-byte descriptor fields: '
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 0 311 311
46 . join(', ', sort @unknown) if @unknown;
47 311 for my $field (@NATIVE_SPEC_FIELD) {
48 croak "missing ordered-byte descriptor field '$field'"
49 8991 ▶ if !exists $spec->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $spec->{$field} 1 8990 8991
50 }
51  
52 310 my %normalized = %$spec;
53 $normalized{$_} = $normalized{$_} ? 1 : 0
54 310 ▶ for qw(include_delimiter prefix_little include_prefix);
Branch: 1 branch
BranchTrueFalseTotal
$normalized{$_} ? : 6 924 930
55 $normalized{$_} = defined($normalized{$_}) ? 0 + $normalized{$_} : 0
56 310 ▶ for qw(
Branch: 1 branch
BranchTrueFalseTotal
defined $normalized{$_} ? : 4025 5 4030
57 read_size read_budget_bytes read_batch_bytes message_batch_size
58 high_watermark low_watermark max_pending_bytes max_buffer
59 read_mode fixed_size prefix_bytes consumer_abi_version
60 consumer_ops_address
61 );
62  
63 310 return \%normalized;
64 }
65  
66 144 ▶sub declare_framer ($base, $target, $definition) {
Subroutine declare_framer: called CC=5 SCAR=17.2
Pod undocumented
67 144 ▶ croak 'a framer may be declared only for a Linux::Event ordered-byte subclass'
Branch: 1 branch
BranchTrueFalseTotal
if $target eq $base or not $target->isa($base) 0 144 144
Condition33%1/3
$target eq $base or not $target->isa($base)
l!l&&r!l&&!r
00144
MC/DC0%0/2
$target eq $base or not $target->isa($base)
$target eq $base not $target->isa($base)
Truth table33%1/3
A or not(B)
A= $target eq $baseB= not $target->isa($base)
ABresult
1X1
011
000
68 if $target eq $base || !$target->isa($base);
69 croak "$target already has an ordered-byte descriptor"
70 144 ▶ if exists $CLASS_DESCRIPTOR{$target};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$target} 0 144 144
71 croak "$target already declares a framer"
72 144 ▶ if exists $FRAMER_DEFINITION{$target};
Branch: 1 branch
BranchTrueFalseTotal
if exists $FRAMER_DEFINITION{$target} 1 143 144
73 143 $FRAMER_DEFINITION{$target} = $definition;
74 143 return;
75 }
76  
77 319 ▶sub _framer_for ($class) {
Subroutine _framer_for: called CC=3 SCAR=11.0
78 319 for my $package (@{ mro::get_linear_isa($class) }) {
79 return $FRAMER_DEFINITION{$package}
80 1033 ▶ if exists $FRAMER_DEFINITION{$package};
Branch: 1 branch
BranchTrueFalseTotal
if exists $FRAMER_DEFINITION{$package} 136 897 1033
81 }
82 183 return undef;
83 }
84  
85 28 ▶sub declare_consumer ($base, $target, $definition) {
Subroutine declare_consumer: called CC=15 SCAR=32.7
Pod undocumented
86 28 ▶ croak 'a native consumer may be declared only for a Linux::Event ordered-byte subclass'
Branch: 1 branch
BranchTrueFalseTotal
if $target eq $base or not $target->isa($base) 0 28 28
Condition33%1/3
$target eq $base or not $target->isa($base)
l!l&&r!l&&!r
0028
MC/DC0%0/2
$target eq $base or not $target->isa($base)
$target eq $base not $target->isa($base)
Truth table33%1/3
A or not(B)
A= $target eq $baseB= not $target->isa($base)
ABresult
1X1
011
000
87 if $target eq $base || !$target->isa($base);
88 croak "$target already has an ordered-byte descriptor"
89 28 ▶ if exists $CLASS_DESCRIPTOR{$target};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$target} 0 28 28
90 croak "$target already declares a native consumer"
91 28 ▶ if exists $CONSUMER_DEFINITION{$target};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CONSUMER_DEFINITION{$target} 0 28 28
92 28 ▶ croak 'native consumer declaration must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $definition ne "HASH" 0 28 28
93 if ref($definition) ne 'HASH';
94 my @unknown = grep {
95 28 ▶ $_ ne 'provider' && $_ ne 'abi_version'
Condition83%5/6
$_ ne 'provider' && $_ ne 'abi_version' && $_ ne 'operations_address'
!ll&&!rl&&r
56280
$_ ne "provider" and $_ ne "abi_version"
!ll&&!rl&&r
282828
MC/DC0%0/3
$_ ne 'provider' && $_ ne 'abi_version' && $_ ne 'operations_address'
$_ ne "provider" $_ ne "abi_version" $_ ne 'operations_address'
Truth table75%3/4
A and B && C
A= $_ ne "provider"B= $_ ne "abi_version"C= $_ ne 'operations_address'
ABCresult
0XX0
10X0
1100
1111
96 && $_ ne 'operations_address'
97 } keys %$definition;
98 28 ▶ croak 'native consumer declaration has unknown fields: '
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 0 28 28
99 . join(', ', sort @unknown) if @unknown;
100 croak 'native consumer declaration requires provider'
101 28 ▶ if !exists($definition->{provider}) || !defined($definition->{provider});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $definition->{"provider"} and defined $definition->{"provider"} 0 28 28
Condition33%1/3
exists $definition->{"provider"} and defined $definition->{"provider"}
!ll&&!rl&&r
0028
MC/DC0%0/2
exists $definition->{"provider"} and defined $definition->{"provider"}
exists $definition->{"provider"} defined $definition->{"provider"}
Truth table33%1/3
A and B
A= exists $definition->{"provider"}B= defined $definition->{"provider"}
ABresult
0X0
100
111
102 croak 'native consumer declaration requires a positive integer abi_version'
103 if !defined($definition->{abi_version})
104 28 ▶ || $definition->{abi_version} !~ /\A[1-9]\d*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $definition->{"abi_version"} and $definition->{"abi_version"} =~ /\A[1-9]\d*\z/u 0 28 28
Condition33%1/3
defined $definition->{"abi_version"} and $definition->{"abi_version"} =~ /\A[1-9]\d*\z/u
!ll&&!rl&&r
0028
MC/DC0%0/2
defined $definition->{"abi_version"} and $definition->{"abi_version"} =~ /\A[1-9]\d*\z/u
defined $definition->{"abi_version"} $definition->{"abi_version"} =~ /\A[1-9]\d*\z/u
Truth table33%1/3
A and B
A= defined $definition->{"abi_version"}B= $definition->{"abi_version"} =~ /\A[1-9]\d*\z/u
ABresult
0X0
100
111
105 croak 'native consumer declaration requires a positive operations_address'
106 if !defined($definition->{operations_address})
107 28 ▶ || $definition->{operations_address} !~ /\A[1-9]\d*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $definition->{"operations_address"} and $definition->{"operations_address"} =~ /\A[1-9]\d*\z/u 0 28 28
Condition33%1/3
defined $definition->{"operations_address"} and $definition->{"operations_address"} =~ /\A[1-9]\d*\z/u
!ll&&!rl&&r
0028
MC/DC0%0/2
defined $definition->{"operations_address"} and $definition->{"operations_address"} =~ /\A[1-9]\d*\z/u
defined $definition->{"operations_address"} $definition->{"operations_address"} =~ /\A[1-9]\d*\z/u
Truth table33%1/3
A and B
A= defined $definition->{"operations_address"}B= $definition->{"operations_address"} =~ /\A[1-9]\d*\z/u
ABresult
0X0
100
111
108 28 $CONSUMER_DEFINITION{$target} = { %$definition };
109 28 return;
110 }
111  
112 319 ▶sub _consumer_for ($class) {
Subroutine _consumer_for: called CC=3 SCAR=11.0
113 319 for my $package (@{ mro::get_linear_isa($class) }) {
114 return $CONSUMER_DEFINITION{$package}
115 1457 ▶ if exists $CONSUMER_DEFINITION{$package};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CONSUMER_DEFINITION{$package} 40 1417 1457
116 }
117 279 return undef;
118 }
119  
120 333 ▶sub _validate_tuning ($target, $option) {
Subroutine _validate_tuning: called CC=13 SCAR=26.2
121 croak "$target high_watermark must be a non-negative integer"
122 333 ▶ if $option->{high_watermark} !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $option->{"high_watermark"} =~ /\A\d+\z/u 0 333 333
123 croak "$target low_watermark must be a non-negative integer"
124 333 ▶ if $option->{low_watermark} !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $option->{"low_watermark"} =~ /\A\d+\z/u 0 333 333
125 croak "$target low_watermark must be <= high_watermark"
126 333 ▶ if $option->{low_watermark} > $option->{high_watermark};
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"low_watermark"} > $option->{"high_watermark"} 1 332 333
127 croak "$target max_pending_bytes must be a non-negative integer"
128 332 ▶ if $option->{max_pending_bytes} !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $option->{"max_pending_bytes"} =~ /\A\d+\z/u 1 331 332
129 croak "$target read_size must be a positive integer"
130 331 ▶ if $option->{read_size} !~ /\A\d+\z/ || $option->{read_size} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $option->{"read_size"} =~ /\A\d+\z/u or $option->{"read_size"} <= 0 1 330 331
Condition66%2/3
not $option->{"read_size"} =~ /\A\d+\z/u or $option->{"read_size"} <= 0
l!l&&r!l&&!r
01330
MC/DC50%1/2
not $option->{"read_size"} =~ /\A\d+\z/u or $option->{"read_size"} <= 0
not $option->{"read_size"} =~ /\A\d+\z/u $option->{"read_size"} <= 0
Truth table66%2/3
not(A) or B
A= not $option->{"read_size"} =~ /\A\d+\z/uB= $option->{"read_size"} <= 0
ABresult
1X1
011
000
131 croak "$target read_budget_bytes must be a non-negative integer"
132 330 ▶ if $option->{read_budget_bytes} !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $option->{"read_budget_bytes"} =~ /\A\d+\z/u 1 329 330
133 croak "$target read_batch_bytes must be a non-negative integer"
134 329 ▶ if $option->{read_batch_bytes} !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $option->{"read_batch_bytes"} =~ /\A\d+\z/u 1 328 329
135 croak "$target message_batch_size must be a non-negative integer"
136 328 ▶ if $option->{message_batch_size} !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $option->{"message_batch_size"} =~ /\A\d+\z/u 1 327 328
137 croak "$target max_buffer must be a positive integer"
138 327 ▶ if $option->{max_buffer} !~ /\A\d+\z/ || $option->{max_buffer} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $option->{"max_buffer"} =~ /\A\d+\z/u or $option->{"max_buffer"} <= 0 0 327 327
Condition33%1/3
not $option->{"max_buffer"} =~ /\A\d+\z/u or $option->{"max_buffer"} <= 0
l!l&&r!l&&!r
00327
MC/DC0%0/2
not $option->{"max_buffer"} =~ /\A\d+\z/u or $option->{"max_buffer"} <= 0
not $option->{"max_buffer"} =~ /\A\d+\z/u $option->{"max_buffer"} <= 0
Truth table33%1/3
not(A) or B
A= not $option->{"max_buffer"} =~ /\A\d+\z/uB= $option->{"max_buffer"} <= 0
ABresult
1X1
011
000
139 327 for my $name (qw(idle_timeout read_timeout write_timeout)) {
140 $option->{$name} = Linux::Event::_ByteStream::_timeout_value(
141 979 $target, $name, $option->{$name},
142 );
143 }
144 326 return $option;
145 }
146  
147 17 ▶sub merge_tuning ($target, $base, $override) {
Subroutine merge_tuning: called CC=3 SCAR=11.0
Pod undocumented
148 17 ▶ croak "$target tuning must be a hash reference"
Branch: 1 branch
BranchTrueFalseTotal
if ref $override ne "HASH" 0 17 17
149 if ref($override) ne 'HASH';
150 17 my @unknown = grep { !$TUNING_NAME{$_} } keys %$override;
151 17 ▶ croak "$target tuning has unknown options: "
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 16 17
152 . join(', ', sort @unknown) if @unknown;
153 16 my %option = (%$base, %$override);
154 16 _validate_tuning($target, \%option);
155 16 return \%option;
156 }
157  
158 319 ▶sub _stream_tuning_for ($class) {
Subroutine _stream_tuning_for: called CC=6 SCAR=17.9
159 319 my %option = (
160 high_watermark => 1_048_576,
161 low_watermark => 262_144,
162 max_pending_bytes => 0,
163 read_size => 65_536,
164 read_budget_bytes => 65_536,
165 read_batch_bytes => 0,
166 message_batch_size => 0,
167 max_buffer => 8_388_608,
168 idle_timeout => 0,
169 read_timeout => 0,
170 write_timeout => 0,
171 );
172  
173 319 ▶ if (my $configure = $class->can('stream_tuning')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $configure = $class->can("stream_tuning")) 100 219 319
174 100 my @configured = $configure->($class);
175 100 my %configured;
176 100 ▶ if (@configured == 1 && ref($configured[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@configured == 1 and ref $configured[0] eq 'HASH') { } 1 99 100
Condition100%3/3
@configured == 1 and ref $configured[0] eq "HASH"
!ll&&!rl&&r
9811
MC/DC100%2/2
@configured == 1 and ref $configured[0] eq "HASH"
@configured == 1 ref $configured[0] eq "HASH"
Truth table100%3/3
A and B
A= @configured == 1B= ref $configured[0] eq "HASH"
ABresult
0X0
100
111
177 1 %configured = %{ $configured[0] };
178 } else {
179 99 ▶ croak "$class stream_tuning() returned an odd option list"
Branch: 1 branch
BranchTrueFalseTotal
if @configured % 2 1 98 99
180 if @configured % 2;
181 98 %configured = @configured;
182 }
183 99 my @unknown = grep { !$TUNING_NAME{$_} } keys %configured;
184 99 ▶ croak "$class stream_tuning() returned unknown options: "
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 98 99
185 . join(', ', sort @unknown) if @unknown;
186 98 @option{keys %configured} = values %configured;
187 }
188  
189 317 _validate_tuning($class, \%option);
190 310 return \%option;
191 }
192  
193 65 ▶sub validate_modes ($target, $descriptor, $tuning, $callbacks) {
Subroutine validate_modes: called CC=14 SCAR=37.0
Pod undocumented
194 65 ▶ if (!$descriptor->{framer}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($descriptor->{"framer"}) 58 7 65
195 croak "$target message_batch_size is available only to framed ordered-byte classes"
196 58 ▶ if $tuning->{message_batch_size};
Branch: 1 branch
BranchTrueFalseTotal
if $tuning->{"message_batch_size"} 0 58 58
197 croak "$target on_message requires a framed ordered-byte class"
198 58 ▶ if $callbacks->{on_message};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_message"} 1 57 58
199 croak "$target on_messages requires a framed ordered-byte class"
200 57 ▶ if $callbacks->{on_messages};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_messages"} 0 57 57
201 57 ▶ if ($descriptor->{consumer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($descriptor->{"consumer"}) 0 57 57
202 croak "$target raw native consumer cannot be combined with read_batch_bytes"
203 0 ▶ if $tuning->{read_batch_bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $tuning->{"read_batch_bytes"} 0 0 0
204 croak "$target on_data cannot be combined with a native consumer"
205 0 ▶ if $callbacks->{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_data"} 0 0 0
206 }
207 57 return;
208 }
209  
210 croak "$target read_batch_bytes is available only to raw ordered-byte classes"
211 7 ▶ if $tuning->{read_batch_bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $tuning->{"read_batch_bytes"} 0 7 7
212 croak "$target on_data requires a raw ordered-byte class"
213 7 ▶ if $callbacks->{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_data"} 0 7 7
214 7 ▶ if ($descriptor->{consumer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($descriptor->{"consumer"}) 0 7 7
215 croak "$target native consumer cannot be combined with message_batch_size"
216 0 ▶ if $tuning->{message_batch_size};
Branch: 1 branch
BranchTrueFalseTotal
if $tuning->{"message_batch_size"} 0 0 0
217 croak "$target on_message cannot be combined with a native consumer"
218 0 ▶ if $callbacks->{on_message};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_message"} 0 0 0
219 croak "$target on_messages cannot be combined with a native consumer"
220 0 ▶ if $callbacks->{on_messages};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_messages"} 0 0 0
221 }
222 7 return;
223 }
224  
225 51 ▶sub effective_input_callback ($descriptor, $tuning, $callbacks = {}) {
Subroutine effective_input_callback: called CC=7 SCAR=19.5
Pod undocumented
226 51 ▶ return undef if $descriptor->{consumer};
Branch: 1 branch
BranchTrueFalseTotal
if $descriptor->{"consumer"} 0 51 51
227 51 ▶ if (!$descriptor->{framer}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($descriptor->{"framer"}) 46 5 51
228 return exists($callbacks->{on_data})
229 46 ▶ ? $callbacks->{on_data} : $descriptor->{callbacks}{on_data};
Branch: 1 branch
BranchTrueFalseTotal
exists $callbacks->{'on_data'} ? : 4 42 46
230 }
231 5 ▶ my $name = $tuning->{message_batch_size} ? 'on_messages' : 'on_message';
Branch: 1 branch
BranchTrueFalseTotal
$tuning->{'message_batch_size'} ? : 1 4 5
232 return exists($callbacks->{$name})
233 5 ▶ ? $callbacks->{$name} : $descriptor->{callbacks}{$name};
Branch: 1 branch
BranchTrueFalseTotal
exists $callbacks->{$name} ? : 1 4 5
234 }
235  
236 309 ▶sub _native_for ($option, $callback, $framing, $consumer) {
Subroutine _native_for: called CC=10 SCAR=23.0
237 return Linux::Event::_ByteStream::Descriptor::Native->new({
238 read_size => $option->{read_size},
239 read_budget_bytes => $option->{read_budget_bytes},
240 read_batch_bytes => $option->{read_batch_bytes},
241 message_batch_size => $option->{message_batch_size},
242 high_watermark => $option->{high_watermark},
243 low_watermark => $option->{low_watermark},
244 max_pending_bytes => $option->{max_pending_bytes},
245 max_buffer => $option->{max_buffer},
246 read_mode => $framing->{read_mode},
247  
248 deliver_cb => $callback->{on_data},
249 message_cb => $callback->{on_message},
250 message_batch_cb => $callback->{on_messages},
251 drain_cb => $callback->{on_drain}
252 ? \&Linux::Event::_ByteStream::_xs_drain : undef,
253 eof_cb => \&Linux::Event::_ByteStream::_xs_read_eof,
254 read_error_cb => \&Linux::Event::_ByteStream::_xs_read_error,
255 write_error_cb => \&Linux::Event::_ByteStream::_xs_write_error,
256 output_limit_cb => \&Linux::Event::_ByteStream::_xs_output_limit,
257 write_empty_cb => \&Linux::Event::_ByteStream::_xs_write_empty,
258 framing_error_cb => \&Linux::Event::_ByteStream::_xs_framing_error,
259  
260 delimiter => $framing->{delimiter},
261 include_delimiter => $framing->{include_delimiter} // 0,
262 max_frame => $framing->{max_frame},
263 fixed_size => $framing->{fixed_size} // 0,
264 prefix_bytes => $framing->{prefix_bytes} // 0,
265 prefix_little => $framing->{prefix_little} // 0,
266 include_prefix => $framing->{include_prefix} // 0,
267  
268 consumer_provider => $consumer ? $consumer->{provider} : undef,
269 consumer_abi_version => $consumer ? $consumer->{abi_version} : 0,
270 consumer_ops_address => $consumer
271 309 ▶ ? $consumer->{operations_address} : 0,
Branch: 4 branches
BranchTrueFalseTotal
$callback->{'on_drain'} ? : 12 297 309
$consumer ? : 37 272 309
$consumer ? : 37 272 309
$consumer ? : 37 272 309
Condition100%10/10
$framing->{"include_delimiter"} // 0
l!l
76233
$framing->{"fixed_size"} // 0
l!l
16293
$framing->{"prefix_bytes"} // 0
l!l
12297
$framing->{"prefix_little"} // 0
l!l
12297
$framing->{"include_prefix"} // 0
l!l
30279
MC/DC100%1/1
$framing->{"include_delimiter"} // 0
$framing->{"include_delimiter"}
MC/DC100%1/1
$framing->{"fixed_size"} // 0
$framing->{"fixed_size"}
MC/DC100%1/1
$framing->{"prefix_bytes"} // 0
$framing->{"prefix_bytes"}
MC/DC100%1/1
$framing->{"prefix_little"} // 0
$framing->{"prefix_little"}
MC/DC100%1/1
$framing->{"include_prefix"} // 0
$framing->{"include_prefix"}
Truth table100%2/2
A
A= $framing->{"include_delimiter"}
Aresult
11
00
Truth table100%2/2
A
A= $framing->{"fixed_size"}
Aresult
11
00
Truth table100%2/2
A
A= $framing->{"prefix_bytes"}
Aresult
11
00
Truth table100%2/2
A
A= $framing->{"prefix_little"}
Aresult
11
00
Truth table100%2/2
A
A= $framing->{"include_prefix"}
Aresult
11
00
272 });
273 }
274  
275 103388 ▶sub for_class ($class) {
Subroutine for_class: called CC=22 SCAR=30.9
Pod undocumented
276 return $CONSTRUCTION_DESCRIPTOR{$class}
277 103388 ▶ if exists $CONSTRUCTION_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CONSTRUCTION_DESCRIPTOR{$class} 1111 102277 103388
278 102277 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 101955 322 102277
279  
280 322 ▶ croak 'Linux::Event::_ByteStream is a private implementation base; subclass a public ordered-byte leaf'
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "Linux::Event::_ByteStream" 1 321 322
281 if $class eq 'Linux::Event::_ByteStream';
282 321 ▶ croak "$class is not a Linux::Event ordered-byte class"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa("Linux::Event::_ByteStream") 0 321 321
283 if !$class->isa('Linux::Event::_ByteStream');
284  
285 321 my $is_stream_socket = $class->isa('Linux::Event::_Socket::Stream');
286 321 ▶ if (!$is_stream_socket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_stream_socket) 39 282 321
287 39 ▶ croak "$class defines socket_options() but is not a Linux::Event stream-socket class"
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("socket_options") 1 38 39
288 if $class->can('socket_options');
289 38 ▶ croak "$class defines configure_socket() but is not a Linux::Event stream-socket class"
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("configure_socket") 1 37 38
290 if $class->can('configure_socket');
291 }
292  
293 319 my $framer = _framer_for($class);
294 319 my $consumer = _consumer_for($class);
295 319 my $option = _stream_tuning_for($class);
296 310 my %callback = map { $_ => scalar $class->can($_) }
297 qw(on_data on_message on_messages on_drain on_eof on_error on_close
298 on_ready on_transport_ready);
299  
300 310 ▶ if ($framer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($framer) { } 135 175 310
301 croak "$class read_batch_bytes is available only to raw ordered-byte classes"
302 135 ▶ if $option->{read_batch_bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"read_batch_bytes"} 1 134 135
303 croak "$class cannot define on_data() when it declares a framer"
304 134 ▶ if $callback{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $callback{"on_data"} 1 133 134
305 133 ▶ if ($consumer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($consumer) 34 99 133
306 croak "$class native consumer cannot be combined with message_batch_size"
307 34 ▶ if $option->{message_batch_size};
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"message_batch_size"} 0 34 34
308 croak "$class native consumer cannot be combined with on_message()"
309 34 ▶ if $callback{on_message};
Branch: 1 branch
BranchTrueFalseTotal
if $callback{"on_message"} 1 33 34
310 croak "$class native consumer cannot be combined with on_messages()"
311 33 ▶ if $callback{on_messages};
Branch: 1 branch
BranchTrueFalseTotal
if $callback{"on_messages"} 0 33 33
312 }
313 } else {
314 croak "$class defines on_message() but does not declare a framer"
315 175 ▶ if $callback{on_message};
Branch: 1 branch
BranchTrueFalseTotal
if $callback{"on_message"} 0 175 175
316 croak "$class defines on_messages() but does not declare a framer"
317 175 ▶ if $callback{on_messages};
Branch: 1 branch
BranchTrueFalseTotal
if $callback{"on_messages"} 1 174 175
318 croak "$class message_batch_size is available only to framed ordered-byte classes"
319 174 ▶ if $option->{message_batch_size};
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"message_batch_size"} 1 173 174
320 173 ▶ if ($consumer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($consumer) 6 167 173
321 croak "$class raw native consumer cannot be combined with read_batch_bytes"
322 6 ▶ if $option->{read_batch_bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"read_batch_bytes"} 1 5 6
323 croak "$class native consumer cannot be combined with on_data()"
324 5 ▶ if $callback{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $callback{"on_data"} 1 4 5
325 }
326 }
327  
328 303 ▶ my $framing = $framer ? { %{ $framer->{native} } } : { read_mode => 0 };
Branch: 1 branch
BranchTrueFalseTotal
$framer ? : 132 171 303
329 303 my $native = _native_for($option, \%callback, $framing, $consumer);
330  
331 296 my $descriptor = {
332 class => $class,
333 native => $native,
334 options => $option,
335 framing => $framing,
336 framer => $framer,
337 consumer => $consumer,
338 callbacks => \%callback,
339 };
340 296 $CLASS_DESCRIPTOR{$class} = $descriptor;
341 296 return $descriptor;
342 }
343  
344 50 ▶sub prepared ($class, $override = {}, $callback_override = {}) {
Subroutine prepared: called CC=6 SCAR=17.9
Pod undocumented
345 50 ▶ croak "$class Listener stream callbacks must be a hash reference"
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback_override ne "HASH" 0 50 50
346 if ref($callback_override) ne 'HASH';
347 50 my $base = for_class($class);
348 50 ▶ return $base if !%$override && !%$callback_override;
Branch: 1 branch
BranchTrueFalseTotal
unless %$override or %$callback_override 43 7 50
Condition100%3/3
%$override or %$callback_override
l!l&&r!l&&!r
1643
MC/DC100%2/2
%$override or %$callback_override
%$override %$callback_override
Truth table100%3/3
A or B
A= %$overrideB= %$callback_override
ABresult
1X1
011
000
349 my $option = merge_tuning(
350 7 "$class Listener stream", $base->{options}, $override,
351 );
352 7 my %callback = (%{ $base->{callbacks} }, %$callback_override);
353 7 validate_modes("$class Listener stream", $base, $option, \%callback);
354 my $native = _native_for(
355 $option, \%callback, $base->{framing}, $base->{consumer},
356 6 );
357 return {
358 6 %$base,
359 native => $native,
360 options => $option,
361 callbacks => \%callback,
362 prepared_from => $base,
363 };
364 }
365  
366 1111 ▶sub with_prepared ($class, $descriptor, $constructor, @arg) {
Subroutine with_prepared: called CC=2 SCAR=7.1
Pod undocumented
367 1111 ▶ croak 'internal prepared Stream constructor must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if ref $constructor ne "CODE" 0 1111 1111
368 if ref($constructor) ne 'CODE';
369 1111 local $CONSTRUCTION_DESCRIPTOR{$class} = $descriptor;
370 1111 return $constructor->($class, @arg);
371 }
372  
373 0 ▶sub clear_cache () {
Subroutine clear_cache: not called CC=1 SCAR=6.9
Pod undocumented
374 0 %CLASS_DESCRIPTOR = ();
375 0 return;
376 }
377  
378 127 1;
« blib/lib/Linux/Event/_SocketConfig.pm ↑ Summary bench/run-stream-lifecycle-bench.pl »