CSV_PP.pm

filter: Statementstmt 93.2% 1878 / 2015 Branchbran 87.8% 1371 / 1560 Conditioncond 82.5% 951 / 1151 (1 uncoverable) MC/DCmcdc 71.0% 446 / 628 Subroutinesub 95.0% 135 / 142 Podpod 98.5% 68 / 69 totaltotal 87.1% 4849 / 5565 (1 uncoverable) CC 1195 SCAR 56.8
CC
1195
Cov
89%
____parse
1135.5
csv
147.9
_csv_attr
96.6
CRAP 294.3
↑ Summary CSV.pm »
1 package Text::CSV_PP;
2  
3 ################################################################################
4 #
5 # Text::CSV_PP - Text::CSV_XS compatible pure-Perl module
6 #
7 ################################################################################
8 39 require 5.006001;
9  
10 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 39 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 39 ▶use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 39 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 39 $VERSION = '2.06';
16 39 @ISA = qw(Exporter);
17  
18 12 ▶sub PV { 0 }
Subroutine PV: called CC=1 SCAR=0.0
Pod documented
19 18 ▶sub IV { 1 }
Subroutine IV: called CC=1 SCAR=0.0
Pod documented
20 16 ▶sub NV { 2 }
Subroutine NV: called CC=1 SCAR=0.0
Pod documented
21  
22 4 ▶sub CSV_TYPE_PV { PV }
Subroutine CSV_TYPE_PV: called CC=1 SCAR=0.0
Pod documented
23 4 ▶sub CSV_TYPE_IV { IV }
Subroutine CSV_TYPE_IV: called CC=1 SCAR=0.0
Pod documented
24 4 ▶sub CSV_TYPE_NV { NV }
Subroutine CSV_TYPE_NV: called CC=1 SCAR=0.0
Pod documented
25  
26 sub IS_QUOTED () { 0x0001; }
27 sub IS_BINARY () { 0x0002; }
28 sub IS_ERROR () { 0x0004; }
29 sub IS_MISSING () { 0x0010; }
30  
31 3317 ▶sub CSV_FLAGS_IS_QUOTED { IS_QUOTED }
Subroutine CSV_FLAGS_IS_QUOTED: called CC=1 SCAR=0.0
Pod documented
32 12 ▶sub CSV_FLAGS_IS_BINARY { IS_BINARY }
Subroutine CSV_FLAGS_IS_BINARY: called CC=1 SCAR=0.0
Pod documented
33 4 ▶sub CSV_FLAGS_ERROR_IN_FIELD { IS_ERROR }
Subroutine CSV_FLAGS_ERROR_IN_FIELD: called CC=1 SCAR=0.0
Pod documented
34 20 ▶sub CSV_FLAGS_IS_MISSING { IS_MISSING }
Subroutine CSV_FLAGS_IS_MISSING: called CC=1 SCAR=0.0
Pod documented
35  
36 sub HOOK_ERROR () { 0x0001; }
37 sub HOOK_AFTER_PARSE () { 0x0002; }
38 sub HOOK_BEFORE_PRINT () { 0x0004; }
39  
40 sub EOL_TYPE_UNDEF () { 0 }
41 sub EOL_TYPE_NL () { 1 }
42 sub EOL_TYPE_CR () { 2 }
43 sub EOL_TYPE_CRNL () { 3 }
44 sub EOL_TYPE_OTHER () { 4 }
45  
46 sub useIO_EOF () { 0x0010; }
47  
48 39 %EXPORT_TAGS = (
49 CONSTANTS => [qw(
50 CSV_FLAGS_IS_QUOTED
51 CSV_FLAGS_IS_BINARY
52 CSV_FLAGS_ERROR_IN_FIELD
53 CSV_FLAGS_IS_MISSING
54  
55 CSV_TYPE_PV
56 CSV_TYPE_IV
57 CSV_TYPE_NV
58 )],
59 );
60 39 @EXPORT_OK = (qw(csv PV IV NV), @{$EXPORT_TAGS{'CONSTANTS'}});
61  
62 39 my $ERRORS = {
63 # Generic errors
64 1000 => "INI - constructor failed",
65 1001 => "INI - sep_char is equal to quote_char or escape_char",
66 1002 => "INI - allow_whitespace with escape_char or quote_char SP or TAB",
67 1003 => "INI - \\r or \\n in main attr not allowed",
68 1004 => "INI - callbacks should be undef or a hashref",
69 1005 => "INI - EOL too long",
70 1006 => "INI - SEP too long",
71 1007 => "INI - QUOTE too long",
72 1008 => "INI - SEP undefined",
73  
74 1010 => "INI - the header is empty",
75 1011 => "INI - the header contains more than one valid separator",
76 1012 => "INI - the header contains an empty field",
77 1013 => "INI - the header contains nun-unique fields",
78 1014 => "INI - header called on undefined stream",
79  
80 # Syntax errors
81 1500 => "PRM - Invalid/unsupported arguments(s)",
82 1501 => "PRM - The key attribute is passed as an unsupported type",
83 1502 => "PRM - The value attribute is passed without the key attribute",
84 1503 => "PRM - The value attribute is passed as an unsupported type",
85  
86 # Parse errors
87 2010 => "ECR - QUO char inside quotes followed by CR not part of EOL",
88 2011 => "ECR - Characters after end of quoted field",
89 2012 => "EOF - End of data in parsing input stream",
90 2013 => "ESP - Specification error for fragments RFC7111",
91 2014 => "ENF - Inconsistent number of fields",
92 2015 => "ERW - Empty row",
93 2016 => "EOL - Inconsistent EOL",
94  
95 # EIQ - Error Inside Quotes
96 2021 => "EIQ - NL char inside quotes, binary off",
97 2022 => "EIQ - CR char inside quotes, binary off",
98 2023 => "EIQ - QUO character not allowed",
99 2024 => "EIQ - EOF cannot be escaped, not even inside quotes",
100 2025 => "EIQ - Loose unescaped escape",
101 2026 => "EIQ - Binary character inside quoted field, binary off",
102 2027 => "EIQ - Quoted field not terminated",
103  
104 # EIF - Error Inside Field
105 2030 => "EIF - NL char inside unquoted verbatim, binary off",
106 2031 => "EIF - CR char is first char of field, not part of EOL",
107 2032 => "EIF - CR char inside unquoted, not part of EOL",
108 2034 => "EIF - Loose unescaped quote",
109 2035 => "EIF - Escaped EOF in unquoted field",
110 2036 => "EIF - ESC error",
111 2037 => "EIF - Binary character in unquoted field, binary off",
112  
113 # Combine errors
114 2110 => "ECB - Binary character in Combine, binary off",
115  
116 # IO errors
117 2200 => "EIO - print to IO failed. See errno",
118  
119 # Hash-Ref errors
120 3001 => "EHR - Unsupported syntax for column_names ()",
121 3002 => "EHR - getline_hr () called before column_names ()",
122 3003 => "EHR - bind_columns () and column_names () fields count mismatch",
123 3004 => "EHR - bind_columns () only accepts refs to scalars",
124 3006 => "EHR - bind_columns () did not pass enough refs for parsed fields",
125 3007 => "EHR - bind_columns needs refs to writable scalars",
126 3008 => "EHR - unexpected error in bound fields",
127 3009 => "EHR - print_hr () called before column_names ()",
128 3010 => "EHR - print_hr () called with invalid arguments",
129  
130 4001 => "PRM - The key does not exist as field in the data",
131  
132 5001 => "PRM - The result does not match the output to append to",
133 5002 => "PRM - Unsupported output",
134  
135 0 => "",
136 };
137  
138 39 ▶BEGIN {
Subroutine BEGIN: called CC=7 SCAR=33.5
139 39 ▶ if ($] < 5.006) {
Branch: 3 branches
BranchTrueFalseTotal
if ($] < 5.006) { } 0 39 39
elsif ($] < 5.008) { } 0 39 39
elsif (not defined &utf8::is_utf8) { } 0 39 39
140 0 ▶ $INC{'bytes.pm'} = 1 unless $INC{'bytes.pm'}; # dummy
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"bytes.pm"} 0 0 0
141 39 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
142 0 ▶ *{"utf8::is_utf8"} = sub { 0; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
143 0 ▶ *{"utf8::decode"} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
144 }
145 elsif ($] < 5.008) {
146 39 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
147 0 ▶ *{"utf8::is_utf8"} = sub { 0; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
148 0 ▶ *{"utf8::decode"} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
149 0 ▶ *{"utf8::encode"} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
150 }
151 elsif (!defined &utf8::is_utf8) {
152 0 require Encode;
153 0 *utf8::is_utf8 = *Encode::is_utf8;
154 }
155  
156 39 eval q| require Scalar::Util |;
157 39 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 39 39
158 0 eval q| require B |;
159 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
160 0 Carp::croak $@;
161 }
162 else {
163 0 my %tmap = qw(
164 B::NULL SCALAR
165 B::HV HASH
166 B::AV ARRAY
167 B::CV CODE
168 B::IO IO
169 B::GV GLOB
170 B::REGEXP REGEXP
171 );
172 0 ▶ *Scalar::Util::reftype = sub (\$) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
173 0 my $r = shift;
174 0 ▶ return undef unless length(ref($r));
Branch: 1 branch
BranchTrueFalseTotal
unless length ref $r 0 0 0
175 0 my $t = ref(B::svref_2object($r));
176 return
177 0 ▶ exists $tmap{$t} ? $tmap{$t}
Branch: 2 branches
BranchTrueFalseTotal
exists $tmap{$t} ? : 0 0 0
length ref $$r ? : 0 0 0
178 : length(ref($$r)) ? 'REF'
179 : 'SCALAR';
180 0 };
181 0 ▶ *Scalar::Util::readonly = sub (\$) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
182 0 my $b = B::svref_2object($_[0]);
183 0 $b->FLAGS & 0x00800000; # SVf_READONLY?
184 0 };
185 }
186 }
187 }
188  
189 ################################################################################
190 #
191 # Common pure perl methods, taken almost directly from Text::CSV_XS.
192 # (These should be moved into a common class eventually, so that
193 # both XS and PP don't need to apply the same changes.)
194 #
195 ################################################################################
196  
197 ################################################################################
198 # version
199 ################################################################################
200  
201 2 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
Pod documented
202 2 return $VERSION;
203 }
204  
205 ################################################################################
206 # new
207 ################################################################################
208  
209 39 my %def_attr = (
210 eol => '',
211 sep_char => ',',
212 quote_char => '"',
213 escape_char => '"',
214 binary => 0,
215 decode_utf8 => 1,
216 auto_diag => 0,
217 diag_verbose => 0,
218 strict => 0,
219 strict_eol => 0,
220 blank_is_undef => 0,
221 empty_is_undef => 0,
222 allow_whitespace => 0,
223 allow_loose_quotes => 0,
224 allow_loose_escapes => 0,
225 allow_unquoted_escape => 0,
226 always_quote => 0,
227 quote_empty => 0,
228 quote_space => 1,
229 quote_binary => 1,
230 escape_null => 1,
231 keep_meta_info => 0,
232 verbatim => 0,
233 formula => 0,
234 skip_empty_rows => 0,
235 undef_str => undef,
236 comment_str => undef,
237 types => undef,
238 callbacks => undef,
239  
240 _EOF => "",
241 _RECNO => 0,
242 _STATUS => undef,
243 _FIELDS => undef,
244 _FFLAGS => undef,
245 _STRING => undef,
246 _ERROR_INPUT => undef,
247 _COLUMN_NAMES => undef,
248 _BOUND_COLUMNS => undef,
249 _AHEAD => undef,
250 _FORMULA_CB => undef,
251 _EMPTROW_CB => undef,
252  
253 ENCODING => undef,
254 );
255  
256 39 my %attr_alias = (
257 quote_always => "always_quote",
258 verbose_diag => "diag_verbose",
259 quote_null => "escape_null",
260 escape => "escape_char",
261 comment => "comment_str",
262 );
263  
264 39 my $last_err = Text::CSV_PP->SetDiag(0);
265 39 my $ebcdic = ord("A") == 0xC1; # Faster than $Config{'ebcdic'}
266 39 my @internal_kh;
267  
268 # NOT a method: is also used before bless
269 15757 ▶sub _unhealthy_whitespace {
Subroutine _unhealthy_whitespace: called CC=8 SCAR=20.8
270 15757 my ($self, $aw) = @_;
271 15757 ▶ $aw or return 0; # no checks needed without allow_whitespace
Branch: 1 branch
BranchTrueFalseTotal
$aw or return 0 3573 12184 15757
272  
273 3573 my $quo = $self->{quote};
274 3573 ▶ defined $quo && length($quo) or $quo = $self->{quote_char};
Branch: 1 branch
BranchTrueFalseTotal
defined $quo and length $quo or $quo = $self->{"quote_char"} 2 3571 3573
Condition100%3/3
defined $quo and length $quo
!ll&&!rl&&r
356832
MC/DC100%2/2
defined $quo and length $quo
defined $quo length $quo
Truth table100%3/3
A and B
A= defined $quoB= length $quo
ABresult
0X0
100
111
275 3573 my $esc = $self->{escape_char};
276  
277 3573 ▶ defined $quo && $quo =~ m/^[ \t]/ and return 1002;
Branch: 1 branch
BranchTrueFalseTotal
defined $quo and $quo =~ /^[ \t]/ and return 1002 242 3331 3573
Condition100%3/3
defined $quo and $quo =~ /^[ \t]/
!ll&&!rl&&r
23329242
MC/DC100%2/2
defined $quo and $quo =~ /^[ \t]/
defined $quo $quo =~ /^[ \t]/
Truth table100%3/3
A and B
A= defined $quoB= $quo =~ /^[ \t]/
ABresult
0X0
100
111
278 3331 ▶ defined $esc && $esc =~ m/^[ \t]/ and return 1002;
Branch: 1 branch
BranchTrueFalseTotal
defined $esc and $esc =~ /^[ \t]/ and return 1002 290 3041 3331
Condition100%3/3
defined $esc and $esc =~ /^[ \t]/
!ll&&!rl&&r
43037290
MC/DC100%2/2
defined $esc and $esc =~ /^[ \t]/
defined $esc $esc =~ /^[ \t]/
Truth table100%3/3
A and B
A= defined $escB= $esc =~ /^[ \t]/
ABresult
0X0
100
111
279  
280 3041 return 0;
281 }
282  
283 12451 ▶sub _check_sanity {
Subroutine _check_sanity: called CC=17 SCAR=28.3
284 12451 my $self = shift;
285  
286 12451 my $eol = $self->{eol};
287 12451 my $sep = $self->{sep};
288 12451 ▶ defined $sep && length($sep) or $sep = $self->{sep_char};
Branch: 1 branch
BranchTrueFalseTotal
defined $sep and length $sep or $sep = $self->{"sep_char"} 35 12416 12451
Condition100%3/3
defined $sep and length $sep
!ll&&!rl&&r
1199741935
MC/DC100%2/2
defined $sep and length $sep
defined $sep length $sep
Truth table100%3/3
A and B
A= defined $sepB= length $sep
ABresult
0X0
100
111
289 12451 my $quo = $self->{quote};
290 12451 ▶ defined $quo && length($quo) or $quo = $self->{quote_char};
Branch: 1 branch
BranchTrueFalseTotal
defined $quo and length $quo or $quo = $self->{"quote_char"} 18 12433 12451
Condition100%3/3
defined $quo and length $quo
!ll&&!rl&&r
124191418
MC/DC100%2/2
defined $quo and length $quo
defined $quo length $quo
Truth table100%3/3
A and B
A= defined $quoB= length $quo
ABresult
0X0
100
111
291 12451 my $esc = $self->{escape_char};
292  
293 # use DP;::diag ("SEP: '", DPeek ($sep),
294 # "', QUO: '", DPeek ($quo),
295 # "', ESC: '", DPeek ($esc),"'");
296  
297 # sep_char should not be undefined
298 12451 ▶ $sep ne "" or return 1008;
Branch: 1 branch
BranchTrueFalseTotal
$sep ne "" or return 1008 12449 2 12451
299 12449 ▶ length($sep) > 16 and return 1006;
Branch: 1 branch
BranchTrueFalseTotal
length $sep > 16 and return 1006 1 12448 12449
300 12448 ▶ $sep =~ m/[\r\n]/ and return 1003;
Branch: 1 branch
BranchTrueFalseTotal
$sep =~ /[\r\n]/ and return 1003 6 12442 12448
301  
302 12442 ▶ if (defined $quo) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $quo) 12431 11 12442
303 12431 ▶ $quo eq $sep and return 1001;
Branch: 1 branch
BranchTrueFalseTotal
$quo eq $sep and return 1001 228 12203 12431
304 12203 ▶ length($quo) > 16 and return 1007;
Branch: 1 branch
BranchTrueFalseTotal
length $quo > 16 and return 1007 1 12202 12203
305 12202 ▶ $quo =~ m/[\r\n]/ and return 1003;
Branch: 1 branch
BranchTrueFalseTotal
$quo =~ /[\r\n]/ and return 1003 6 12196 12202
306 }
307 12207 ▶ if (defined $esc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $esc) 12191 16 12207
308 12191 ▶ $esc eq $sep and return 1001;
Branch: 1 branch
BranchTrueFalseTotal
$esc eq $sep and return 1001 168 12023 12191
309 12023 ▶ $esc =~ m/[\r\n]/ and return 1003;
Branch: 1 branch
BranchTrueFalseTotal
$esc =~ /[\r\n]/ and return 1003 6 12017 12023
310 }
311 12033 ▶ if (defined $eol) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $eol) 12028 5 12033
312 12028 ▶ length($eol) > 16 and return 1005;
Branch: 1 branch
BranchTrueFalseTotal
length $eol > 16 and return 1005 1 12027 12028
313 }
314  
315 12032 return _unhealthy_whitespace($self, $self->{allow_whitespace});
316 }
317  
318 3 ▶sub known_attributes {
Subroutine known_attributes: called CC=1 SCAR=0.0
Pod documented
319 3 sort grep !m/^_/ => "sep", "quote", keys %def_attr;
320 }
321  
322 1025 ▶sub new {
Subroutine new: called CC=31 SCAR=34.3
Pod documented
323 1025 $last_err = Text::CSV_PP->SetDiag(1000,
324 "usage: my \$csv = Text::CSV_PP->new ([{ option => value, ... }]);");
325  
326 1025 my $proto = shift;
327 1025 ▶ my $class = ref $proto || $proto or return;
Branch: 1 branch
BranchTrueFalseTotal
my $class = ref $proto || $proto or return 1024 1 1025
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
010241
MC/DC50%1/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
328 1024 ▶ @_ > 0 && ref $_[0] ne "HASH" and return;
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 and ref $_[0] ne "HASH" and return 8 1016 1024
Condition100%3/3
@_ > 0 and ref $_[0] ne "HASH"
!ll&&!rl&&r
959218
MC/DC100%2/2
@_ > 0 and ref $_[0] ne "HASH"
@_ > 0 ref $_[0] ne "HASH"
Truth table100%3/3
A and B
A= @_ > 0B= ref $_[0] ne "HASH"
ABresult
0X0
100
111
329 1016 ▶ my $attr = shift || {};
Condition100%2/2
shift() || {}
l!l
92195
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
330 my %attr = map {
331 2801 ▶ my $k = m/^[a-zA-Z]\w+$/ ? lc $_ : $_;
Branch: 1 branch
BranchTrueFalseTotal
/^[a-zA-Z]\w+$/ ? : 2800 1 2801
332 2801 ▶ exists $attr_alias{$k} and $k = $attr_alias{$k};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr_alias{$k} and $k = $attr_alias{$k} 21 2780 2801
333 2801 ($k => $attr->{$_});
334 1016 } keys %{$attr};
335  
336 1016 my $sep_aliased = 0;
337 1016 ▶ if (exists $attr{sep}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr{"sep"}) 10 1006 1016
338 10 $attr{sep_char} = delete $attr{sep};
339 10 $sep_aliased = 1;
340 }
341 1016 my $quote_aliased = 0;
342 1016 ▶ if (exists $attr{quote}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr{"quote"}) 25 991 1016
343 25 $attr{quote_char} = delete $attr{quote};
344 25 $quote_aliased = 1;
345 }
346 exists $attr{formula_handling} and
347 1016 ▶ $attr{formula} = delete $attr{formula_handling};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr{"formula_handling"} and $attr{"formula"} = delete $attr{"formula_handling"} 12 1004 1016
348 1016 my $attr_formula = delete $attr{formula};
349  
350 1016 for (keys %attr) {
351 2763 ▶ if (m/^[a-z]/ && exists $def_attr{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[a-z]/ and exists $def_attr{$_}) 2756 7 2763
Condition100%3/3
/^[a-z]/ and exists $def_attr{$_}
!ll&&!rl&&r
162756
MC/DC100%2/2
/^[a-z]/ and exists $def_attr{$_}
/^[a-z]/ exists $def_attr{$_}
Truth table100%3/3
A and B
A= /^[a-z]/B= exists $def_attr{$_}
ABresult
0X0
100
111
352 # uncoverable condition false
353 2756 ▶ defined $attr{$_} && m/_char$/ and utf8::decode($attr{$_});
Branch: 1 branch
BranchTrueFalseTotal
defined $attr{$_} and /_char$/ and utf8::decode($attr{$_}) 216 2540 2756
Condition66%3/3
defined $attr{$_} and /_char$/
!ll&&!rl&&r
222518216
MC/DC100%2/2
defined $attr{$_} and /_char$/
defined $attr{$_} /_char$/
Truth table66%3/3
A and B
A= defined $attr{$_}B= /_char$/
ABresult
0X0
100
111
354 2756 next;
355 }
356 # croak?
357 7 $last_err = Text::CSV_PP->SetDiag(1000, "INI - Unknown attribute '$_'");
358 7 ▶ $attr{auto_diag} and error_diag();
Branch: 1 branch
BranchTrueFalseTotal
$attr{"auto_diag"} and error_diag() 1 6 7
359 7 return;
360 }
361 1009 ▶ if ($sep_aliased) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sep_aliased) 10 999 1009
362 10 my @b = unpack "U0C*", $attr{sep_char};
363 10 ▶ if (@b > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@b > 1) { } 6 4 10
364 6 $attr{sep} = $attr{sep_char};
365 6 $attr{sep_char} = "\0";
366 }
367 else {
368 4 $attr{sep} = undef;
369 }
370 }
371 1009 ▶ if ($quote_aliased and defined $attr{quote_char}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_aliased and defined $attr{"quote_char"}) 21 988 1009
Condition100%3/3
$quote_aliased and defined $attr{"quote_char"}
!ll&&!rl&&r
984421
MC/DC100%2/2
$quote_aliased and defined $attr{"quote_char"}
$quote_aliased defined $attr{"quote_char"}
Truth table100%3/3
A and B
A= $quote_aliasedB= defined $attr{"quote_char"}
ABresult
0X0
100
111
372 21 my @b = unpack "U0C*", $attr{quote_char};
373 21 ▶ if (@b > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@b > 1) { } 7 14 21
374 7 $attr{quote} = $attr{quote_char};
375 7 $attr{quote_char} = "\0";
376 }
377 else {
378 14 $attr{quote} = undef;
379 }
380 }
381  
382 1009 my $self = {%def_attr, %attr};
383 1009 ▶ if (my $ec = _check_sanity($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ec = _check_sanity($self)) 35 974 1009
384 35 $last_err = Text::CSV_PP->SetDiag($ec);
385 35 ▶ $attr{auto_diag} and error_diag();
Branch: 1 branch
BranchTrueFalseTotal
$attr{"auto_diag"} and error_diag() 1 34 35
386 35 return;
387 }
388 974 ▶ if (defined $self->{callbacks} && ref $self->{callbacks} ne "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"callbacks"} and ref $self->{"callbacks"} ne "HASH") 6 968 974
Condition100%3/3
defined $self->{"callbacks"} and ref $self->{"callbacks"} ne "HASH"
!ll&&!rl&&r
6443246
MC/DC100%2/2
defined $self->{"callbacks"} and ref $self->{"callbacks"} ne "HASH"
defined $self->{"callbacks"} ref $self->{"callbacks"} ne "HASH"
Truth table100%3/3
A and B
A= defined $self->{"callbacks"}B= ref $self->{"callbacks"} ne "HASH"
ABresult
0X0
100
111
389 6 carp("The 'callbacks' attribute is set but is not a hash: ignored\n");
390 6 $self->{callbacks} = undef;
391 }
392  
393 974 $last_err = Text::CSV_PP->SetDiag(0);
394 974 ▶ defined $\ && !exists $attr{eol} and $self->{eol} = $\;
Branch: 1 branch
BranchTrueFalseTotal
defined $\ and not exists $attr{"eol"} and $self->{"eol"} = $\ 8 966 974
Condition100%3/3
defined $\ and not exists $attr{"eol"}
!ll&&!rl&&r
96428
MC/DC100%2/2
defined $\ and not exists $attr{"eol"}
defined $\ not exists $attr{"eol"}
Truth table100%3/3
A and not(B)
A= defined $\B= not exists $attr{"eol"}
ABresult
0X0
100
111
395 974 bless $self, $class;
396 974 ▶ defined $self->{'types'} and $self->types($self->{'types'});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"types"} and $self->types($self->{"types"}) 1 973 974
397 974 ▶ defined $self->{'skip_empty_rows'} and $self->{'skip_empty_rows'} = _supported_skip_empty_rows($self, $self->{'skip_empty_rows'});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"skip_empty_rows"} and $self->{"skip_empty_rows"} = _supported_skip_empty_rows($self, $self->{"skip_empty_rows"}) 974 0 974
398 974 ▶ defined $attr_formula and $self->{'formula'} = _supported_formula($self, $attr_formula);
Branch: 1 branch
BranchTrueFalseTotal
defined $attr_formula and $self->{"formula"} = _supported_formula($self, $attr_formula) 36 938 974
399 973 $self;
400 }
401  
402 # Keep in sync with XS!
403 39 my %_cache_id = ( # Only expose what is accessed from within PM
404 quote_char => 0,
405 escape_char => 1,
406 sep_char => 2,
407 always_quote => 4,
408 quote_empty => 5,
409 quote_space => 6,
410 quote_binary => 7,
411 allow_loose_quotes => 8,
412 allow_loose_escapes => 9,
413 allow_unquoted_escape => 10,
414 allow_whitespace => 11,
415 blank_is_undef => 12,
416 empty_is_undef => 13,
417 auto_diag => 14,
418 diag_verbose => 15,
419 escape_null => 16,
420 formula => 18,
421 decode_utf8 => 21,
422 verbatim => 23,
423 strict_eol => 24,
424 eol_type => 27,
425 strict => 28,
426 skip_empty_rows => 29,
427 binary => 30,
428 keep_meta_info => 31,
429 _has_hooks => 32,
430 _has_ahead => 33,
431 _is_bound => 44,
432 eol => 100,
433 sep => 116,
434 quote => 132,
435 undef_str => 148,
436 comment_str => 156,
437 types => 92,
438 );
439  
440 39 my %_hidden_cache_id = (
441 has_error_input => 20,
442 eol_is_cr => 26,
443 eol_len => 36,
444 sep_len => 37,
445 quo_len => 38,
446 );
447  
448 my %_reverse_cache_id = (
449 1326 map({ $_cache_id{$_} => $_ } keys %_cache_id),
450 39 map({ $_hidden_cache_id{$_} => $_ } keys %_hidden_cache_id),
451 );
452  
453 # A `character'
454 11109 ▶sub _set_attr_C {
Subroutine _set_attr_C: called CC=3 SCAR=11.0
455 11109 my ($self, $name, $val, $ec) = @_;
456 11109 ▶ defined $val and utf8::decode($val);
Branch: 1 branch
BranchTrueFalseTotal
defined $val and utf8::decode($val) 11101 8 11109
457 11109 $self->{$name} = $val;
458 11109 ▶ $ec = _check_sanity($self) and croak($self->SetDiag($ec));
Branch: 1 branch
BranchTrueFalseTotal
$ec = _check_sanity($self) and croak($self->SetDiag($ec)) 910 10199 11109
459 10199 $self->_cache_set($_cache_id{$name}, $val);
460 }
461  
462 # A flag
463 5646 ▶sub _set_attr_X {
Subroutine _set_attr_X: called CC=2 SCAR=6.9
464 5646 my ($self, $name, $val) = @_;
465 5646 ▶ defined $val or $val = 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $val or $val = 0 5645 1 5646
466 5646 $self->{$name} = $val;
467 5646 $self->_cache_set($_cache_id{$name}, 0 + $val);
468 }
469  
470 # A number
471 68 ▶sub _set_attr_N {
Subroutine _set_attr_N: called CC=1 SCAR=0.0
472 68 my ($self, $name, $val) = @_;
473 68 $self->{$name} = $val;
474 68 $self->_cache_set($_cache_id{$name}, 0 + $val);
475 }
476  
477 # Accessor methods.
478 # It is unwise to change them halfway through a single file!
479 4836 ▶sub quote_char {
Subroutine quote_char: called CC=2 SCAR=6.9
Pod documented
480 4836 my $self = shift;
481 4836 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3601 1235 4836
482 3601 $self->_set_attr_C("quote_char", shift);
483 3374 $self->_cache_set($_cache_id{quote}, "");
484 }
485 4609 $self->{quote_char};
486 }
487  
488 20 ▶sub quote {
Subroutine quote: called CC=8 SCAR=20.8
Pod documented
489 20 my $self = shift;
490 20 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 9 20
491 11 my $quote = shift;
492 11 ▶ defined $quote or $quote = "";
Branch: 1 branch
BranchTrueFalseTotal
defined $quote or $quote = "" 10 1 11
493 11 utf8::decode($quote);
494 11 my @b = unpack "U0C*", $quote;
495 11 ▶ if (@b > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@b > 1) { } 5 6 11
496 5 ▶ @b > 16 and croak($self->SetDiag(1007));
Branch: 1 branch
BranchTrueFalseTotal
@b > 16 and croak($self->SetDiag(1007)) 1 4 5
497 4 $self->quote_char("\0");
498 }
499 else {
500 6 $self->quote_char($quote);
501 6 $quote = "";
502 }
503 10 $self->{quote} = $quote;
504  
505 10 my $ec = _check_sanity($self);
506 10 ▶ $ec and croak($self->SetDiag($ec));
Branch: 1 branch
BranchTrueFalseTotal
$ec and croak($self->SetDiag($ec)) 1 9 10
507  
508 9 $self->_cache_set($_cache_id{quote}, $quote);
509 }
510 18 my $quote = $self->{quote};
511 18 ▶ defined $quote && length($quote) ? $quote : $self->{quote_char};
Branch: 1 branch
BranchTrueFalseTotal
defined $quote && length $quote ? : 6 12 18
Condition100%3/3
defined $quote and length $quote
!ll&&!rl&&r
666
MC/DC100%2/2
defined $quote and length $quote
defined $quote length $quote
Truth table100%3/3
A and B
A= defined $quoteB= length $quote
ABresult
0X0
100
111
512 }
513  
514 4827 ▶sub escape_char {
Subroutine escape_char: called CC=3 SCAR=11.0
Pod documented
515 4827 my $self = shift;
516 4827 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3595 1232 4827
517 3595 my $ec = shift;
518 3595 $self->_set_attr_C("escape_char", $ec);
519 3480 ▶ $ec or $self->_set_attr_X("escape_null", 0);
Branch: 1 branch
BranchTrueFalseTotal
$ec or $self->_set_attr_X("escape_null", 0) 3474 6 3480
520 }
521 4712 $self->{escape_char};
522 }
523  
524 5156 ▶sub sep_char {
Subroutine sep_char: called CC=2 SCAR=6.9
Pod documented
525 5156 my $self = shift;
526 5156 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3913 1243 5156
527 3913 $self->_set_attr_C("sep_char", shift);
528 3345 $self->_cache_set($_cache_id{sep}, "");
529 }
530 4588 $self->{sep_char};
531 }
532  
533 360 ▶sub sep {
Subroutine sep: called CC=8 SCAR=20.8
Pod documented
534 360 my $self = shift;
535 360 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 327 33 360
536 327 my $sep = shift;
537 327 ▶ defined $sep or $sep = "";
Branch: 1 branch
BranchTrueFalseTotal
defined $sep or $sep = "" 326 1 327
538 327 utf8::decode($sep);
539 327 my @b = unpack "U0C*", $sep;
540 327 ▶ if (@b > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@b > 1) { } 13 314 327
541 13 ▶ @b > 16 and croak($self->SetDiag(1006));
Branch: 1 branch
BranchTrueFalseTotal
@b > 16 and croak($self->SetDiag(1006)) 1 12 13
542 12 $self->sep_char("\0");
543 }
544 else {
545 314 $self->sep_char($sep);
546 311 $sep = "";
547 }
548 323 $self->{sep} = $sep;
549  
550 323 my $ec = _check_sanity($self);
551 323 ▶ $ec and croak($self->SetDiag($ec));
Branch: 1 branch
BranchTrueFalseTotal
$ec and croak($self->SetDiag($ec)) 1 322 323
552  
553 322 $self->_cache_set($_cache_id{sep}, $sep);
554 }
555 355 my $sep = $self->{sep};
556 355 ▶ defined $sep && length($sep) ? $sep : $self->{sep_char};
Branch: 1 branch
BranchTrueFalseTotal
defined $sep && length $sep ? : 21 334 355
Condition100%3/3
defined $sep and length $sep
!ll&&!rl&&r
532921
MC/DC100%2/2
defined $sep and length $sep
defined $sep length $sep
Truth table100%3/3
A and B
A= defined $sepB= length $sep
ABresult
0X0
100
111
557 }
558  
559 280 ▶sub eol {
Subroutine eol: called CC=4 SCAR=13.9
Pod documented
560 280 my $self = shift;
561 280 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 227 53 280
562 227 my $eol = shift;
563 227 ▶ defined $eol or $eol = ""; # Also reset strict_eol?
Branch: 1 branch
BranchTrueFalseTotal
defined $eol or $eol = "" 98 129 227
564 227 ▶ length($eol) > 16 and croak($self->SetDiag(1005));
Branch: 1 branch
BranchTrueFalseTotal
length $eol > 16 and croak($self->SetDiag(1005)) 1 226 227
565 226 $self->{eol} = $eol;
566 226 $self->_cache_set($_cache_id{eol}, $eol);
567 }
568 279 $self->{eol};
569 }
570  
571 32 ▶sub eol_type {
Subroutine eol_type: called CC=1 SCAR=0.0
Pod documented
572 32 my $self = shift;
573 32 $self->_cache_get_eolt;
574 }
575  
576 3033 ▶sub always_quote {
Subroutine always_quote: called CC=2 SCAR=6.9
Pod documented
577 3033 my $self = shift;
578 3033 ▶ @_ and $self->_set_attr_X("always_quote", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("always_quote", shift()) 1800 1233 3033
579 3033 $self->{always_quote};
580 }
581  
582 10 ▶sub quote_space {
Subroutine quote_space: called CC=2 SCAR=6.9
Pod documented
583 10 my $self = shift;
584 10 ▶ @_ and $self->_set_attr_X("quote_space", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("quote_space", shift()) 6 4 10
585 10 $self->{quote_space};
586 }
587  
588 5 ▶sub quote_empty {
Subroutine quote_empty: called CC=2 SCAR=6.9
Pod documented
589 5 my $self = shift;
590 5 ▶ @_ and $self->_set_attr_X("quote_empty", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("quote_empty", shift()) 3 2 5
591 5 $self->{quote_empty};
592 }
593  
594 6 ▶sub escape_null {
Subroutine escape_null: called CC=2 SCAR=6.9
Pod documented
595 6 my $self = shift;
596 6 ▶ @_ and $self->_set_attr_X("escape_null", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("escape_null", shift()) 4 2 6
597 6 $self->{escape_null};
598 }
599  
600 3 ▶sub quote_null { goto &escape_null; }
Subroutine quote_null: called CC=1 SCAR=0.0
Pod undocumented
601  
602 7 ▶sub quote_binary {
Subroutine quote_binary: called CC=2 SCAR=6.9
Pod documented
603 7 my $self = shift;
604 7 ▶ @_ and $self->_set_attr_X("quote_binary", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("quote_binary", shift()) 6 1 7
605 7 $self->{quote_binary};
606 }
607  
608 21 ▶sub binary {
Subroutine binary: called CC=2 SCAR=6.9
Pod documented
609 21 my $self = shift;
610 21 ▶ @_ and $self->_set_attr_X("binary", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("binary", shift()) 12 9 21
611 21 $self->{binary};
612 }
613  
614 2 ▶sub strict {
Subroutine strict: called CC=2 SCAR=6.9
Pod documented
615 2 my $self = shift;
616 2 ▶ @_ and $self->_set_attr_X("strict", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("strict", shift()) 1 1 2
617 2 $self->{strict};
618 }
619  
620 2 ▶sub strict_eol {
Subroutine strict_eol: called CC=2 SCAR=6.9
Pod documented
621 2 my $self = shift;
622 2 ▶ @_ and $self->_set_attr_X("strict_eol", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("strict_eol", shift()) 1 1 2
623 2 $self->{'strict_eol'};
624 }
625  
626 995 ▶sub _supported_skip_empty_rows {
Subroutine _supported_skip_empty_rows: called CC=14 SCAR=28.2
627 995 my ($self, $f) = @_;
628 995 ▶ defined $f or return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $f or return 0 994 1 995
629 994 ▶ if ($self && $f && ref $f && ref $f eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self and $f and ref $f and ref $f eq "CODE") 5 989 994
Condition77%7/9
$self and $f and ref $f and ref $f eq "CODE"
!ll&&!rl&&r
98905
$self and $f and ref $f
!ll&&!rl&&r
933565
$self and $f
!ll&&!rl&&r
093361
MC/DC50%2/4
$self and $f and ref $f and ref $f eq "CODE"
$self $f ref $f ref $f eq "CODE"
Truth table60%3/5
A and B and C and D
A= $selfB= $fC= ref $fD= ref $f eq "CODE"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
630 5 $self->{'_EMPTROW_CB'} = $f;
631 5 return 6;
632 }
633 $f =~ m/^(?: 0 | undef )$/xi ? 0 :
634 $f =~ m/^(?: 1 | skip )$/xi ? 1 :
635 $f =~ m/^(?: 2 | eof | stop )$/xi ? 2 :
636 $f =~ m/^(?: 3 | die )$/xi ? 3 :
637 $f =~ m/^(?: 4 | croak )$/xi ? 4 :
638 $f =~ m/^(?: 5 | error )$/xi ? 5 :
639 989 ▶ $f =~ m/^(?: 6 | cb )$/xi ? 6 : do {
Branch: 7 branches
BranchTrueFalseTotal
$f =~ /^(?: 0 | undef )$/xi ? : 933 56 989
$f =~ /^(?: 1 | skip )$/xi ? : 32 24 56
$f =~ /^(?: 2 | eof | stop )$/xi ? : 7 17 24
$f =~ /^(?: 3 | die )$/xi ? : 6 11 17
$f =~ /^(?: 4 | croak )$/xi ? : 6 5 11
$f =~ /^(?: 5 | error )$/xi ? : 5 0 5
$f =~ /^(?: 6 | cb )$/xi ? : 0 0 0
640 0 ▶ $self ||= "Text::CSV_PP";
Condition0%0/2
$self ||= "Text::CSV_PP"
l!l
00
MC/DC0%0/1
$self ||= "Text::CSV_PP"
$self
Truth table0%0/2
A
A= $self
Aresult
11
00
641 0 croak($self->_SetDiagInfo(1500, "skip_empty_rows '$f' is not supported"));
642 };
643 }
644  
645 23 ▶sub skip_empty_rows {
Subroutine skip_empty_rows: called CC=8 SCAR=20.8
Pod documented
646 23 my $self = shift;
647 23 ▶ @_ and $self->_set_attr_N("skip_empty_rows", _supported_skip_empty_rows($self, shift));
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_N("skip_empty_rows", _supported_skip_empty_rows($self, shift())) 21 2 23
648 23 my $ser = $self->{'skip_empty_rows'};
649 23 ▶ $ser == 6 or $self->{'_EMPTROW_CB'} = undef;
Branch: 1 branch
BranchTrueFalseTotal
$ser == 6 or $self->{"_EMPTROW_CB"} = undef 1 22 23
650 $ser <= 1 ? $ser : $ser == 2 ? "eof" : $ser == 3 ? "die" :
651 $ser == 4 ? "croak" : $ser == 5 ? "error" :
652 23 ▶ $self->{'_EMPTROW_CB'};
Branch: 5 branches
BranchTrueFalseTotal
$ser <= 1 ? : 8 15 23
$ser == 2 ? : 5 10 15
$ser == 3 ? : 3 7 10
$ser == 4 ? : 3 4 7
$ser == 5 ? : 3 1 4
653 }
654  
655 17 ▶sub _SetDiagInfo {
Subroutine _SetDiagInfo: called CC=3 SCAR=11.2
656 17 my ($self, $err, $msg) = @_;
657 17 $self->SetDiag($err);
658 17 my $em = $self->error_diag();
659 17 ▶ $em =~ s/^\d+$// and $msg =~ s/^/# /;
Branch: 1 branch
BranchTrueFalseTotal
$em =~ s/^\d+$// and $msg =~ s/^/# / 0 17 17
660 17 ▶ my $sep = $em =~ m/[;\n]$/ ? "\n\t" : ": ";
Branch: 1 branch
BranchTrueFalseTotal
$em =~ /[;\n]$/ ? : 0 17 17
661 17 join $sep => grep m/\S\S\S/ => $em, $msg;
662 }
663  
664 103 ▶sub _supported_formula {
Subroutine _supported_formula: called CC=14 SCAR=26.4
665 103 my ($self, $f) = @_;
666 103 ▶ defined $f or return 5;
Branch: 1 branch
BranchTrueFalseTotal
defined $f or return 5 102 1 103
667 102 ▶ if ($self && $f && ref $f && ref $f eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self and $f and ref $f and ref $f eq "CODE") 6 96 102
Condition88%8/9
$self and $f and ref $f and ref $f eq "CODE"
!ll&&!rl&&r
9426
$self and $f and ref $f
!ll&&!rl&&r
13818
$self and $f
!ll&&!rl&&r
01389
MC/DC75%3/4
$self and $f and ref $f and ref $f eq "CODE"
$self $f ref $f ref $f eq "CODE"
Truth table80%4/5
A and B and C and D
A= $selfB= $fC= ref $fD= ref $f eq "CODE"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
668 6 $self->{_FORMULA_CB} = $f;
669 6 return 6;
670 }
671 $f =~ m/^(?: 0 | none )$/xi ? 0 :
672 $f =~ m/^(?: 1 | die )$/xi ? 1 :
673 $f =~ m/^(?: 2 | croak )$/xi ? 2 :
674 $f =~ m/^(?: 3 | diag )$/xi ? 3 :
675 $f =~ m/^(?: 4 | empty | )$/xi ? 4 :
676 $f =~ m/^(?: 5 | undef )$/xi ? 5 :
677 96 ▶ $f =~ m/^(?: 6 | cb )$/xi ? 6 : do {
Branch: 7 branches
BranchTrueFalseTotal
$f =~ /^(?: 0 | none )$/xi ? : 16 80 96
$f =~ /^(?: 1 | die )$/xi ? : 13 67 80
$f =~ /^(?: 2 | croak )$/xi ? : 13 54 67
$f =~ /^(?: 3 | diag )$/xi ? : 16 38 54
$f =~ /^(?: 4 | empty | )$/xi ? : 15 23 38
$f =~ /^(?: 5 | undef )$/xi ? : 14 9 23
$f =~ /^(?: 6 | cb )$/xi ? : 2 7 9
678 7 ▶ $self ||= "Text::CSV_PP";
Condition50%1/2
$self ||= "Text::CSV_PP"
l!l
70
MC/DC0%0/1
$self ||= "Text::CSV_PP"
$self
Truth table50%1/2
A
A= $self
Aresult
11
00
679 7 croak($self->_SetDiagInfo(1500, "formula-handling '$f' is not supported"));
680 };
681 }
682  
683 44 ▶sub formula {
Subroutine formula: called CC=3 SCAR=11.0
Pod documented
684 44 my $self = shift;
685 44 ▶ @_ and $self->_set_attr_N("formula", _supported_formula($self, shift));
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_N("formula", _supported_formula($self, shift())) 29 15 44
686 38 ▶ $self->{formula} == 6 or $self->{_FORMULA_CB} = undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"formula"} == 6 or $self->{"_FORMULA_CB"} = undef 2 36 38
687 38 [qw( none die croak diag empty undef cb )]->[_supported_formula($self, $self->{formula})];
688 }
689 7 ▶sub formula_handling {
Subroutine formula_handling: called CC=1 SCAR=0.0
Pod documented
690 7 my $self = shift;
691 7 $self->formula(@_);
692 }
693  
694 2 ▶sub decode_utf8 {
Subroutine decode_utf8: called CC=2 SCAR=6.9
Pod documented
695 2 my $self = shift;
696 2 ▶ @_ and $self->_set_attr_X("decode_utf8", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("decode_utf8", shift()) 1 1 2
697 2 $self->{decode_utf8};
698 }
699  
700 12 ▶sub keep_meta_info {
Subroutine keep_meta_info: called CC=6 SCAR=17.9
Pod documented
701 12 my $self = shift;
702 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 1 12
703 11 my $v = shift;
704 11 ▶ !defined $v || $v eq "" and $v = 0;
Branch: 1 branch
BranchTrueFalseTotal
!defined($v) || $v eq "" and $v = 0 2 9 11
Condition100%3/3
not defined $v or $v eq ""
l!l&&r!l&&!r
119
MC/DC100%2/2
not defined $v or $v eq ""
not defined $v $v eq ""
Truth table100%3/3
not(A) or B
A= not defined $vB= $v eq ""
ABresult
1X1
011
000
705 11 ▶ $v =~ m/^[0-9]/ or $v = lc $v eq "false" ? 0 : 1; # true/truth = 1
Branch: 2 branches
BranchTrueFalseTotal
$v =~ /^[0-9]/ or $v = lc $v eq "false" ? 0 : 1 9 2 11
lc $v eq 'false' ? : 1 1 2
706 11 $self->_set_attr_X("keep_meta_info", $v);
707 }
708 12 $self->{keep_meta_info};
709 }
710  
711 12 ▶sub allow_loose_quotes {
Subroutine allow_loose_quotes: called CC=2 SCAR=6.9
Pod documented
712 12 my $self = shift;
713 12 ▶ @_ and $self->_set_attr_X("allow_loose_quotes", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("allow_loose_quotes", shift()) 11 1 12
714 12 $self->{allow_loose_quotes};
715 }
716  
717 12 ▶sub allow_loose_escapes {
Subroutine allow_loose_escapes: called CC=2 SCAR=6.9
Pod documented
718 12 my $self = shift;
719 12 ▶ @_ and $self->_set_attr_X("allow_loose_escapes", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("allow_loose_escapes", shift()) 11 1 12
720 12 $self->{allow_loose_escapes};
721 }
722  
723 4954 ▶sub allow_whitespace {
Subroutine allow_whitespace: called CC=3 SCAR=11.0
Pod documented
724 4954 my $self = shift;
725 4954 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3725 1229 4954
726 3725 my $aw = shift;
727 3725 ▶ _unhealthy_whitespace($self, $aw) and
Branch: 1 branch
BranchTrueFalseTotal
_unhealthy_whitespace($self, $aw) and croak($self->SetDiag(1002)) 4 3721 3725
728 croak($self->SetDiag(1002));
729 3721 $self->_set_attr_X("allow_whitespace", $aw);
730 }
731 4950 $self->{allow_whitespace};
732 }
733  
734 4 ▶sub allow_unquoted_escape {
Subroutine allow_unquoted_escape: called CC=2 SCAR=6.9
Pod documented
735 4 my $self = shift;
736 4 ▶ @_ and $self->_set_attr_X("allow_unquoted_escape", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("allow_unquoted_escape", shift()) 3 1 4
737 4 $self->{allow_unquoted_escape};
738 }
739  
740 3 ▶sub blank_is_undef {
Subroutine blank_is_undef: called CC=2 SCAR=6.9
Pod documented
741 3 my $self = shift;
742 3 ▶ @_ and $self->_set_attr_X("blank_is_undef", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("blank_is_undef", shift()) 2 1 3
743 3 $self->{blank_is_undef};
744 }
745  
746 2 ▶sub empty_is_undef {
Subroutine empty_is_undef: called CC=2 SCAR=6.9
Pod documented
747 2 my $self = shift;
748 2 ▶ @_ and $self->_set_attr_X("empty_is_undef", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("empty_is_undef", shift()) 1 1 2
749 2 $self->{empty_is_undef};
750 }
751  
752 9 ▶sub verbatim {
Subroutine verbatim: called CC=2 SCAR=6.9
Pod documented
753 9 my $self = shift;
754 9 ▶ @_ and $self->_set_attr_X("verbatim", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("verbatim", shift()) 7 2 9
755 9 $self->{verbatim};
756 }
757  
758 12 ▶sub undef_str {
Subroutine undef_str: called CC=3 SCAR=11.0
Pod documented
759 12 my $self = shift;
760 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 1 12
761 11 my $v = shift;
762 11 ▶ $self->{undef_str} = defined $v ? "$v" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 9 2 11
763 11 $self->_cache_set($_cache_id{undef_str}, $self->{undef_str});
764 }
765 12 $self->{undef_str};
766 }
767  
768 15 ▶sub comment_str {
Subroutine comment_str: called CC=3 SCAR=11.0
Pod documented
769 15 my $self = shift;
770 15 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 1 15
771 14 my $v = shift;
772 14 ▶ $self->{comment_str} = defined $v ? "$v" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 13 1 14
773 14 $self->_cache_set($_cache_id{comment_str}, $self->{comment_str});
774 }
775 15 $self->{comment_str};
776 }
777  
778 12 ▶sub auto_diag {
Subroutine auto_diag: called CC=6 SCAR=17.9
Pod documented
779 12 my $self = shift;
780 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 9 3 12
781 9 my $v = shift;
782 9 ▶ !defined $v || $v eq "" and $v = 0;
Branch: 1 branch
BranchTrueFalseTotal
!defined($v) || $v eq "" and $v = 0 2 7 9
Condition100%3/3
not defined $v or $v eq ""
l!l&&r!l&&!r
117
MC/DC100%2/2
not defined $v or $v eq ""
not defined $v $v eq ""
Truth table100%3/3
not(A) or B
A= not defined $vB= $v eq ""
ABresult
1X1
011
000
783 9 ▶ $v =~ m/^[0-9]/ or $v = lc $v eq "false" ? 0 : 1; # true/truth = 1
Branch: 2 branches
BranchTrueFalseTotal
$v =~ /^[0-9]/ or $v = lc $v eq "false" ? 0 : 1 7 2 9
lc $v eq 'false' ? : 1 1 2
784 9 $self->_set_attr_X("auto_diag", $v);
785 }
786 12 $self->{auto_diag};
787 }
788  
789 10 ▶sub diag_verbose {
Subroutine diag_verbose: called CC=6 SCAR=17.9
Pod documented
790 10 my $self = shift;
791 10 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 2 10
792 8 my $v = shift;
793 8 ▶ !defined $v || $v eq "" and $v = 0;
Branch: 1 branch
BranchTrueFalseTotal
!defined($v) || $v eq "" and $v = 0 2 6 8
Condition100%3/3
not defined $v or $v eq ""
l!l&&r!l&&!r
116
MC/DC100%2/2
not defined $v or $v eq ""
not defined $v $v eq ""
Truth table100%3/3
not(A) or B
A= not defined $vB= $v eq ""
ABresult
1X1
011
000
794 8 ▶ $v =~ m/^[0-9]/ or $v = lc $v eq "false" ? 0 : 1; # true/truth = 1
Branch: 2 branches
BranchTrueFalseTotal
$v =~ /^[0-9]/ or $v = lc $v eq "false" ? 0 : 1 6 2 8
lc $v eq 'false' ? : 1 1 2
795 8 $self->_set_attr_X("diag_verbose", $v);
796 }
797 10 $self->{diag_verbose};
798 }
799  
800 ################################################################################
801 # status
802 ################################################################################
803  
804 5 ▶sub status {
Subroutine status: called CC=1 SCAR=0.0
Pod documented
805 5 my $self = shift;
806 5 return $self->{_STATUS};
807 }
808  
809 33 ▶sub eof {
Subroutine eof: called CC=1 SCAR=0.0
Pod documented
810 33 my $self = shift;
811 33 return $self->{_EOF};
812 }
813  
814 7 ▶sub types {
Subroutine types: called CC=3 SCAR=11.0
Pod documented
815 7 my $self = shift;
816  
817 7 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 5 7
818 2 ▶ if (my $types = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $types = shift()) { } 1 1 2
819 1 $self->{'_types'} = join "", map { chr } @{$types};
820 1 $self->{'types'} = $types;
821 1 $self->_cache_set($_cache_id{'types'}, $self->{'_types'});
822 }
823 else {
824 1 delete $self->{'types'};
825 1 delete $self->{'_types'};
826 1 $self->_cache_set($_cache_id{'types'}, undef);
827 1 undef;
828 }
829 }
830 else {
831 5 $self->{'types'};
832 }
833 }
834  
835 74 ▶sub callbacks {
Subroutine callbacks: called CC=14 SCAR=26.4
Pod documented
836 74 my $self = shift;
837 74 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 44 30 74
838 44 my $cb;
839 44 my $hf = 0x00;
840 44 ▶ if (defined $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[0]) { } 42 2 44
elsif (@_ > 1) { } 1 1 2
841 42 ▶ grep { !defined } @_ and croak($self->SetDiag(1004));
Branch: 1 branch
BranchTrueFalseTotal
grep {not defined $_;} @_ and croak($self->SetDiag(1004)) 2 40 42
842 40 ▶ $cb = @_ == 1 && ref $_[0] eq "HASH" ? shift
Branch: 2 branches
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'HASH' ? : 8 32 40
@_ % 2 == 0 ? : 27 5 32
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
2848
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
843 : @_ % 2 == 0 ? {@_}
844 : croak($self->SetDiag(1004));
845 35 foreach my $cbk (keys %{$cb}) {
846 # A key cannot be a ref. That would be stored as the *string
847 # 'SCALAR(0x1f3e710)' or 'ARRAY(0x1a5ae18)'
848 37 ▶ $cbk =~ m/^[\w.]+$/ && ref $cb->{$cbk} eq "CODE" or
Branch: 1 branch
BranchTrueFalseTotal
$cbk =~ /^[\w.]+$/ and ref $cb->{$cbk} eq "CODE" or croak($self->SetDiag(1004)) 23 14 37
Condition100%3/3
$cbk =~ /^[\w.]+$/ and ref $cb->{$cbk} eq "CODE"
!ll&&!rl&&r
41023
MC/DC100%2/2
$cbk =~ /^[\w.]+$/ and ref $cb->{$cbk} eq "CODE"
$cbk =~ /^[\w.]+$/ ref $cb->{$cbk} eq "CODE"
Truth table100%3/3
A and B
A= $cbk =~ /^[\w.]+$/B= ref $cb->{$cbk} eq "CODE"
ABresult
0X0
100
111
849 croak($self->SetDiag(1004));
850 }
851 21 ▶ exists $cb->{error} and $hf |= 0x01;
Branch: 1 branch
BranchTrueFalseTotal
exists $cb->{"error"} and $hf |= 1 3 18 21
852 21 ▶ exists $cb->{after_parse} and $hf |= 0x02;
Branch: 1 branch
BranchTrueFalseTotal
exists $cb->{"after_parse"} and $hf |= 2 18 3 21
853 21 ▶ exists $cb->{before_print} and $hf |= 0x04;
Branch: 1 branch
BranchTrueFalseTotal
exists $cb->{"before_print"} and $hf |= 4 1 20 21
854 }
855 elsif (@_ > 1) {
856 # (undef, whatever)
857 1 croak($self->SetDiag(1004));
858 }
859 22 $self->_set_attr_X("_has_hooks", $hf);
860 22 $self->{callbacks} = $cb;
861 }
862 52 $self->{callbacks};
863 }
864  
865 ################################################################################
866 # error_diag
867 ################################################################################
868  
869 1864 ▶sub error_diag {
Subroutine error_diag: called CC=31 SCAR=35.9
Pod documented
870 1864 my $self = shift;
871 1864 my @diag = (0 + $last_err, $last_err, 0, 0, 0, 0);
872  
873 # Docs state to NEVER use UNIVERSAL::isa, because it will *never* call an
874 # overridden isa method in any class. Well, that is exacly what I want here
875 1864 ▶ if ($self && ref $self and # Not a class method or direct call
Branch: 1 branch
BranchTrueFalseTotal
if ($self and ref $self and (UNIVERSAL::isa($self, __PACKAGE__) and exists $self->{"_ERROR_DIAG"})) 1685 179 1864
Condition100%9/9
$self and ref $self and (UNIVERSAL::isa($self, __PACKAGE__) and exists $self->{"_ERROR_DIAG"})
!ll&&!rl&&r
701091685
$self and ref $self
!ll&&!rl&&r
6641794
UNIVERSAL::isa($self, __PACKAGE__) and exists $self->{"_ERROR_DIAG"}
!ll&&!rl&&r
11081685
MC/DC100%4/4
$self and ref $self and (UNIVERSAL::isa($self, __PACKAGE__) and exists $self->{"_ERROR_DIAG"})
$self ref $self UNIVERSAL::isa($self, __PACKAGE__) exists $self->{"_ERROR_DIAG"}
Truth table100%5/5
A and B and C and D
A= $selfB= ref $selfC= UNIVERSAL::isa($self, __PACKAGE__)D= exists $self->{"_ERROR_DIAG"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
876 UNIVERSAL::isa($self, __PACKAGE__) && exists $self->{_ERROR_DIAG}) {
877 1685 $diag[0] = 0 + $self->{_ERROR_DIAG};
878 1685 $diag[1] = $self->{_ERROR_DIAG};
879 1685 ▶ $diag[2] = 1 + $self->{_ERROR_POS} if exists $self->{_ERROR_POS};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_ERROR_POS"} 388 1297 1685
880 1685 $diag[3] = $self->{_RECNO};
881 1685 ▶ $diag[4] = $self->{_ERROR_FLD} if exists $self->{_ERROR_FLD};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_ERROR_FLD"} 388 1297 1685
882 1685 ▶ $diag[5] = $self->{_ERROR_SRC} if exists $self->{_ERROR_SRC} && $self->{diag_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_ERROR_SRC"} and $self->{"diag_verbose"} 37 1648 1685
Condition100%3/3
exists $self->{"_ERROR_SRC"} and $self->{"diag_verbose"}
!ll&&!rl&&r
130234637
MC/DC100%2/2
exists $self->{"_ERROR_SRC"} and $self->{"diag_verbose"}
exists $self->{"_ERROR_SRC"} $self->{"diag_verbose"}
Truth table100%3/3
A and B
A= exists $self->{"_ERROR_SRC"}B= $self->{"diag_verbose"}
ABresult
0X0
100
111
883  
884 $diag[0] && $self->{callbacks} && $self->{callbacks}{error} and
885 1685 ▶ return $self->{callbacks}{error}->(@diag);
Branch: 1 branch
BranchTrueFalseTotal
$diag[0] and $self->{"callbacks"} and $self->{"callbacks"}{"error"} and return $self->{"callbacks"}{"error"}->(@diag) 10 1675 1685
Condition100%6/6
$diag[0] and $self->{"callbacks"} and $self->{"callbacks"}{"error"}
!ll&&!rl&&r
135232310
$diag[0] and $self->{"callbacks"}
!ll&&!rl&&r
71345333
MC/DC100%3/3
$diag[0] and $self->{"callbacks"} and $self->{"callbacks"}{"error"}
$diag[0] $self->{"callbacks"} $self->{"callbacks"}{"error"}
Truth table100%4/4
A and B and C
A= $diag[0]B= $self->{"callbacks"}C= $self->{"callbacks"}{"error"}
ABCresult
0XX0
10X0
1100
1111
886 }
887  
888 1854 my $context = wantarray;
889  
890 1854 ▶ unless (defined $context) { # Void context, auto-diag
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $context) 387 1467 1854
891 387 ▶ if ($diag[0] && $diag[0] != 2012) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diag[0] and $diag[0] != 2012) 80 307 387
Condition100%3/3
$diag[0] and $diag[0] != 2012
!ll&&!rl&&r
1029780
MC/DC100%2/2
$diag[0] and $diag[0] != 2012
$diag[0] $diag[0] != 2012
Truth table100%3/3
A and B
A= $diag[0]B= $diag[0] != 2012
ABresult
0X0
100
111
892 80 my $msg = "# CSV_PP ERROR: $diag[0] - $diag[1] \@ rec $diag[3] pos $diag[2]\n";
893 80 ▶ $diag[4] and $msg =~ s/$/ field $diag[4]/;
Branch: 1 branch
BranchTrueFalseTotal
$diag[4] and $msg =~ s/$/ field $diag[4]/ 69 11 80
894 80 ▶ $diag[5] and $msg =~ s/$/ (PP#$diag[5])/;
Branch: 1 branch
BranchTrueFalseTotal
$diag[5] and $msg =~ s/$/ (PP#$diag[5])/ 16 64 80
895  
896 80 ▶ unless ($self && ref $self) { # auto_diag
Branch: 1 branch
BranchTrueFalseTotal
unless ($self and ref $self) 4 76 80
Condition100%3/3
$self and ref $self
!ll&&!rl&&r
3176
MC/DC100%2/2
$self and ref $self
$self ref $self
Truth table100%3/3
A and B
A= $selfB= ref $self
ABresult
0X0
100
111
897 # called without args in void context
898 4 warn $msg;
899 4 return;
900 }
901  
902 $self->{diag_verbose} && $self->{_ERROR_INPUT} and
903 76 ▶ $msg .= $self->{_ERROR_INPUT} . "\n" .
Branch: 1 branch
BranchTrueFalseTotal
$self->{"diag_verbose"} and $self->{"_ERROR_INPUT"} and $msg .= $self->{"_ERROR_INPUT"} . "\n" . " " x ($diag[2] - 1) . "^\n" 16 60 76
Condition66%2/3
$self->{"diag_verbose"} and $self->{"_ERROR_INPUT"}
!ll&&!rl&&r
60016
MC/DC50%1/2
$self->{"diag_verbose"} and $self->{"_ERROR_INPUT"}
$self->{"diag_verbose"} $self->{"_ERROR_INPUT"}
Truth table66%2/3
A and B
A= $self->{"diag_verbose"}B= $self->{"_ERROR_INPUT"}
ABresult
0X0
100
111
904 (" " x ($diag[2] - 1)) . "^\n";
905  
906 76 my $lvl = $self->{auto_diag};
907 76 ▶ if ($lvl < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lvl < 2) 73 3 76
908 73 my @c = caller(2);
909 73 ▶ if (@c >= 11 && $c[10] && ref $c[10] eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (@c >= 11 and $c[10] and ref $c[10] eq "HASH") 0 73 73
Condition50%3/6
@c >= 11 and $c[10] and ref $c[10] eq "HASH"
!ll&&!rl&&r
7300
@c >= 11 and $c[10]
!ll&&!rl&&r
1720
MC/DC0%0/3
@c >= 11 and $c[10] and ref $c[10] eq "HASH"
@c >= 11 $c[10] ref $c[10] eq "HASH"
Truth table50%2/4
A and B and C
A= @c >= 11B= $c[10]C= ref $c[10] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
910 0 my $hints = $c[10];
911 (exists $hints->{autodie} && $hints->{autodie} or
912 exists $hints->{'guard Fatal'} &&
913 0 ▶ !exists $hints->{'no Fatal'}) and
Branch: 1 branch
BranchTrueFalseTotal
exists $hints->{"autodie"} && $hints->{"autodie"} || exists $hints->{"guard Fatal"} && !exists $hints->{"no Fatal"} and ++$lvl 0 0 0
Condition0%0/9
exists $hints->{"autodie"} and $hints->{"autodie"} or exists $hints->{"guard Fatal"} and not exists $hints->{"no Fatal"}
l!l&&r!l&&!r
000
exists $hints->{"autodie"} and $hints->{"autodie"}
!ll&&!rl&&r
000
exists $hints->{"guard Fatal"} and not exists $hints->{"no Fatal"}
!ll&&!rl&&r
000
MC/DC0%0/4
exists $hints->{"autodie"} and $hints->{"autodie"} or exists $hints->{"guard Fatal"} and not exists $hints->{"no Fatal"}
exists $hints->{"autodie"} $hints->{"autodie"} exists $hints->{"guard Fatal"} not exists $hints->{"no Fatal"}
Truth table0%0/7
A and B or C and not(D)
A= exists $hints->{"autodie"}B= $hints->{"autodie"}C= exists $hints->{"guard Fatal"}D= not exists $hints->{"no Fatal"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
914 $lvl++;
915 # Future releases of autodie will probably set $^H{autodie}
916 # to "autodie @args", like "autodie :all" or "autodie open"
917 # so we can/should check for "open" or "new"
918 }
919 }
920 76 ▶ $lvl > 1 ? die $msg : warn $msg;
Branch: 1 branch
BranchTrueFalseTotal
$lvl > 1 ? : 3 73 76
921 }
922 380 return;
923 }
924  
925 1467 ▶ return $context ? @diag : $diag[1];
Branch: 1 branch
BranchTrueFalseTotal
$context ? : 268 1199 1467
926 }
927  
928 14 ▶sub record_number {
Subroutine record_number: called CC=1 SCAR=0.0
Pod documented
929 14 my $self = shift;
930 14 return $self->{_RECNO};
931 }
932  
933 ################################################################################
934 # string
935 ################################################################################
936  
937 39 *string = \&_string;
938 1401 ▶sub _string {
Subroutine _string: called CC=2 SCAR=6.9
939 1401 my $self = shift;
940 1401 ▶ return ref $self->{_STRING} ? ${$self->{_STRING}} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_STRING'} ? : 1400 1 1401
941 }
942  
943 ################################################################################
944 # fields
945 ################################################################################
946  
947 39 *fields = \&_fields;
948 1617 ▶sub _fields {
Subroutine _fields: called CC=2 SCAR=6.9
949 1617 my $self = shift;
950 1617 ▶ return ref $self->{_FIELDS} ? @{$self->{_FIELDS}} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_FIELDS'} ? : 1616 1 1617
951 }
952  
953 ################################################################################
954 # meta_info
955 ################################################################################
956  
957 21 ▶sub meta_info {
Subroutine meta_info: called CC=2 SCAR=6.9
Pod documented
958 21 my $self = shift;
959 21 ▶ return ref $self->{_FFLAGS} ? @{$self->{_FFLAGS}} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_FFLAGS'} ? : 16 5 21
960 }
961  
962 29 ▶sub is_quoted {
Subroutine is_quoted: called CC=5 SCAR=16.1
Pod documented
963 29 my ($self, $idx) = @_;
964 ref $self->{_FFLAGS} &&
965 29 ▶ $idx >= 0 && $idx < @{$self->{_FFLAGS}} or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"_FFLAGS"} and $idx >= 0 and $idx < @{$self->{"_FFLAGS"};} or return 24 5 29
Condition100%6/6
ref $self->{"_FFLAGS"} and $idx >= 0 and $idx < @{$self->{"_FFLAGS"};}
!ll&&!rl&&r
4124
ref $self->{"_FFLAGS"} and $idx >= 0
!ll&&!rl&&r
3125
MC/DC100%3/3
ref $self->{"_FFLAGS"} and $idx >= 0 and $idx < @{$self->{"_FFLAGS"};}
ref $self->{"_FFLAGS"} $idx >= 0 $idx < @{$self->{"_FFLAGS"};}
Truth table100%4/4
A and B and C
A= ref $self->{"_FFLAGS"}B= $idx >= 0C= $idx < @{$self->{"_FFLAGS"};}
ABCresult
0XX0
10X0
1100
1111
966 24 ▶ $self->{_FFLAGS}[$idx] & CSV_FLAGS_IS_QUOTED() ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_QUOTED() ? : 10 14 24
967 }
968  
969 11 ▶sub is_binary {
Subroutine is_binary: called CC=5 SCAR=16.1
Pod documented
970 11 my ($self, $idx) = @_;
971 ref $self->{_FFLAGS} &&
972 11 ▶ $idx >= 0 && $idx < @{$self->{_FFLAGS}} or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"_FFLAGS"} and $idx >= 0 and $idx < @{$self->{"_FFLAGS"};} or return 8 3 11
Condition100%6/6
ref $self->{"_FFLAGS"} and $idx >= 0 and $idx < @{$self->{"_FFLAGS"};}
!ll&&!rl&&r
218
ref $self->{"_FFLAGS"} and $idx >= 0
!ll&&!rl&&r
119
MC/DC100%3/3
ref $self->{"_FFLAGS"} and $idx >= 0 and $idx < @{$self->{"_FFLAGS"};}
ref $self->{"_FFLAGS"} $idx >= 0 $idx < @{$self->{"_FFLAGS"};}
Truth table100%4/4
A and B and C
A= ref $self->{"_FFLAGS"}B= $idx >= 0C= $idx < @{$self->{"_FFLAGS"};}
ABCresult
0XX0
10X0
1100
1111
973 8 ▶ $self->{_FFLAGS}[$idx] & CSV_FLAGS_IS_BINARY() ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_BINARY() ? : 4 4 8
974 }
975  
976 19 ▶sub is_missing {
Subroutine is_missing: called CC=5 SCAR=16.1
Pod documented
977 19 my ($self, $idx) = @_;
978 19 ▶ $idx < 0 || !ref $self->{_FFLAGS} and return;
Branch: 1 branch
BranchTrueFalseTotal
$idx < 0 || !ref($self->{"_FFLAGS"}) and return 8 11 19
Condition100%3/3
$idx < 0 or not ref $self->{"_FFLAGS"}
l!l&&r!l&&!r
1711
MC/DC100%2/2
$idx < 0 or not ref $self->{"_FFLAGS"}
$idx < 0 not ref $self->{"_FFLAGS"}
Truth table100%3/3
A or not(B)
A= $idx < 0B= not ref $self->{"_FFLAGS"}
ABresult
1X1
011
000
979 11 ▶ $idx >= @{$self->{_FFLAGS}} and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$idx >= @{$self->{"_FFLAGS"};} and return 1 1 10 11
980 10 ▶ $self->{_FFLAGS}[$idx] & CSV_FLAGS_IS_MISSING() ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_MISSING() ? : 4 6 10
981 }
982  
983 ################################################################################
984 # combine
985 ################################################################################
986 39 *combine = \&_combine;
987 1399 ▶sub _combine {
Subroutine _combine: called CC=2 SCAR=6.9
988 1399 my $self = shift;
989 1399 my $str = "";
990 1399 $self->{_FIELDS} = \@_;
991 1399 ▶ $self->{_STATUS} = (@_ > 0) && $self->__combine(\$str, \@_, 0);
Condition100%3/3
@_ > 0 && $self->__combine(\$str, \@_, 0)
!ll&&!rl&&r
111397
MC/DC100%2/2
@_ > 0 && $self->__combine(\$str, \@_, 0)
@_ > 0 $self->__combine(\$str, \@_, 0)
Truth table100%3/3
A && B
A= @_ > 0B= $self->__combine(\$str, \@_, 0)
ABresult
0X0
100
111
992 1395 $self->{_STRING} = \$str;
993 1395 $self->{_STATUS};
994 }
995  
996 ################################################################################
997 # parse
998 ################################################################################
999 39 *parse = \&_parse;
1000 1962 ▶sub _parse {
Subroutine _parse: called CC=4 SCAR=13.9
1001 1962 my ($self, $str) = @_;
1002  
1003 1962 ▶ ref $str and croak($self->SetDiag(1500));
Branch: 1 branch
BranchTrueFalseTotal
ref $str and croak($self->SetDiag(1500)) 4 1958 1962
1004  
1005 1958 my $fields = [];
1006 1958 my $fflags = [];
1007 1958 $self->{_STRING} = \$str;
1008 1958 ▶ if (defined $str && $self->__parse($fields, $fflags, $str, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and $self->__parse($fields, $fflags, $str, 0)) { } 1744 211 1955
Condition100%3/3
defined $str and $self->__parse($fields, $fflags, $str, 0)
!ll&&!rl&&r
62051747
MC/DC100%2/2
defined $str and $self->__parse($fields, $fflags, $str, 0)
defined $str $self->__parse($fields, $fflags, $str, 0)
Truth table100%3/3
A and B
A= defined $strB= $self->__parse($fields, $fflags, $str, 0)
ABresult
0X0
100
111
1009 1744 $self->{_FIELDS} = $fields;
1010 1744 $self->{_FFLAGS} = $fflags;
1011 1744 $self->{_STATUS} = 1;
1012 }
1013 else {
1014 211 $self->{_FIELDS} = undef;
1015 211 $self->{_FFLAGS} = undef;
1016 211 $self->{_STATUS} = 0;
1017 }
1018 1955 $self->{_STATUS};
1019 }
1020  
1021 1028 ▶sub column_names {
Subroutine column_names: called CC=12 SCAR=24.8
Pod documented
1022 1028 my ($self, @keys) = @_;
1023  
1024 @keys or
1025 1028 ▶ return defined $self->{_COLUMN_NAMES} ? @{$self->{_COLUMN_NAMES}} : ();
Branch: 2 branches
BranchTrueFalseTotal
@keys or return defined $self->{"_COLUMN_NAMES"} ? @{$self->{"_COLUMN_NAMES"};} : () 691 337 1028
defined $self->{'_COLUMN_NAMES'} ? : 294 43 337
1026 @keys == 1 && !defined $keys[0] and
1027 691 ▶ return $self->{_COLUMN_NAMES} = undef;
Branch: 1 branch
BranchTrueFalseTotal
@keys == 1 and not defined $keys[0] and return $self->{"_COLUMN_NAMES"} = undef 138 553 691
Condition100%3/3
@keys == 1 and not defined $keys[0]
!ll&&!rl&&r
316237138
MC/DC100%2/2
@keys == 1 and not defined $keys[0]
@keys == 1 not defined $keys[0]
Truth table100%3/3
A and not(B)
A= @keys == 1B= not defined $keys[0]
ABresult
0X0
100
111
1028  
1029 553 ▶ if (@keys == 1 && ref $keys[0] eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (@keys == 1 and ref $keys[0] eq 'ARRAY') { } 228 325 553
elsif (join '', map({defined $_ ? ref $_ : '';} @keys)) { } 5 320 325
Condition100%3/3
@keys == 1 and ref $keys[0] eq "ARRAY"
!ll&&!rl&&r
3169228
MC/DC100%2/2
@keys == 1 and ref $keys[0] eq "ARRAY"
@keys == 1 ref $keys[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @keys == 1B= ref $keys[0] eq "ARRAY"
ABresult
0X0
100
111
1030 228 @keys = @{$keys[0]};
1031 }
1032 715 ▶ elsif (join "", map { defined $_ ? ref $_ : "" } @keys) {
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 714 1 715
1033 5 croak($self->SetDiag(3001));
1034 }
1035  
1036 548 ▶ $self->{_BOUND_COLUMNS} && @keys != @{$self->{_BOUND_COLUMNS}} and
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_BOUND_COLUMNS"} and @keys != @{$self->{"_BOUND_COLUMNS"};} and croak($self->SetDiag(3003)) 1 547 548
Condition100%3/3
$self->{"_BOUND_COLUMNS"} and @keys != @{$self->{"_BOUND_COLUMNS"};}
!ll&&!rl&&r
54611
MC/DC100%2/2
$self->{"_BOUND_COLUMNS"} and @keys != @{$self->{"_BOUND_COLUMNS"};}
$self->{"_BOUND_COLUMNS"} @keys != @{$self->{"_BOUND_COLUMNS"};}
Truth table100%3/3
A and B
A= $self->{"_BOUND_COLUMNS"}B= @keys != @{$self->{"_BOUND_COLUMNS"};}
ABresult
0X0
100
111
1037 croak($self->SetDiag(3003));
1038  
1039 547 ▶ $self->{_COLUMN_NAMES} = [map { defined $_ ? $_ : "\cAUNDEF\cA" } @keys];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1280 1 1281
1040 547 @{$self->{_COLUMN_NAMES}};
1041 }
1042  
1043 334 ▶sub header {
Subroutine header: called CC=63 SCAR=41.5
Pod documented
1044 334 my ($self, $fh, @args) = @_;
1045  
1046 334 ▶ $fh or croak($self->SetDiag(1014));
Branch: 1 branch
BranchTrueFalseTotal
$fh or croak($self->SetDiag(1014)) 333 1 334
1047  
1048 333 my (@seps, %args);
1049 333 for (@args) {
1050 226 ▶ if (ref $_ eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "ARRAY") 18 208 226
1051 18 push @seps, @{$_};
1052 18 next;
1053 }
1054 208 ▶ if (ref $_ eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "HASH") 207 1 208
1055 207 %args = %{$_};
1056 207 next;
1057 }
1058 1 croak('usage: $csv->header ($fh, [ seps ], { options })');
1059 }
1060  
1061 defined $args{munge} && !defined $args{munge_column_names} and
1062 332 ▶ $args{munge_column_names} = $args{munge}; # munge as alias
Branch: 1 branch
BranchTrueFalseTotal
defined $args{"munge"} and not defined $args{"munge_column_names"} and $args{"munge_column_names"} = $args{"munge"} 1 331 332
Condition66%2/3
defined $args{"munge"} and not defined $args{"munge_column_names"}
!ll&&!rl&&r
33101
MC/DC50%1/2
defined $args{"munge"} and not defined $args{"munge_column_names"}
defined $args{"munge"} not defined $args{"munge_column_names"}
Truth table66%2/3
A and not(B)
A= defined $args{"munge"}B= not defined $args{"munge_column_names"}
ABresult
0X0
100
111
1063 332 ▶ defined $args{detect_bom} or $args{detect_bom} = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{"detect_bom"} or $args{"detect_bom"} = 1 163 169 332
1064 332 ▶ defined $args{set_column_names} or $args{set_column_names} = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{"set_column_names"} or $args{"set_column_names"} = 1 8 324 332
1065 332 ▶ defined $args{munge_column_names} or $args{munge_column_names} = "lc";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{"munge_column_names"} or $args{"munge_column_names"} = "lc" 21 311 332
1066  
1067 # Reset any previous leftovers
1068 332 $self->{_RECNO} = 0;
1069 332 $self->{_AHEAD} = undef;
1070 332 ▶ $self->{_COLUMN_NAMES} = undef if $args{set_column_names};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"set_column_names"} 324 8 332
1071 332 ▶ $self->{_BOUND_COLUMNS} = undef if $args{set_column_names};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"set_column_names"} 324 8 332
1072 332 $self->_cache_set($_cache_id{'_has_ahead'}, 0);
1073  
1074 332 ▶ if (defined $args{sep_set}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"sep_set"}) 27 305 332
1075 27 ▶ ref $args{sep_set} eq "ARRAY" or
Branch: 1 branch
BranchTrueFalseTotal
ref $args{"sep_set"} eq "ARRAY" or croak($self->_SetDiagInfo(1500, "sep_set should be an array ref")) 22 5 27
1076 croak($self->_SetDiagInfo(1500, "sep_set should be an array ref"));
1077 22 @seps = @{$args{sep_set}};
1078 }
1079  
1080 327 ▶ $^O eq "MSWin32" and binmode $fh;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq "MSWin32" and binmode $fh 0 327 327
1081 327 my $hdr = <$fh>;
1082 # check if $hdr can be empty here, I don't think so
1083 327 ▶ defined $hdr && $hdr ne "" or croak($self->SetDiag(1010));
Branch: 1 branch
BranchTrueFalseTotal
defined $hdr and $hdr ne "" or croak($self->SetDiag(1010)) 325 2 327
Condition66%2/3
defined $hdr and $hdr ne ""
!ll&&!rl&&r
20325
MC/DC50%1/2
defined $hdr and $hdr ne ""
defined $hdr $hdr ne ""
Truth table66%2/3
A and B
A= defined $hdrB= $hdr ne ""
ABresult
0X0
100
111
1084  
1085 325 my %sep;
1086 325 ▶ @seps or @seps = (",", ";");
Branch: 1 branch
BranchTrueFalseTotal
@seps or @seps = (",", ";") 40 285 325
1087 325 foreach my $sep (@seps) {
1088 734 ▶ index($hdr, $sep) >= 0 and $sep{$sep}++;
Branch: 1 branch
BranchTrueFalseTotal
index($hdr, $sep) != -1 and ++$sep{$sep} 322 412 734
1089 }
1090  
1091 325 ▶ keys %sep >= 2 and croak($self->SetDiag(1011));
Branch: 1 branch
BranchTrueFalseTotal
keys %sep >= 2 and croak($self->SetDiag(1011)) 4 321 325
1092  
1093 321 $self->sep(keys %sep);
1094 321 my $enc = "";
1095 321 ▶ if ($args{detect_bom}) { # UTF-7 is not supported
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"detect_bom"}) 320 1 321
1096 320 ▶ if ($hdr =~ s/^\x00\x00\xfe\xff//) { $enc = "utf-32be" }
Branch: 11 branches
BranchTrueFalseTotal
if ($hdr =~ s/^\x00\x00\xfe\xff//) { } 24 296 320
elsif ($hdr =~ s/^\xff\xfe\x00\x00//) { } 24 272 296
elsif ($hdr =~ s/^\xfe\xff//) { } 25 247 272
elsif ($hdr =~ s/^\xff\xfe//) { } 24 223 247
elsif ($hdr =~ s/^\xef\xbb\xbf//) { } 48 175 223
elsif ($hdr =~ s/^\xf7\x64\x4c//) { } 1 174 175
elsif ($hdr =~ s/^\xdd\x73\x66\x73//) { } 1 173 174
elsif ($hdr =~ s/^\x0e\xfe\xff//) { } 1 172 173
elsif ($hdr =~ s/^\xfb\xee\x28//) { } 1 171 172
elsif ($hdr =~ s/^\x84\x31\x95\x33//) { } 1 170 171
elsif ($hdr =~ s/^\x{feff}//) { } 36 134 170
1097 24 elsif ($hdr =~ s/^\xff\xfe\x00\x00//) { $enc = "utf-32le" }
1098 25 elsif ($hdr =~ s/^\xfe\xff//) { $enc = "utf-16be" }
1099 24 elsif ($hdr =~ s/^\xff\xfe//) { $enc = "utf-16le" }
1100 48 elsif ($hdr =~ s/^\xef\xbb\xbf//) { $enc = "utf-8" }
1101 1 elsif ($hdr =~ s/^\xf7\x64\x4c//) { $enc = "utf-1" }
1102 1 elsif ($hdr =~ s/^\xdd\x73\x66\x73//) { $enc = "utf-ebcdic" }
1103 1 elsif ($hdr =~ s/^\x0e\xfe\xff//) { $enc = "scsu" }
1104 1 elsif ($hdr =~ s/^\xfb\xee\x28//) { $enc = "bocu-1" }
1105 1 elsif ($hdr =~ s/^\x84\x31\x95\x33//) { $enc = "gb-18030" }
1106 36 elsif ($hdr =~ s/^\x{feff}//) { $enc = "" }
1107  
1108 320 ▶ $self->{ENCODING} = $enc ? uc $enc : undef;
Branch: 1 branch
BranchTrueFalseTotal
$enc ? : 150 170 320
1109  
1110 320 ▶ $hdr eq "" and croak($self->SetDiag(1010));
Branch: 1 branch
BranchTrueFalseTotal
$hdr eq "" and croak($self->SetDiag(1010)) 6 314 320
1111  
1112 314 ▶ if ($enc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) 144 170 314
1113 144 ▶ $ebcdic && $enc eq "utf-ebcdic" and $enc = "";
Branch: 1 branch
BranchTrueFalseTotal
$ebcdic and $enc eq "utf-ebcdic" and $enc = "" 0 144 144
Condition33%1/3
$ebcdic and $enc eq "utf-ebcdic"
!ll&&!rl&&r
14400
MC/DC0%0/2
$ebcdic and $enc eq "utf-ebcdic"
$ebcdic $enc eq "utf-ebcdic"
Truth table33%1/3
A and B
A= $ebcdicB= $enc eq "utf-ebcdic"
ABresult
0X0
100
111
1114 144 ▶ if ($enc =~ m/([13]).le$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc =~ /([13]).le$/) 48 96 144
1115 48 my $l = 0 + $1;
1116 48 my $x;
1117 48 $hdr .= "\0" x $l;
1118 48 read $fh, $x, $l;
1119 }
1120 144 ▶ if ($enc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) 144 0 144
1121 144 ▶ if ($enc ne "utf-8") {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc ne "utf-8") 96 48 144
1122 96 require Encode;
1123 96 $hdr = Encode::decode($enc, $hdr);
1124 }
1125 144 binmode $fh, ":encoding($enc)";
1126 }
1127 }
1128 }
1129  
1130 315 my ($ahead, $eol);
1131 315 ▶ if ($hdr and $hdr =~ s/\Asep=(\S)([\r\n]+)//i) { # Also look in xs:Parse
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr and $hdr =~ s/\Asep=(\S)([\r\n]+)//i) 1 314 315
Condition66%2/3
$hdr and $hdr =~ s/\Asep=(\S)([\r\n]+)//i
!ll&&!rl&&r
03141
MC/DC50%1/2
$hdr and $hdr =~ s/\Asep=(\S)([\r\n]+)//i
$hdr $hdr =~ s/\Asep=(\S)([\r\n]+)//i
Truth table66%2/3
A and B
A= $hdrB= $hdr =~ s/\Asep=(\S)([\r\n]+)//i
ABresult
0X0
100
111
1132 1 $self->sep($1);
1133 1 ▶ length $hdr or $hdr = <$fh>;
Branch: 1 branch
BranchTrueFalseTotal
length $hdr or $hdr = readline $fh 0 1 1
1134 }
1135  
1136 315 ▶ if ($hdr =~ s/^([^\r\n]+)([\r\n]+)([^\r\n].+)\z/$1/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr =~ s/^([^\r\n]+)([\r\n]+)([^\r\n].+)\z/$1/s) 142 173 315
1137 142 $eol = $2;
1138 142 $ahead = $3;
1139 }
1140  
1141 315 my $hr = \$hdr; # Will cause croak on perl-5.6.x
1142 315 ▶ open my $h, "<", $hr or croak($self->SetDiag(1010));
Branch: 1 branch
BranchTrueFalseTotal
open my $h, "<", $hr or croak($self->SetDiag(1010)) 315 0 315
1143  
1144 315 ▶ my $row = $self->getline($h) or croak();
Branch: 1 branch
BranchTrueFalseTotal
my $row = $self->getline($h) or croak() 313 2 315
1145 313 close $h;
1146  
1147 313 ▶ if ($args{'munge_column_names'} eq "lc") {
Branch: 3 branches
BranchTrueFalseTotal
if ($args{'munge_column_names'} eq 'lc') { } 294 19 313
elsif ($args{'munge_column_names'} eq 'uc') { } 7 12 19
elsif ($args{'munge_column_names'} eq 'db') { } 3 9 12
1148 294 $_ = lc for @{$row};
1149 }
1150 elsif ($args{'munge_column_names'} eq "uc") {
1151 7 $_ = uc for @{$row};
1152 }
1153 elsif ($args{'munge_column_names'} eq "db") {
1154 3 for (@{$row}) {
1155 7 s/\W+/_/g;
1156 7 s/^_+//;
1157 7 $_ = lc;
1158 }
1159 }
1160  
1161 313 ▶ if ($ahead) { # Must be after getline, which creates the cache
Branch: 1 branch
BranchTrueFalseTotal
if ($ahead) 142 171 313
1162 142 $self->_cache_set($_cache_id{_has_ahead}, 1);
1163 142 $self->{_AHEAD} = $ahead;
1164 142 ▶ $eol =~ m/^\r([^\n]|\z)/ and $self->eol($eol);
Branch: 1 branch
BranchTrueFalseTotal
$eol =~ /^\r([^\n]|\z)/ and $self->eol($eol) 72 70 142
1165 }
1166  
1167 313 my @hdr = @{$row};
1168 ref $args{munge_column_names} eq "CODE" and
1169 313 ▶ @hdr = map { $args{munge_column_names}->($_) } @hdr;
Branch: 1 branch
BranchTrueFalseTotal
ref $args{"munge_column_names"} eq "CODE" and @hdr = map({$args{"munge_column_names"}->($_);} @hdr) 2 311 313
1170 ref $args{munge_column_names} eq "HASH" and
1171 313 ▶ @hdr = map { $args{munge_column_names}->{$_} || $_ } @hdr;
Branch: 1 branch
BranchTrueFalseTotal
ref $args{"munge_column_names"} eq "HASH" and @hdr = map({$args{"munge_column_names"}{$_} or $_;} @hdr) 1 312 313
Condition66%2/3
$args{'munge_column_names'}{$_} || $_
l!l&&r!l&&!r
120
MC/DC0%0/2
$args{'munge_column_names'}{$_} || $_
$args{'munge_column_names'}{$_} $_
Truth table66%2/3
A || B
A= $args{'munge_column_names'}{$_}B= $_
ABresult
1X1
011
000
1172 313 my %hdr; $hdr{$_}++ for @hdr;
1173 313 ▶ exists $hdr{''} and croak($self->SetDiag(1012));
Branch: 1 branch
BranchTrueFalseTotal
exists $hdr{""} and croak($self->SetDiag(1012)) 2 311 313
1174 311 ▶ unless (keys %hdr == @hdr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %hdr == @hdr) 1 310 311
1175 croak($self->_SetDiagInfo(1013, join ", " =>
1176 1 map { "$_ ($hdr{$_})" } grep { $hdr{$_} > 1 } keys %hdr));
1177 }
1178 310 ▶ $args{set_column_names} and $self->column_names(@hdr);
Branch: 1 branch
BranchTrueFalseTotal
$args{"set_column_names"} and $self->column_names(@hdr) 302 8 310
1179 310 ▶ wantarray ? @hdr : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 195 115 310
1180 }
1181  
1182 36 ▶sub bind_columns {
Subroutine bind_columns: called CC=9 SCAR=22.0
Pod documented
1183 36 my ($self, @refs) = @_;
1184  
1185 @refs or
1186 36 ▶ return defined $self->{_BOUND_COLUMNS} ? @{$self->{_BOUND_COLUMNS}} : undef;
Branch: 2 branches
BranchTrueFalseTotal
@refs or return defined $self->{"_BOUND_COLUMNS"} ? @{$self->{"_BOUND_COLUMNS"};} : undef 32 4 36
defined $self->{'_BOUND_COLUMNS'} ? : 2 2 4
1187 32 ▶ if (@refs == 1 && !defined $refs[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@refs == 1 and not defined $refs[0]) 5 27 32
Condition100%3/3
@refs == 1 and not defined $refs[0]
!ll&&!rl&&r
2075
MC/DC100%2/2
@refs == 1 and not defined $refs[0]
@refs == 1 not defined $refs[0]
Truth table100%3/3
A and not(B)
A= @refs == 1B= not defined $refs[0]
ABresult
0X0
100
111
1188 5 $self->{_COLUMN_NAMES} = undef;
1189 5 return $self->{_BOUND_COLUMNS} = undef;
1190 }
1191  
1192 27 ▶ $self->{_COLUMN_NAMES} && @refs != @{$self->{_COLUMN_NAMES}} and
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_COLUMN_NAMES"} and @refs != @{$self->{"_COLUMN_NAMES"};} and croak($self->SetDiag(3003)) 1 26 27
Condition100%3/3
$self->{"_COLUMN_NAMES"} and @refs != @{$self->{"_COLUMN_NAMES"};}
!ll&&!rl&&r
2421
MC/DC100%2/2
$self->{"_COLUMN_NAMES"} and @refs != @{$self->{"_COLUMN_NAMES"};}
$self->{"_COLUMN_NAMES"} @refs != @{$self->{"_COLUMN_NAMES"};}
Truth table100%3/3
A and B
A= $self->{"_COLUMN_NAMES"}B= @refs != @{$self->{"_COLUMN_NAMES"};}
ABresult
0X0
100
111
1193 croak($self->SetDiag(3003));
1194 26 ▶ join "", map { ref $_ eq "SCALAR" ? "" : "*" } @refs and
Branch: 2 branches
BranchTrueFalseTotal
join "", map({ref $_ eq "SCALAR" ? "" : "*";} @refs) and croak($self->SetDiag(3004)) 2 24 26
ref $_ eq 'SCALAR' ? : 74627 5 74632
1195 croak($self->SetDiag(3004));
1196  
1197 24 $self->_set_attr_N("_is_bound", scalar @refs);
1198 24 $self->{_BOUND_COLUMNS} = [@refs];
1199 24 @refs;
1200 }
1201  
1202 132 ▶sub getline_hr {
Subroutine getline_hr: called CC=10 SCAR=23.2
Pod documented
1203 132 my ($self, @args, %hr) = @_;
1204 132 ▶ $self->{_COLUMN_NAMES} or croak($self->SetDiag(3002));
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_COLUMN_NAMES"} or croak($self->SetDiag(3002)) 131 1 132
1205 131 ▶ my $fr = $self->getline(@args) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fr = $self->getline(@args) or return 128 3 131
1206 128 ▶ if (ref $self->{_FFLAGS}) { # missing
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"_FFLAGS"}) 5 123 128
1207 $self->{_FFLAGS}[$_] = CSV_FLAGS_IS_MISSING()
1208 5 ▶ for (@{$fr} ? $#{$fr} + 1 : 0) .. $#{$self->{_COLUMN_NAMES}};
Branch: 1 branch
BranchTrueFalseTotal
@{$fr;} ? : 5 0 5
1209 5 ▶ @{$fr} == 1 && (!defined $fr->[0] || $fr->[0] eq "") and
Condition50%3/6
not defined $fr->[0] or $fr->[0] eq ""
l!l&&r!l&&!r
021
$self->{"_FFLAGS"}[0] ||= CSV_FLAGS_IS_MISSING()
l!l&&r!l&&!r
020
MC/DC50%1/2
not defined $fr->[0] or $fr->[0] eq ""
not defined $fr->[0] $fr->[0] eq ""
MC/DC0%0/2
$self->{"_FFLAGS"}[0] ||= CSV_FLAGS_IS_MISSING()
$self->{"_FFLAGS"}[0] CSV_FLAGS_IS_MISSING()
Truth table66%2/3
not(A) or B
A= not defined $fr->[0]B= $fr->[0] eq ""
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $self->{"_FFLAGS"}[0]B= CSV_FLAGS_IS_MISSING()
ABresult
1X1
011
000
1210 5 ▶ $self->{_FFLAGS}[0] ||= CSV_FLAGS_IS_MISSING();
Branch: 1 branch
BranchTrueFalseTotal
@{$fr;} == 1 and !defined($fr->[0]) || $fr->[0] eq "" and $self->{"_FFLAGS"}[0] ||= CSV_FLAGS_IS_MISSING() 2 3 5
Condition100%3/3
@{$fr;} == 1 and !defined($fr->[0]) || $fr->[0] eq ""
!ll&&!rl&&r
212
MC/DC0%0/2
@{$fr;} == 1 and !defined($fr->[0]) || $fr->[0] eq ""
@{$fr;} == 1 !defined($fr->[0]) || $fr->[0] eq ""
Truth table66%2/3
A and B
A= @{$fr;} == 1B= !defined($fr->[0]) || $fr->[0] eq ""
ABresult
0X0
100
111
1211 }
1212 128 @hr{@{$self->{_COLUMN_NAMES}}} = @{$fr};
1213 128 \%hr;
1214 }
1215  
1216 251 ▶sub getline_hr_all {
Subroutine getline_hr_all: called CC=2 SCAR=6.9
Pod documented
1217 251 my ($self, @args) = @_;
1218  
1219 251 ▶ $self->{_COLUMN_NAMES} or croak($self->SetDiag(3002));
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_COLUMN_NAMES"} or croak($self->SetDiag(3002)) 249 2 251
1220  
1221 249 my @cn = @{$self->{_COLUMN_NAMES}};
1222  
1223 249 [map { my %h; @h{@cn} = @{$_}; \%h } @{$self->getline_all(@args)}];
1224 }
1225  
1226 34 ▶sub say {
Subroutine say: called CC=6 SCAR=18.1
Pod documented
1227 34 my ($self, $io, @f) = @_;
1228 34 my $eol = $self->eol();
1229 # say ($fh, undef) does not propage actual undef to print ()
1230 34 ▶ my $state = $self->print($io, @f == 1 && !defined $f[0] ? undef : @f);
Branch: 1 branch
BranchTrueFalseTotal
@f == 1 && !defined($f[0]) ? : 1 33 34
Condition66%2/3
@f == 1 and not defined $f[0]
!ll&&!rl&&r
0331
MC/DC50%1/2
@f == 1 and not defined $f[0]
@f == 1 not defined $f[0]
Truth table66%2/3
A and not(B)
A= @f == 1B= not defined $f[0]
ABresult
0X0
100
111
1231 34 ▶ unless (length $eol) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $eol) 32 2 34
1232 32 ▶ $eol = $self->eol_type() || $\ || $/;
Condition66%4/6
$self->eol_type || $\ || $/
l!l&&r!l&&!r
21110
$self->eol_type or $\
l!l&&r!l&&!r
21011
MC/DC0%0/3
$self->eol_type || $\ || $/
$self->eol_type $\ $/
Truth table50%2/4
A or B || C
A= $self->eol_typeB= $\C= $/
ABCresult
1XX1
01X1
0011
0000
1233 32 print $io $eol;
1234 }
1235 34 return $state;
1236 }
1237  
1238 3 ▶sub print_hr {
Subroutine print_hr: called CC=3 SCAR=11.0
Pod documented
1239 3 my ($self, $io, $hr) = @_;
1240 3 ▶ $self->{_COLUMN_NAMES} or croak($self->SetDiag(3009));
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_COLUMN_NAMES"} or croak($self->SetDiag(3009)) 2 1 3
1241 2 ▶ ref $hr eq "HASH" or croak($self->SetDiag(3010));
Branch: 1 branch
BranchTrueFalseTotal
ref $hr eq "HASH" or croak($self->SetDiag(3010)) 1 1 2
1242 1 $self->print($io, [map { $hr->{$_} } $self->column_names()]);
1243 }
1244  
1245 58 ▶sub fragment {
Subroutine fragment: called CC=53 SCAR=39.7
Pod documented
1246 58 my ($self, $io, $spec) = @_;
1247  
1248 58 my $qd = qr{\s* [0-9]+ \s* }x; # digit
1249 58 my $qs = qr{\s* (?: [0-9]+ | \* ) \s*}x; # digit or star
1250 58 my $qr = qr{$qd (?: - $qs )?}x; # range
1251 58 my $qc = qr{$qr (?: ; $qr )*}x; # list
1252 58 ▶ defined $spec && $spec =~ m{^ \s*
Branch: 1 branch
BranchTrueFalseTotal
defined $spec and $spec =~ /^ \s* \x23 ? \s* # optional leading # ( row | col | cell ) \s* = ( $qc # for row and col | $qd , $qd (?: - $qs , $qs)? # for cell (ranges) (?: ; $qd , $qd (?: - $qs , $qs)? )* # and cell (range) lists ) \s* $/xi or croak($self->SetDiag(2013)) 38 20 58
Condition100%3/3
defined $spec and $spec =~ /^ \s* \x23 ? \s* # optional leading # ( row | col | cell ) \s* = ( $qc # for row and col | $qd , $qd (?: - $qs , $qs)? # for cell (ranges) (?: ; $qd , $qd (?: - $qs , $qs)? )* # and cell (range) lists ) \s* $/xi
!ll&&!rl&&r
11938
MC/DC100%2/2
defined $spec and $spec =~ /^ \s* \x23 ? \s* # optional leading # ( row | col | cell ) \s* = ( $qc # for row and col | $qd , $qd (?: - $qs , $qs)? # for cell (ranges) (?: ; $qd , $qd (?: - $qs , $qs)? )* # and cell (range) lists ) \s* $/xi
defined $spec $spec =~ /^ \s* \x23 ? \s* # optional leading # ( row | col | cell ) \s* = ( $qc # for row and col | $qd , $qd (?: - $qs , $qs)? # for cell (ranges) (?: ; $qd , $qd (?: - $qs , $qs)? )* # and cell (range) lists ) \s* $/xi
Truth table100%3/3
A and B
A= defined $specB= $spec =~ /^ \s* \x23 ? \s* # optional leading # ( row | col | cell ) \s* = ( $qc # for row and col | $qd , $qd (?: - $qs , $qs)? # for cell (ranges) (?: ; $qd , $qd (?: - $qs , $qs)? )* # and cell (range) lists ) \s* $/xi
ABresult
0X0
100
111
1253 \x23 ? \s* # optional leading #
1254 ( row | col | cell ) \s* =
1255 ( $qc # for row and col
1256 | $qd , $qd (?: - $qs , $qs)? # for cell (ranges)
1257 (?: ; $qd , $qd (?: - $qs , $qs)? )* # and cell (range) lists
1258 ) \s* $}xi or croak($self->SetDiag(2013));
1259 38 my ($type, $range) = (lc $1, $2);
1260  
1261 38 my @h = $self->column_names();
1262  
1263 38 my @c;
1264 38 ▶ if ($type eq "cell") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "cell") 21 17 38
1265 21 my @spec;
1266 my $min_row;
1267 21 my $max_row = 0;
1268 21 for (split m/\s*;\s*/ => $range) {
1269 37 ▶ my ($tlr, $tlc, $brr, $brc) = (m{
Branch: 1 branch
BranchTrueFalseTotal
() = / ^ \s* ([0-9]+ ) \s* , \s* ([0-9]+ ) \s* (?: - \s* ([0-9]+ | \*) \s* , \s* ([0-9]+ | \*) \s* )? $/x or croak($self->SetDiag(2013)) 36 1 37
1270 ^ \s* ([0-9]+ ) \s* , \s* ([0-9]+ ) \s*
1271 (?: - \s* ([0-9]+ | \*) \s* , \s* ([0-9]+ | \*) \s* )?
1272 $}x) or croak($self->SetDiag(2013));
1273 36 ▶ defined $brr or ($brr, $brc) = ($tlr, $tlc);
Branch: 1 branch
BranchTrueFalseTotal
defined $brr or () = 17 19 36
1274 36 ▶ $tlr == 0 || $tlc == 0 ||
Branch: 1 branch
BranchTrueFalseTotal
$tlr == 0 || $tlc == 0 || $brr ne "*" && ($brr == 0 || $brr < $tlr) || $brc ne "*" && ($brc == 0 || $brc < $tlc) and croak($self->SetDiag(2013)) 8 28 36
Condition90%19/21
$tlr == 0 or $tlc == 0 or $brr ne "*" and $brr == 0 || $brr < $tlr or $brc ne "*" and $brc == 0 || $brc < $tlc
l!l&&r!l&&!r
6228
$tlr == 0 or $tlc == 0 or $brr ne "*" and $brr == 0 || $brr < $tlr
l!l&&r!l&&!r
4230
$tlr == 0 or $tlc == 0
l!l&&r!l&&!r
2232
$brr ne "*" and $brr == 0 || $brr < $tlr
!ll&&!rl&&r
3272
$brr == 0 or $brr < $tlr
l!l&&r!l&&!r
0227
$brc ne "*" and $brc == 0 || $brc < $tlc
!ll&&!rl&&r
2262
$brc == 0 or $brc < $tlc
l!l&&r!l&&!r
0226
MC/DC75%6/8
$tlr == 0 or $tlc == 0 or $brr ne "*" and $brr == 0 || $brr < $tlr or $brc ne "*" and $brc == 0 || $brc < $tlc
$tlr == 0 $tlc == 0 $brr ne "*" $brr == 0 $brr < $tlr $brc ne "*" $brc == 0 $brc < $tlc
Truth table75%9/12
A or B or C and D or E or F and G or H
A= $tlr == 0B= $tlc == 0C= $brr ne "*"D= $brr == 0E= $brr < $tlrF= $brc ne "*"G= $brc == 0H= $brc < $tlc
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
0011XXXX1
00101XXX1
000XX11X1
000XX1011
0010011X1
001001011
000XX0XX0
000XX1000
001000XX0
001001000
1275 ($brr ne "*" && ($brr == 0 || $brr < $tlr)) ||
1276 ($brc ne "*" && ($brc == 0 || $brc < $tlc))
1277 and croak($self->SetDiag(2013));
1278 28 $tlc--;
1279 28 ▶ $brc-- unless $brc eq "*";
Branch: 1 branch
BranchTrueFalseTotal
unless $brc eq "*" 26 2 28
1280 28 ▶ defined $min_row or $min_row = $tlr;
Branch: 1 branch
BranchTrueFalseTotal
defined $min_row or $min_row = $tlr 14 14 28
1281 28 ▶ $tlr < $min_row and $min_row = $tlr;
Branch: 1 branch
BranchTrueFalseTotal
$tlr < $min_row and $min_row = $tlr 1 27 28
1282 28 ▶ $brr eq "*" || $brr > $max_row and
Branch: 1 branch
BranchTrueFalseTotal
$brr eq "*" || $brr > $max_row and $max_row = $brr 19 9 28
Condition100%3/3
$brr eq "*" or $brr > $max_row
l!l&&r!l&&!r
2179
MC/DC100%2/2
$brr eq "*" or $brr > $max_row
$brr eq "*" $brr > $max_row
Truth table100%3/3
A or B
A= $brr eq "*"B= $brr > $max_row
ABresult
1X1
011
000
1283 $max_row = $brr;
1284 28 push @spec, [$tlr, $tlc, $brr, $brc];
1285 }
1286 12 my $r = 0;
1287 12 ▶ while (my $row = $self->getline($io)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $self->getline($io)) 77 2 79
1288 77 ▶ ++$r < $min_row and next;
Branch: 1 branch
BranchTrueFalseTotal
++$r < $min_row and next 44 33 77
1289 33 my %row;
1290 my $lc;
1291 33 foreach my $s (@spec) {
1292 77 my ($tlr, $tlc, $brr, $brc) = @{$s};
1293 77 ▶ $r < $tlr || ($brr ne "*" && $r > $brr) and next;
Branch: 1 branch
BranchTrueFalseTotal
$r < $tlr || $brr ne "*" && $r > $brr and next 32 45 77
Condition100%6/6
$r < $tlr or $brr ne "*" and $r > $brr
l!l&&r!l&&!r
171545
$brr ne "*" and $r > $brr
!ll&&!rl&&r
63915
MC/DC100%3/3
$r < $tlr or $brr ne "*" and $r > $brr
$r < $tlr $brr ne "*" $r > $brr
Truth table100%4/4
A or B and C
A= $r < $tlrB= $brr ne "*"C= $r > $brr
ABCresult
1XX1
0111
00X0
0100
1294 45 ▶ !defined $lc || $tlc < $lc and $lc = $tlc;
Branch: 1 branch
BranchTrueFalseTotal
!defined($lc) || $tlc < $lc and $lc = $tlc 36 9 45
Condition100%3/3
not defined $lc or $tlc < $lc
l!l&&r!l&&!r
3339
MC/DC100%2/2
not defined $lc or $tlc < $lc
not defined $lc $tlc < $lc
Truth table100%3/3
not(A) or B
A= not defined $lcB= $tlc < $lc
ABresult
1X1
011
000
1295 45 ▶ my $rr = $brc eq "*" ? $#{$row} : $brc;
Branch: 1 branch
BranchTrueFalseTotal
$brc eq '*' ? : 5 40 45
1296 45 $row{$_} = $row->[$_] for $tlc .. $rr;
1297 }
1298 33 push @c, [@row{sort { $a <=> $b } keys %row}];
1299 33 ▶ if (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 2 31 33
1300 2 my %h; @h{@h} = @{$c[-1]};
1301 2 $c[-1] = \%h;
1302 }
1303 33 ▶ $max_row ne "*" && $r == $max_row and last;
Branch: 1 branch
BranchTrueFalseTotal
$max_row ne "*" and $r == $max_row and last 10 23 33
Condition100%3/3
$max_row ne "*" and $r == $max_row
!ll&&!rl&&r
61710
MC/DC100%2/2
$max_row ne "*" and $r == $max_row
$max_row ne "*" $r == $max_row
Truth table100%3/3
A and B
A= $max_row ne "*"B= $r == $max_row
ABresult
0X0
100
111
1304 }
1305 12 return \@c;
1306 }
1307  
1308 # row or col
1309 17 my @r;
1310 17 my $eod = 0;
1311 17 for (split m/\s*;\s*/ => $range) {
1312 25 ▶ my ($from, $to) = m/^\s* ([0-9]+) (?: \s* - \s* ([0-9]+ | \* ))? \s* $/x
Branch: 1 branch
BranchTrueFalseTotal
() = /^\s* ([0-9]+) (?: \s* - \s* ([0-9]+ | \* ))? \s* $/x or croak($self->SetDiag(2013)) 25 0 25
1313 or croak($self->SetDiag(2013));
1314 25 ▶ $to ||= $from;
Condition100%3/3
$to ||= $from
l!l&&r!l&&!r
9142
MC/DC100%2/2
$to ||= $from
$to $from
Truth table100%3/3
A ||= B
A= $toB= $from
ABresult
1X1
011
000
1315 25 ▶ $to eq "*" and ($to, $eod) = ($from, 1);
Branch: 1 branch
BranchTrueFalseTotal
$to eq "*" and ($to, $eod) = ($from, 1) 2 23 25
1316 # $to cannot be <= 0 due to regex and ||=
1317 25 ▶ $from <= 0 || $to < $from and croak($self->SetDiag(2013));
Branch: 1 branch
BranchTrueFalseTotal
$from <= 0 || $to < $from and croak($self->SetDiag(2013)) 3 22 25
Condition100%3/3
$from <= 0 or $to < $from
l!l&&r!l&&!r
2122
MC/DC100%2/2
$from <= 0 or $to < $from
$from <= 0 $to < $from
Truth table100%3/3
A or B
A= $from <= 0B= $to < $from
ABresult
1X1
011
000
1318 22 $r[$_] = 1 for $from .. $to;
1319 }
1320  
1321 14 my $r = 0;
1322 14 ▶ $type eq "col" and shift @r;
Branch: 1 branch
BranchTrueFalseTotal
$type eq "col" and shift @r 5 9 14
1323 14 ▶ $_ ||= 0 for @r;
Condition100%2/2
$_ ||= 0
l!l
2827
MC/DC100%1/1
$_ ||= 0
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
1324 14 ▶ while (my $row = $self->getline($io)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $self->getline($io)) 109 14 123
1325 109 $r++;
1326 109 ▶ if ($type eq "row") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "row") 64 45 109
1327 64 ▶ if (($r > $#r && $eod) || $r[$r]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r > $#r and $eod or $r[$r]) 20 44 64
Condition100%6/6
$r > $#r and $eod or $r[$r]
l!l&&r!l&&!r
31744
$r > $#r and $eod
!ll&&!rl&&r
28333
MC/DC100%3/3
$r > $#r and $eod or $r[$r]
$r > $#r $eod $r[$r]
Truth table80%4/5
A and B or C
A= $r > $#rB= $eodC= $r[$r]
ABCresult
11X1
0X11
1011
0X00
1000
1328 20 push @c, $row;
1329 20 ▶ if (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 3 17 20
1330 3 my %h; @h{@h} = @{$c[-1]};
1331 3 $c[-1] = \%h;
1332 }
1333 }
1334 64 next;
1335 }
1336 45 ▶ push @c, [map { ($_ > $#r && $eod) || $r[$_] ? $row->[$_] : () } 0 .. $#{$row}];
Branch: 1 branch
BranchTrueFalseTotal
$_ > $#r && $eod || $r[$_] ? : 126 279 405
Condition100%6/6
$_ > $#r and $eod or $r[$_]
l!l&&r!l&&!r
2799279
$_ > $#r and $eod
!ll&&!rl&&r
16221627
MC/DC100%3/3
$_ > $#r and $eod or $r[$_]
$_ > $#r $eod $r[$_]
Truth table80%4/5
A and B or C
A= $_ > $#rB= $eodC= $r[$_]
ABCresult
11X1
0X11
1011
0X00
1000
1337 45 ▶ if (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 9 36 45
1338 9 my %h; @h{@h} = @{$c[-1]};
1339 9 $c[-1] = \%h;
1340 }
1341 }
1342  
1343 14 return \@c;
1344 }
1345  
1346 39 my $csv_usage = q{usage: my $aoa = csv (in => $file);};
1347  
1348 345 ▶sub _csv_attr {
Subroutine _csv_attr: called CC=89 SCAR=45.7
1349 345 ▶ my %attr = (@_ == 1 && ref $_[0] eq "HASH" ? %{$_[0]} : @_) or croak();
Branch: 2 branches
BranchTrueFalseTotal
my(%attr) = @_ == 1 && ref $_[0] eq "HASH" ? %{$_[0];} : @_ or croak() 345 0 345
@_ == 1 && ref $_[0] eq 'HASH' ? : 4 341 345
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
34104
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
1350  
1351 345 $attr{binary} = 1;
1352 345 $attr{strict_eol} = 1;
1353  
1354 345 ▶ my $enc = delete $attr{enc} || delete $attr{encoding} || "";
Condition100%5/5
delete $attr{'enc'} || delete $attr{'encoding'} || ''
l!l
45300
delete $attr{"enc"} or delete $attr{"encoding"}
l!l&&r!l&&!r
144300
MC/DC100%2/2
delete $attr{'enc'} || delete $attr{'encoding'} || ''
delete $attr{"enc"} delete $attr{"encoding"}
Truth table100%3/3
A or B
A= delete $attr{"enc"}B= delete $attr{"encoding"}
ABresult
1X1
011
000
1355 345 ▶ $enc eq "auto" and ($attr{detect_bom}, $enc) = (1, "");
Branch: 1 branch
BranchTrueFalseTotal
$enc eq "auto" and ($attr{"detect_bom"}, $enc) = (1, "") 42 303 345
1356 345 ▶ my $stack = $enc =~ s/(:\w.*)// ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$enc =~ s/(:\w.*)// ? : 0 345 345
1357 345 ▶ $enc =~ m/^[-\w.]+$/ and $enc = ":encoding($enc)";
Branch: 1 branch
BranchTrueFalseTotal
$enc =~ /^[-\w.]+$/ and $enc = ":encoding($enc)" 3 342 345
1358 345 $enc .= $stack;
1359  
1360 345 my $hdrs = delete $attr{'headers'};
1361 345 my $frag = delete $attr{'fragment'};
1362 345 my $key = delete $attr{'key'};
1363 345 my $val = delete $attr{'value'};
1364 my $kh = delete $attr{'keep_headers'} ||
1365 delete $attr{'keep_column_names'} ||
1366 345 ▶ delete $attr{'kh'};
Condition100%6/6
delete $attr{'keep_headers'} || delete $attr{'keep_column_names'} || delete $attr{'kh'}
l!l&&r!l&&!r
415326
delete $attr{"keep_headers"} or delete $attr{"keep_column_names"}
l!l&&r!l&&!r
22341
MC/DC100%3/3
delete $attr{'keep_headers'} || delete $attr{'keep_column_names'} || delete $attr{'kh'}
delete $attr{"keep_headers"} delete $attr{"keep_column_names"} delete $attr{'kh'}
Truth table100%4/4
A or B || C
A= delete $attr{"keep_headers"}B= delete $attr{"keep_column_names"}C= delete $attr{'kh'}
ABCresult
1XX1
01X1
0011
0000
1367  
1368 my $cbai = delete $attr{'callbacks'}{'after_in'} ||
1369 delete $attr{'after_in'} ||
1370 delete $attr{'callbacks'}{'after_parse'} ||
1371 345 ▶ delete $attr{'after_parse'};
Condition100%9/9
delete $attr{'callbacks'}{'after_in'} || delete $attr{'after_in'} || delete $attr{'callbacks'}{'after_parse'} || delete $attr{'after_parse'}
l!l&&r!l&&!r
112332
delete $attr{"callbacks"}{"after_in"} or delete $attr{"after_in"} or delete $attr{"callbacks"}{"after_parse"}
l!l&&r!l&&!r
92334
delete $attr{"callbacks"}{"after_in"} or delete $attr{"after_in"}
l!l&&r!l&&!r
27336
MC/DC100%4/4
delete $attr{'callbacks'}{'after_in'} || delete $attr{'after_in'} || delete $attr{'callbacks'}{'after_parse'} || delete $attr{'after_parse'}
delete $attr{"callbacks"}{"after_in"} delete $attr{"after_in"} delete $attr{"callbacks"}{"after_parse"} delete $attr{'after_parse'}
Truth table100%5/5
A or B or C || D
A= delete $attr{"callbacks"}{"after_in"}B= delete $attr{"after_in"}C= delete $attr{"callbacks"}{"after_parse"}D= delete $attr{'after_parse'}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1372 my $cbbo = delete $attr{'callbacks'}{'before_out'} ||
1373 345 ▶ delete $attr{'before_out'};
Condition100%3/3
delete $attr{'callbacks'}{'before_out'} || delete $attr{'before_out'}
l!l&&r!l&&!r
22341
MC/DC100%2/2
delete $attr{'callbacks'}{'before_out'} || delete $attr{'before_out'}
delete $attr{'callbacks'}{'before_out'} delete $attr{'before_out'}
Truth table100%3/3
A || B
A= delete $attr{'callbacks'}{'before_out'}B= delete $attr{'before_out'}
ABresult
1X1
011
000
1374 my $cboi = delete $attr{'callbacks'}{'on_in'} ||
1375 345 ▶ delete $attr{'on_in'};
Condition100%3/3
delete $attr{'callbacks'}{'on_in'} || delete $attr{'on_in'}
l!l&&r!l&&!r
412329
MC/DC100%2/2
delete $attr{'callbacks'}{'on_in'} || delete $attr{'on_in'}
delete $attr{'callbacks'}{'on_in'} delete $attr{'on_in'}
Truth table100%3/3
A || B
A= delete $attr{'callbacks'}{'on_in'}B= delete $attr{'on_in'}
ABresult
1X1
011
000
1376 my $cboe = delete $attr{'callbacks'}{'on_error'} ||
1377 345 ▶ delete $attr{'on_error'};
Condition66%2/3
delete $attr{'callbacks'}{'on_error'} || delete $attr{'on_error'}
l!l&&r!l&&!r
01344
MC/DC50%1/2
delete $attr{'callbacks'}{'on_error'} || delete $attr{'on_error'}
delete $attr{'callbacks'}{'on_error'} delete $attr{'on_error'}
Truth table66%2/3
A || B
A= delete $attr{'callbacks'}{'on_error'}B= delete $attr{'on_error'}
ABresult
1X1
011
000
1378  
1379 my $hd_s = delete $attr{'sep_set'} ||
1380 345 ▶ delete $attr{'seps'};
Condition100%3/3
delete $attr{'sep_set'} || delete $attr{'seps'}
l!l&&r!l&&!r
46335
MC/DC100%2/2
delete $attr{'sep_set'} || delete $attr{'seps'}
delete $attr{'sep_set'} delete $attr{'seps'}
Truth table100%3/3
A || B
A= delete $attr{'sep_set'}B= delete $attr{'seps'}
ABresult
1X1
011
000
1381 my $hd_b = delete $attr{'detect_bom'} ||
1382 345 ▶ delete $attr{'bom'};
Condition100%3/3
delete $attr{'detect_bom'} || delete $attr{'bom'}
l!l&&r!l&&!r
42120183
MC/DC100%2/2
delete $attr{'detect_bom'} || delete $attr{'bom'}
delete $attr{'detect_bom'} delete $attr{'bom'}
Truth table100%3/3
A || B
A= delete $attr{'detect_bom'}B= delete $attr{'bom'}
ABresult
1X1
011
000
1383 my $hd_m = delete $attr{'munge'} ||
1384 345 ▶ delete $attr{'munge_column_names'};
Condition100%3/3
delete $attr{'munge'} || delete $attr{'munge_column_names'}
l!l&&r!l&&!r
71337
MC/DC100%2/2
delete $attr{'munge'} || delete $attr{'munge_column_names'}
delete $attr{'munge'} delete $attr{'munge_column_names'}
Truth table100%3/3
A || B
A= delete $attr{'munge'}B= delete $attr{'munge_column_names'}
ABresult
1X1
011
000
1385 345 my $hd_c = delete $attr{'set_column_names'};
1386  
1387 345 my $fh;
1388 345 my $sink = 0;
1389 345 my $cls = 0; # If I open a file, I have to close it
1390 345 ▶ my $in = delete $attr{in} || delete $attr{file} or croak($csv_usage);
Branch: 1 branch
BranchTrueFalseTotal
my $in = delete $attr{"in"} || delete $attr{"file"} or croak($csv_usage) 342 3 345
Condition100%3/3
delete $attr{'in'} || delete $attr{'file'}
l!l&&r!l&&!r
33933
MC/DC100%2/2
delete $attr{'in'} || delete $attr{'file'}
delete $attr{'in'} delete $attr{'file'}
Truth table100%3/3
A || B
A= delete $attr{'in'}B= delete $attr{'file'}
ABresult
1X1
011
000
1391 my $out = exists $attr{out} && !$attr{out} ? \"skip"
1392 342 ▶ : delete $attr{out} || delete $attr{file};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr{'out'} && !$attr{'out'} ? : 1 341 342
Condition100%6/6
exists $attr{"out"} and not $attr{"out"}
!ll&&!rl&&r
305361
delete $attr{"out"} or delete $attr{"file"}
l!l&&r!l&&!r
361304
MC/DC100%2/2
exists $attr{"out"} and not $attr{"out"}
exists $attr{"out"} not $attr{"out"}
MC/DC100%2/2
delete $attr{"out"} or delete $attr{"file"}
delete $attr{"out"} delete $attr{"file"}
Truth table100%3/3
A and not(B)
A= exists $attr{"out"}B= not $attr{"out"}
ABresult
0X0
100
111
Truth table100%3/3
A or B
A= delete $attr{"out"}B= delete $attr{"file"}
ABresult
1X1
011
000
1393  
1394 342 ▶ ref $in eq "CODE" || ref $in eq "ARRAY" and $out ||= \*STDOUT;
Branch: 1 branch
BranchTrueFalseTotal
ref $in eq "CODE" || ref $in eq "ARRAY" and $out ||= \*STDOUT 25 317 342
Condition100%5/5
ref $in eq "CODE" or ref $in eq "ARRAY"
l!l&&r!l&&!r
322317
$out ||= \*STDOUT
l!l
232
MC/DC100%2/2
ref $in eq "CODE" or ref $in eq "ARRAY"
ref $in eq "CODE" ref $in eq "ARRAY"
MC/DC100%1/1
$out ||= \*STDOUT
$out
Truth table100%3/3
A or B
A= ref $in eq "CODE"B= ref $in eq "ARRAY"
ABresult
1X1
011
000
Truth table100%2/2
A
A= $out
Aresult
11
00
1395  
1396 342 my ($fho, $fho_cls);
1397 342 ▶ if ($in && $out and (!ref $in || ref $in eq "GLOB" || ref \$in eq "GLOB")
Branch: 1 branch
BranchTrueFalseTotal
if ($in and $out and !ref($in) || ref $in eq "GLOB" || ref \$in eq "GLOB" and !ref($out) || ref $out eq "GLOB" || ref \$out eq "GLOB") 7 335 342
Condition85%18/21
$in and $out and !ref($in) || ref $in eq "GLOB" || ref \$in eq "GLOB" and !ref($out) || ref $out eq "GLOB" || ref \$out eq "GLOB"
!ll&&!rl&&r
33057
$in and $out and !ref($in) || ref $in eq "GLOB" || ref \$in eq "GLOB"
!ll&&!rl&&r
3022812
$in and $out
!ll&&!rl&&r
030240
not ref $in or ref $in eq "GLOB" or ref \$in eq "GLOB"
l!l&&r!l&&!r
12028
not ref $in or ref $in eq "GLOB"
l!l&&r!l&&!r
10228
not ref $out or ref $out eq "GLOB" or ref \$out eq "GLOB"
l!l&&r!l&&!r
705
not ref $out or ref $out eq "GLOB"
l!l&&r!l&&!r
525
MC/DC62%5/8
$in and $out and !ref($in) || ref $in eq "GLOB" || ref \$in eq "GLOB" and !ref($out) || ref $out eq "GLOB" || ref \$out eq "GLOB"
$in $out not ref $in ref $in eq "GLOB" ref \$in eq "GLOB" not ref $out ref $out eq "GLOB" ref \$out eq "GLOB"
Truth table46%7/15
A and B and not(C) or D or E and not(F) or G or H
A= $inB= $outC= not ref $inD= ref $in eq "GLOB"E= ref \$in eq "GLOB"F= not ref $outG= ref $out eq "GLOB"H= ref \$out eq "GLOB"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
11000XXX0
111XX0000
1101X0000
110010000
111XX1XX1
111XX01X1
111XX0011
1101X1XX1
1101X01X1
1101X0011
110011XX1
1100101X1
110010011
1398 and (!ref $out || ref $out eq "GLOB" || ref \$out eq "GLOB")) {
1399 7 ▶ if (ref $out or "GLOB" eq ref \$out) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $out or 'GLOB' eq ref \$out) { } 2 5 7
Condition66%2/3
ref $out or "GLOB" eq ref \$out
l!l&&r!l&&!r
205
MC/DC50%1/2
ref $out or "GLOB" eq ref \$out
ref $out "GLOB" eq ref \$out
Truth table66%2/3
A or B
A= ref $outB= "GLOB" eq ref \$out
ABresult
1X1
011
000
1400 2 $fho = $out;
1401 }
1402 else {
1403 5 ▶ open $fho, ">", $out or croak "$out: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $fho, ">", $out or croak("${out}: $!\n") 5 0 5
1404 5 ▶ if (my $e = $attr{'encoding'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $attr{"encoding"}) 0 5 5
1405 0 binmode $fho, ":encoding($e)";
1406 0 ▶ $hd_b and print $fho "\x{feff}";
Branch: 1 branch
BranchTrueFalseTotal
$hd_b and print $fho "\x{feff}" 0 0 0
1407 }
1408 5 $fho_cls = 1;
1409 }
1410 7 ▶ if ($cboi && !$cbai) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cboi and not $cbai) 1 6 7
Condition66%2/3
$cboi and not $cbai
!ll&&!rl&&r
601
MC/DC50%1/2
$cboi and not $cbai
$cboi not $cbai
Truth table66%2/3
A and not(B)
A= $cboiB= not $cbai
ABresult
0X0
100
111
1411 1 $cbai = $cboi;
1412 1 $cboi = undef;
1413 }
1414 7 ▶ if ($cbai) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cbai) { } 2 5 7
1415 2 my $cb = $cbai;
1416 2 ▶ $cbai = sub { $cb->(@_); $_[0]->say($fho, $_[1]); 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
1417 }
1418 else {
1419 5 ▶ $cbai = sub { $_[0]->say($fho, $_[1]); 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
1420 }
1421  
1422 # Put all callbacks back in place for streaming behavior
1423 7 $attr{'callbacks'}{'after_parse'} = $cbai; $cbai = undef;
1424 7 $attr{'callbacks'}{'before_out'} = $cbbo; $cbbo = undef;
1425 7 $attr{'callbacks'}{'on_in'} = $cboi; $cboi = undef;
1426 7 $attr{'callbacks'}{'on_error'} = $cboe; $cboe = undef;
1427 7 $out = undef;
1428 7 $sink = 1;
1429 }
1430  
1431 342 ▶ if ($out) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out) 33 309 342
1432 33 ▶ if (ref $out and ("ARRAY" eq ref $out or "HASH" eq ref $out)) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $out and 'ARRAY' eq ref $out || 'HASH' eq ref $out) { } 5 28 33
elsif (ref $out and 'SCALAR' ne ref $out or 'GLOB' eq ref \$out) { } 14 14 28
elsif (ref $out and 'SCALAR' eq ref $out and defined ${$out;} and ${$out;} eq 'skip') { } 2 12 14
Condition100%6/6
ref $out and "ARRAY" eq ref $out || "HASH" eq ref $out
!ll&&!rl&&r
8205
"ARRAY" eq ref $out or "HASH" eq ref $out
l!l&&r!l&&!r
4120
MC/DC100%3/3
ref $out and "ARRAY" eq ref $out || "HASH" eq ref $out
ref $out "ARRAY" eq ref $out "HASH" eq ref $out
Truth table100%4/4
A and B or C
A= ref $outB= "ARRAY" eq ref $outC= "HASH" eq ref $out
ABCresult
0XX0
1000
11X1
1011
1433 5 delete $attr{out};
1434 5 $sink = 1;
1435 }
1436 ▶ elsif ((ref $out and "SCALAR" ne ref $out) or "GLOB" eq ref \$out) {
Condition100%6/6
ref $out and "SCALAR" ne ref $out or "GLOB" eq ref \$out
l!l&&r!l&&!r
13114
ref $out and "SCALAR" ne ref $out
!ll&&!rl&&r
8713
MC/DC100%3/3
ref $out and "SCALAR" ne ref $out or "GLOB" eq ref \$out
ref $out "SCALAR" ne ref $out "GLOB" eq ref \$out
Truth table80%4/5
A and B or C
A= ref $outB= "SCALAR" ne ref $outC= "GLOB" eq ref \$out
ABCresult
11X1
0X11
1011
0X00
1000
1437 14 $fh = $out;
1438 }
1439 7 ▶ elsif (ref $out and "SCALAR" eq ref $out and defined ${$out} and ${$out} eq "skip") {
Condition77%7/9
ref $out and "SCALAR" eq ref $out and defined ${$out;} and ${$out;} eq "skip"
!ll&&!rl&&r
752
ref $out and "SCALAR" eq ref $out and defined ${$out;}
!ll&&!rl&&r
707
ref $out and "SCALAR" eq ref $out
!ll&&!rl&&r
707
MC/DC50%2/4
ref $out and "SCALAR" eq ref $out and defined ${$out;} and ${$out;} eq "skip"
ref $out "SCALAR" eq ref $out defined ${$out;} ${$out;} eq "skip"
Truth table60%3/5
A and B and C and D
A= ref $outB= "SCALAR" eq ref $outC= defined ${$out;}D= ${$out;} eq "skip"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1440 2 delete $attr{out};
1441 2 $sink = 1;
1442 }
1443 else {
1444 12 ▶ open $fh, ">", $out or croak("$out: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $out or croak("${out}: $!") 11 1 12
1445 11 $cls = 1;
1446 }
1447 32 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 25 7 32
1448 25 ▶ if ($enc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) 1 24 25
1449 1 binmode $fh, $enc;
1450 1 my $fn = fileno $fh; # This is a workaround for a bug in PerlIO::via::gzip
1451 }
1452 25 ▶ unless (defined $attr{eol} || defined $fho) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $attr{"eol"} or defined $fho) 18 7 25
Condition66%2/3
defined $attr{"eol"} or defined $fho
l!l&&r!l&&!r
7018
MC/DC50%1/2
defined $attr{"eol"} or defined $fho
defined $attr{"eol"} defined $fho
Truth table66%2/3
A or B
A= defined $attr{"eol"}B= defined $fho
ABresult
1X1
011
000
1453 18 my @layers = eval { PerlIO::get_layers($fh) };
1454 18 ▶ $attr{eol} = (grep m/crlf/ => @layers) ? "\n" : "\r\n";
Branch: 1 branch
BranchTrueFalseTotal
grep(/crlf/, @layers) ? : 1 17 18
1455 }
1456 }
1457 }
1458  
1459 341 ▶ if (ref $in eq "CODE" or ref $in eq "ARRAY") {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $in eq 'CODE' or ref $in eq 'ARRAY') { } 24 317 341
elsif (ref $in eq 'SCALAR') { } 30 287 317
elsif (ref $in or 'GLOB' eq ref \$in) { } 18 269 287
Condition100%3/3
ref $in eq "CODE" or ref $in eq "ARRAY"
l!l&&r!l&&!r
321317
MC/DC100%2/2
ref $in eq "CODE" or ref $in eq "ARRAY"
ref $in eq "CODE" ref $in eq "ARRAY"
Truth table100%3/3
A or B
A= ref $in eq "CODE"B= ref $in eq "ARRAY"
ABresult
1X1
011
000
1460 # All done
1461 }
1462 elsif (ref $in eq "SCALAR") {
1463 # Strings with code points over 0xFF may not be mapped into in-memory file handles
1464 # "<$enc" does not change that :(
1465 30 ▶ open $fh, "<", $in or croak("Cannot open from SCALAR using PerlIO");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $in or croak("Cannot open from SCALAR using PerlIO") 30 0 30
1466 30 $cls = 1;
1467 }
1468 ▶ elsif (ref $in or "GLOB" eq ref \$in) {
Condition100%3/3
ref $in or "GLOB" eq ref \$in
l!l&&r!l&&!r
162269
MC/DC100%2/2
ref $in or "GLOB" eq ref \$in
ref $in "GLOB" eq ref \$in
Truth table100%3/3
A or B
A= ref $inB= "GLOB" eq ref \$in
ABresult
1X1
011
000
1469 18 ▶ if (!ref $in && $] < 5.008005) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $in and $] < 5.008005) { } 0 18 18
Condition66%2/3
not ref $in and $] < "5.008005"
!ll&&!rl&&r
1620
MC/DC0%0/2
not ref $in and $] < "5.008005"
not ref $in $] < "5.008005"
Truth table66%2/3
not(A) and B
A= not ref $inB= $] < "5.008005"
ABresult
0X0
100
111
1470 0 $fh = \*{$in}; # uncoverable statement ancient perl version required
1471 }
1472 else {
1473 18 $fh = $in;
1474 }
1475 }
1476 else {
1477 269 ▶ open $fh, "<$enc", $in or croak("$in: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<$enc", $in or croak("${in}: $!") 267 1 268
1478 267 $cls = 1;
1479 }
1480 339 ▶ $fh || $sink or croak(qq{No valid source passed. "in" is required});
Branch: 1 branch
BranchTrueFalseTotal
$fh or $sink or croak("No valid source passed. \"in\" is required") 339 0 339
Condition33%1/3
$fh or $sink
l!l&&r!l&&!r
33900
MC/DC0%0/2
$fh or $sink
$fh $sink
Truth table33%1/3
A or B
A= $fhB= $sink
ABresult
1X1
011
000
1481  
1482 339 for ([quo => "quote"],
1483 [esc => "escape"],
1484 [escape => "escape_char"],
1485 ) {
1486 1017 my ($f, $t) = @{$_};
1487 1017 ▶ exists $attr{$f} and !exists $attr{$t} and $attr{$t} = delete $attr{$f};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr{$f} and not exists $attr{$t} and $attr{$t} = delete $attr{$f} 6 1011 1017
Condition100%3/3
exists $attr{$f} and not exists $attr{$t}
!ll&&!rl&&r
101016
MC/DC100%2/2
exists $attr{$f} and not exists $attr{$t}
exists $attr{$f} not exists $attr{$t}
Truth table100%3/3
A and not(B)
A= exists $attr{$f}B= not exists $attr{$t}
ABresult
0X0
100
111
1488 }
1489  
1490 339 my $fltr = delete $attr{filter};
1491 my %fltr = (
1492 10 ▶ not_blank => sub { @{$_[1]} > 1 or defined $_[1][0] && $_[1][0] ne "" },
Subroutine __ANON__: called CC=3 SCAR=11.8
Branch: 1 branch
BranchTrueFalseTotal
@{$_[1];} > 1 or defined $_[1][0] and $_[1][0] ne "" 8 2 10
Condition50%3/6
@{$_[1];} > 1 || defined $_[1][0] && $_[1][0] ne ''
l!l&&r!l&&!r
802
defined $_[1][0] and $_[1][0] ne ""
!ll&&!rl&&r
020
MC/DC33%1/3
@{$_[1];} > 1 || defined $_[1][0] && $_[1][0] ne ''
@{$_[1];} > 1 defined $_[1][0] $_[1][0] ne ""
Truth table50%2/4
A || B and C
A= @{$_[1];} > 1B= defined $_[1][0]C= $_[1][0] ne ""
ABCresult
1XX1
0111
00X0
0100
1493 10 ▶ not_empty => sub { grep { defined && $_ ne "" } @{$_[1]} },
Subroutine __ANON__: called CC=2 SCAR=7.0
Condition66%2/3
defined $_ && $_ ne ''
!ll&&!rl&&r
01511
MC/DC50%1/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
Truth table66%2/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
1494 10 ▶ filled => sub { grep { defined && m/\S/ } @{$_[1]} },
Subroutine __ANON__: called CC=2 SCAR=7.0
Condition66%2/3
defined $_ && /\S/
!ll&&!rl&&r
0179
MC/DC50%1/2
defined $_ && /\S/
defined $_ /\S/
Truth table66%2/3
A && B
A= defined $_B= /\S/
ABresult
0X0
100
111
1495 339 );
1496 defined $fltr && !ref $fltr && exists $fltr{$fltr} and
1497 339 ▶ $fltr = {0 => $fltr{$fltr}};
Branch: 1 branch
BranchTrueFalseTotal
defined $fltr and not ref $fltr and exists $fltr{$fltr} and $fltr = {0, $fltr{$fltr}} 3 336 339
Condition83%5/6
defined $fltr and not ref $fltr and exists $fltr{$fltr}
!ll&&!rl&&r
33603
defined $fltr and not ref $fltr
!ll&&!rl&&r
323133
MC/DC66%2/3
defined $fltr and not ref $fltr and exists $fltr{$fltr}
defined $fltr not ref $fltr exists $fltr{$fltr}
Truth table75%3/4
A and not(B) and C
A= defined $fltrB= not ref $fltrC= exists $fltr{$fltr}
ABCresult
0XX0
10X0
1100
1111
1498 339 ▶ ref $fltr eq "CODE" and $fltr = {0 => $fltr};
Branch: 1 branch
BranchTrueFalseTotal
ref $fltr eq "CODE" and $fltr = {0, $fltr} 2 337 339
1499 339 ▶ ref $fltr eq "HASH" or $fltr = undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $fltr eq "HASH" or $fltr = undef 16 323 339
1500  
1501 339 my $form = delete $attr{formula};
1502  
1503 339 ▶ defined $attr{auto_diag} or $attr{auto_diag} = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $attr{"auto_diag"} or $attr{"auto_diag"} = 1 31 308 339
1504 339 ▶ defined $attr{escape_null} or $attr{escape_null} = 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $attr{"escape_null"} or $attr{"escape_null"} = 0 1 338 339
1505 339 ▶ my $csv = delete $attr{csv} || Text::CSV_PP->new(\%attr)
Branch: 1 branch
BranchTrueFalseTotal
my $csv = delete $attr{"csv"} || "Text::CSV_PP"->new(\%attr) or croak($last_err) 339 0 339
Condition66%2/3
delete $attr{'csv'} || 'Text::CSV_PP'->new(\%attr)
l!l&&r!l&&!r
173220
MC/DC0%0/2
delete $attr{'csv'} || 'Text::CSV_PP'->new(\%attr)
delete $attr{'csv'} 'Text::CSV_PP'->new(\%attr)
Truth table66%2/3
A || B
A= delete $attr{'csv'}B= 'Text::CSV_PP'->new(\%attr)
ABresult
1X1
011
000
1506 or croak($last_err);
1507 339 ▶ defined $form and $csv->formula($form);
Branch: 1 branch
BranchTrueFalseTotal
defined $form and $csv->formula($form) 1 338 339
1508 339 ▶ defined $cboe and $csv->callbacks(error => $cboe);
Branch: 1 branch
BranchTrueFalseTotal
defined $cboe and $csv->callbacks("error", $cboe) 1 338 339
1509  
1510 339 ▶ $kh && !ref $kh && $kh =~ m/^(?:1|yes|true|internal|auto)$/i and
Branch: 1 branch
BranchTrueFalseTotal
$kh and not ref $kh and $kh =~ /^(?:1|yes|true|internal|auto)$/i and $kh = \@internal_kh 8 331 339
Condition100%6/6
$kh and not ref $kh and $kh =~ /^(?:1|yes|true|internal|auto)$/i
!ll&&!rl&&r
32838
$kh and not ref $kh
!ll&&!rl&&r
320811
MC/DC100%3/3
$kh and not ref $kh and $kh =~ /^(?:1|yes|true|internal|auto)$/i
$kh not ref $kh $kh =~ /^(?:1|yes|true|internal|auto)$/i
Truth table100%4/4
A and not(B) and C
A= $khB= not ref $khC= $kh =~ /^(?:1|yes|true|internal|auto)$/i
ABCresult
0XX0
10X0
1100
1111
1511 $kh = \@internal_kh;
1512  
1513 return {
1514 339 csv => $csv,
1515 attr => {%attr},
1516 fh => $fh,
1517 cls => $cls,
1518 in => $in,
1519 sink => $sink,
1520 out => $out,
1521 enc => $enc,
1522 fho => $fho,
1523 fhoc => $fho_cls,
1524 hdrs => $hdrs,
1525 key => $key,
1526 val => $val,
1527 kh => $kh,
1528 frag => $frag,
1529 fltr => $fltr,
1530 cbai => $cbai,
1531 cbbo => $cbbo,
1532 cboi => $cboi,
1533 hd_s => $hd_s,
1534 hd_b => $hd_b,
1535 hd_m => $hd_m,
1536 hd_c => $hd_c,
1537 };
1538 }
1539  
1540 346 ▶sub csv {
Subroutine csv: called CC=129 SCAR=50.0
Pod documented
1541 346 ▶ @_ && (ref $_[0] eq __PACKAGE__ or ref $_[0] eq 'Text::CSV') and splice @_, 0, 0, "csv";
Branch: 1 branch
BranchTrueFalseTotal
@_ and ref $_[0] eq __PACKAGE__ || ref $_[0] eq "Text::CSV" and splice @_, 0, 0, "csv" 0 346 346
Condition50%3/6
@_ and ref $_[0] eq __PACKAGE__ || ref $_[0] eq "Text::CSV"
!ll&&!rl&&r
13450
ref $_[0] eq __PACKAGE__ or ref $_[0] eq "Text::CSV"
l!l&&r!l&&!r
00345
MC/DC0%0/3
@_ and ref $_[0] eq __PACKAGE__ || ref $_[0] eq "Text::CSV"
@_ ref $_[0] eq __PACKAGE__ ref $_[0] eq "Text::CSV"
Truth table50%2/4
A and B or C
A= @_B= ref $_[0] eq __PACKAGE__C= ref $_[0] eq "Text::CSV"
ABCresult
0XX0
1000
11X1
1011
1542 346 ▶ @_ or croak($csv_usage);
Branch: 1 branch
BranchTrueFalseTotal
@_ or croak($csv_usage) 345 1 346
1543  
1544 345 my $c = _csv_attr(@_);
1545  
1546 339 my ($csv, $in, $fh, $hdrs) = @{$c}{qw( csv in fh hdrs )};
1547 339 my %hdr;
1548 339 ▶ if (ref $hdrs eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hdrs eq "HASH") 2 337 339
1549 2 %hdr = %{$hdrs};
1550 2 $hdrs = "auto";
1551 }
1552  
1553 339 ▶ if ($c->{out} && !$c->{sink}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"out"} and not $c->{"sink"}) 24 315 339
Condition100%3/3
$c->{"out"} and not $c->{"sink"}
!ll&&!rl&&r
308724
MC/DC100%2/2
$c->{"out"} and not $c->{"sink"}
$c->{"out"} not $c->{"sink"}
Truth table100%3/3
A and not(B)
A= $c->{"out"}B= not $c->{"sink"}
ABresult
0X0
100
111
1554 !$hdrs && ref $c->{'kh'} && $c->{'kh'} == \@internal_kh and
1555 24 ▶ $hdrs = $c->{'kh'};
Branch: 1 branch
BranchTrueFalseTotal
not $hdrs and ref $c->{"kh"} and $c->{"kh"} == \@internal_kh and $hdrs = $c->{"kh"} 4 20 24
Condition83%5/6
not $hdrs and ref $c->{"kh"} and $c->{"kh"} == \@internal_kh
!ll&&!rl&&r
2004
not $hdrs and ref $c->{"kh"}
!ll&&!rl&&r
6144
MC/DC66%2/3
not $hdrs and ref $c->{"kh"} and $c->{"kh"} == \@internal_kh
not $hdrs ref $c->{"kh"} $c->{"kh"} == \@internal_kh
Truth table75%3/4
not(A) and B and C
A= not $hdrsB= ref $c->{"kh"}C= $c->{"kh"} == \@internal_kh
ABCresult
0XX0
10X0
1100
1111
1556  
1557 24 ▶ if (ref $in eq "CODE") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $in eq 'CODE') { } 3 21 24
elsif (@{$in;} == 0 or ref $in->[0] eq 'ARRAY') { } 10 11 21
1558 3 my $hdr = 1;
1559 3 ▶ while (my $row = $in->($csv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$in($csv)) 7 3 10
1560 7 ▶ if (ref $row eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $row eq "ARRAY") 3 4 7
1561 3 $csv->print($fh, $row);
1562 3 next;
1563 }
1564 4 ▶ if (ref $row eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $row eq "HASH") 4 0 4
1565 4 ▶ if ($hdr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr) 2 2 4
1566 2 ▶ $hdrs ||= [map { $hdr{$_} || $_ } keys %{$row}];
Condition60%3/5
$hdrs ||= [map({$hdr{$_} or $_;} keys %{$row;})]
l!l
11
$hdr{$_} || $_
l!l&&r!l&&!r
030
MC/DC100%1/1
$hdrs ||= [map({$hdr{$_} or $_;} keys %{$row;})]
$hdrs
MC/DC0%0/2
$hdr{$_} || $_
$hdr{$_} $_
Truth table100%2/2
A
A= $hdrs
Aresult
11
00
Truth table33%1/3
A || B
A= $hdr{$_}B= $_
ABresult
1X1
011
000
1567 2 $csv->print($fh, $hdrs);
1568 2 $hdr = 0;
1569 }
1570 4 $csv->print($fh, [@{$row}{@{$hdrs}}]);
1571 }
1572 }
1573 }
1574 21 ▶ elsif (@{$in} == 0 or ref $in->[0] eq "ARRAY") { # aoa
Condition100%3/3
@{$in;} == 0 or ref $in->[0] eq "ARRAY"
l!l&&r!l&&!r
1911
MC/DC100%2/2
@{$in;} == 0 or ref $in->[0] eq "ARRAY"
@{$in;} == 0 ref $in->[0] eq "ARRAY"
Truth table100%3/3
A or B
A= @{$in;} == 0B= ref $in->[0] eq "ARRAY"
ABresult
1X1
011
000
1575 10 ▶ ref $hdrs and $csv->print($fh, $hdrs);
Branch: 1 branch
BranchTrueFalseTotal
ref $hdrs and $csv->print($fh, $hdrs) 0 10 10
1576 10 for (@{$in}) {
1577 12 ▶ $c->{cboi} and $c->{cboi}->($csv, $_);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cboi"} and $c->{"cboi"}->($csv, $_) 2 10 12
1578 12 ▶ $c->{cbbo} and $c->{cbbo}->($csv, $_);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cbbo"} and $c->{"cbbo"}->($csv, $_) 0 12 12
1579 12 $csv->print($fh, $_);
1580 }
1581 }
1582 else { # aoh
1583 11 ▶ my @hdrs = ref $hdrs ? @{$hdrs} : keys %{$in->[0]};
Branch: 1 branch
BranchTrueFalseTotal
ref $hdrs ? : 5 6 11
1584 11 ▶ defined $hdrs or $hdrs = "auto";
Branch: 1 branch
BranchTrueFalseTotal
defined $hdrs or $hdrs = "auto" 9 2 11
1585 ref $hdrs || $hdrs eq "auto" and @hdrs and
1586 11 ▶ $csv->print($fh, [map { $hdr{$_} || $_ } @hdrs]);
Branch: 1 branch
BranchTrueFalseTotal
ref $hdrs || $hdrs eq "auto" and @hdrs and $csv->print($fh, [map({$hdr{$_} or $_;} @hdrs)]) 10 1 11
Condition77%7/9
ref $hdrs || $hdrs eq "auto" and @hdrs
!ll&&!rl&&r
1010
ref $hdrs or $hdrs eq "auto"
l!l&&r!l&&!r
551
$hdr{$_} || $_
l!l&&r!l&&!r
1190
MC/DC66%2/3
ref $hdrs || $hdrs eq "auto" and @hdrs
ref $hdrs $hdrs eq "auto" @hdrs
MC/DC0%0/2
$hdr{$_} || $_
$hdr{$_} $_
Truth table60%3/5
A or B and C
A= ref $hdrsB= $hdrs eq "auto"C= @hdrs
ABCresult
00X0
1X00
0100
1X11
0111
Truth table66%2/3
A || B
A= $hdr{$_}B= $_
ABresult
1X1
011
000
1587 11 for (@{$in}) {
1588 17 local %_;
1589 17 *_ = $_;
1590 17 ▶ $c->{cboi} and $c->{cboi}->($csv, $_);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cboi"} and $c->{"cboi"}->($csv, $_) 0 17 17
1591 17 ▶ $c->{cbbo} and $c->{cbbo}->($csv, $_);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cbbo"} and $c->{"cbbo"}->($csv, $_) 0 17 17
1592 17 $csv->print($fh, [@{$_}{@hdrs}]);
1593 }
1594 }
1595  
1596 24 ▶ $c->{cls} and close $fh;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cls"} and close $fh 11 13 24
1597 24 ▶ $c->{fho_cls} and close $c->{fho};
Branch: 1 branch
BranchTrueFalseTotal
$c->{"fho_cls"} and close $c->{"fho"} 0 24 24
1598 24 return 1;
1599 }
1600  
1601 315 my @row1;
1602 315 ▶ if (defined $c->{hd_s} || defined $c->{hd_b} || defined $c->{hd_m} || defined $c->{hd_c}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c->{"hd_s"} or defined $c->{"hd_b"} or defined $c->{"hd_m"} or defined $c->{"hd_c"}) 174 141 315
Condition100%9/9
defined $c->{"hd_s"} or defined $c->{"hd_b"} or defined $c->{"hd_m"} or defined $c->{"hd_c"}
l!l&&r!l&&!r
1722141
defined $c->{"hd_s"} or defined $c->{"hd_b"} or defined $c->{"hd_m"}
l!l&&r!l&&!r
1666143
defined $c->{"hd_s"} or defined $c->{"hd_b"}
l!l&&r!l&&!r
10156149
MC/DC100%4/4
defined $c->{"hd_s"} or defined $c->{"hd_b"} or defined $c->{"hd_m"} or defined $c->{"hd_c"}
defined $c->{"hd_s"} defined $c->{"hd_b"} defined $c->{"hd_m"} defined $c->{"hd_c"}
Truth table100%5/5
A or B or C or D
A= defined $c->{"hd_s"}B= defined $c->{"hd_b"}C= defined $c->{"hd_m"}D= defined $c->{"hd_c"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1603 174 my %harg;
1604 !defined $c->{'hd_s'} && $c->{'attr'}{'sep_char'} and
1605 174 ▶ $c->{'hd_s'} = [$c->{'attr'}{'sep_char'}];
Branch: 1 branch
BranchTrueFalseTotal
not defined $c->{"hd_s"} and $c->{"attr"}{"sep_char"} and $c->{"hd_s"} = [$c->{"attr"}{"sep_char"}] 3 171 174
Condition100%3/3
not defined $c->{"hd_s"} and $c->{"attr"}{"sep_char"}
!ll&&!rl&&r
101613
MC/DC100%2/2
not defined $c->{"hd_s"} and $c->{"attr"}{"sep_char"}
not defined $c->{"hd_s"} $c->{"attr"}{"sep_char"}
Truth table100%3/3
not(A) and B
A= not defined $c->{"hd_s"}B= $c->{"attr"}{"sep_char"}
ABresult
0X0
100
111
1606 !defined $c->{'hd_s'} && $c->{'attr'}{'sep'} and
1607 174 ▶ $c->{'hd_s'} = [$c->{'attr'}{'sep'}];
Branch: 1 branch
BranchTrueFalseTotal
not defined $c->{"hd_s"} and $c->{"attr"}{"sep"} and $c->{"hd_s"} = [$c->{"attr"}{"sep"}] 3 171 174
Condition100%3/3
not defined $c->{"hd_s"} and $c->{"attr"}{"sep"}
!ll&&!rl&&r
131583
MC/DC100%2/2
not defined $c->{"hd_s"} and $c->{"attr"}{"sep"}
not defined $c->{"hd_s"} $c->{"attr"}{"sep"}
Truth table100%3/3
not(A) and B
A= not defined $c->{"hd_s"}B= $c->{"attr"}{"sep"}
ABresult
0X0
100
111
1608 174 ▶ defined $c->{'hd_s'} and $harg{'sep_set'} = $c->{'hd_s'};
Branch: 1 branch
BranchTrueFalseTotal
defined $c->{"hd_s"} and $harg{"sep_set"} = $c->{"hd_s"} 16 158 174
1609 174 ▶ defined $c->{'hd_b'} and $harg{'detect_bom'} = $c->{'hd_b'};
Branch: 1 branch
BranchTrueFalseTotal
defined $c->{"hd_b"} and $harg{"detect_bom"} = $c->{"hd_b"} 162 12 174
1610 174 ▶ defined $c->{'hd_m'} and $harg{'munge_column_names'} = $hdrs ? "none" : $c->{'hd_m'};
Branch: 2 branches
BranchTrueFalseTotal
defined $c->{"hd_m"} and $harg{"munge_column_names"} = $hdrs ? "none" : $c->{"hd_m"} 8 166 174
$hdrs ? : 0 8 8
1611 174 ▶ defined $c->{'hd_c'} and $harg{'set_column_names'} = $hdrs ? 0 : $c->{'hd_c'};
Branch: 2 branches
BranchTrueFalseTotal
defined $c->{"hd_c"} and $harg{"set_column_names"} = $hdrs ? 0 : $c->{"hd_c"} 4 170 174
$hdrs ? : 0 4 4
1612 174 @row1 = $csv->header($fh, \%harg);
1613 171 my @hdr = $csv->column_names();
1614 171 ▶ @hdr and $hdrs ||= \@hdr;
Branch: 1 branch
BranchTrueFalseTotal
@hdr and $hdrs ||= \@hdr 167 4 171
Condition100%2/2
$hdrs ||= \@hdr
l!l
1166
MC/DC100%1/1
$hdrs ||= \@hdr
$hdrs
Truth table100%2/2
A
A= $hdrs
Aresult
11
00
1615 }
1616  
1617 312 ▶ if ($c->{kh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"kh"}) 15 297 312
1618 15 @internal_kh = ();
1619 15 ▶ ref $c->{kh} eq "ARRAY" or croak($csv->SetDiag(1501));
Branch: 1 branch
BranchTrueFalseTotal
ref $c->{"kh"} eq "ARRAY" or croak($csv->SetDiag(1501)) 10 5 15
1620 10 ▶ $hdrs ||= "auto";
Condition100%2/2
$hdrs ||= "auto"
l!l
37
MC/DC100%1/1
$hdrs ||= "auto"
$hdrs
Truth table100%2/2
A
A= $hdrs
Aresult
11
00
1621 }
1622  
1623 307 my $key = $c->{key};
1624 307 ▶ if ($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) 27 280 307
1625 27 ▶ !ref $key or ref $key eq "ARRAY" && @{$key} > 1 or croak($csv->SetDiag(1501));
Branch: 1 branch
BranchTrueFalseTotal
not ref $key or ref $key eq "ARRAY" and @{$key;} > 1 or croak($csv->SetDiag(1501)) 20 7 27
Condition100%6/6
not ref $key or ref $key eq "ARRAY" and @{$key;} > 1
l!l&&r!l&&!r
1557
ref $key eq "ARRAY" and @{$key;} > 1
!ll&&!rl&&r
435
MC/DC100%3/3
not ref $key or ref $key eq "ARRAY" and @{$key;} > 1
not ref $key ref $key eq "ARRAY" @{$key;} > 1
Truth table100%4/4
not(A) or B and C
A= not ref $keyB= ref $key eq "ARRAY"C= @{$key;} > 1
ABCresult
1XX1
0111
00X0
0100
1626 20 ▶ $hdrs ||= "auto";
Condition100%2/2
$hdrs ||= "auto"
l!l
713
MC/DC100%1/1
$hdrs ||= "auto"
$hdrs
Truth table100%2/2
A
A= $hdrs
Aresult
11
00
1627 }
1628 300 my $val = $c->{val};
1629 300 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 9 291 300
1630 9 ▶ $key or croak($csv->SetDiag(1502));
Branch: 1 branch
BranchTrueFalseTotal
$key or croak($csv->SetDiag(1502)) 8 1 9
1631 8 ▶ !ref $val or ref $val eq "ARRAY" && @{$val} > 0 or croak($csv->SetDiag(1503));
Branch: 1 branch
BranchTrueFalseTotal
not ref $val or ref $val eq "ARRAY" and @{$val;} > 0 or croak($csv->SetDiag(1503)) 5 3 8
Condition100%6/6
not ref $val or ref $val eq "ARRAY" and @{$val;} > 0
l!l&&r!l&&!r
323
ref $val eq "ARRAY" and @{$val;} > 0
!ll&&!rl&&r
212
MC/DC100%3/3
not ref $val or ref $val eq "ARRAY" and @{$val;} > 0
not ref $val ref $val eq "ARRAY" @{$val;} > 0
Truth table100%4/4
not(A) or B and C
A= not ref $valB= ref $val eq "ARRAY"C= @{$val;} > 0
ABCresult
1XX1
0111
00X0
0100
1632 }
1633  
1634 296 ▶ $c->{fltr} && grep m/\D/ => keys %{$c->{fltr}} and $hdrs ||= "auto";
Branch: 1 branch
BranchTrueFalseTotal
$c->{"fltr"} and grep /\D/, keys %{$$c{"fltr"};} and $hdrs ||= "auto" 5 291 296
Condition100%5/5
$c->{"fltr"} and grep /\D/, keys %{$$c{"fltr"};}
!ll&&!rl&&r
280115
$hdrs ||= "auto"
l!l
23
MC/DC100%2/2
$c->{"fltr"} and grep /\D/, keys %{$$c{"fltr"};}
$c->{"fltr"} grep /\D/, keys %{$$c{"fltr"};}
MC/DC100%1/1
$hdrs ||= "auto"
$hdrs
Truth table100%3/3
A and B
A= $c->{"fltr"}B= grep /\D/, keys %{$$c{"fltr"};}
ABresult
0X0
100
111
Truth table100%2/2
A
A= $hdrs
Aresult
11
00
1635 296 ▶ if (defined $hdrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hdrs) 224 72 296
1636 224 ▶ if (!ref $hdrs or ref $hdrs eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $hdrs or ref $hdrs eq "CODE") 52 172 224
Condition100%3/3
not ref $hdrs or ref $hdrs eq "CODE"
l!l&&r!l&&!r
511172
MC/DC100%2/2
not ref $hdrs or ref $hdrs eq "CODE"
not ref $hdrs ref $hdrs eq "CODE"
Truth table100%3/3
not(A) or B
A= not ref $hdrsB= ref $hdrs eq "CODE"
ABresult
1X1
011
000
1637 52 ▶ my $h = $c->{'hd_b'}
Branch: 1 branch
BranchTrueFalseTotal
$c->{'hd_b'} ? : 1 51 52
1638 ? [$csv->column_names()]
1639 : $csv->getline($fh);
1640 52 ▶ my $has_h = $h && @$h;
Condition33%1/3
$h && @$h
!ll&&!rl&&r
0052
MC/DC0%0/2
$h && @$h
$h @$h
Truth table33%1/3
A && B
A= $hB= @$h
ABresult
0X0
100
111
1641  
1642 52 ▶ if (ref $hdrs) {
Branch: 5 branches
BranchTrueFalseTotal
if (ref $hdrs) { } 1 51 52
elsif ($hdrs eq 'skip') { } 1 50 51
elsif ($hdrs eq 'auto') { } 48 2 50
elsif ($hdrs eq 'lc') { } 1 1 2
elsif ($hdrs eq 'uc') { } 1 0 1
1643 1 ▶ $has_h or return;
Branch: 1 branch
BranchTrueFalseTotal
$has_h or return 1 0 1
1644 1 my $cr = $hdrs;
1645 1 ▶ $hdrs = [map { $cr->($hdr{$_} || $_) } @{$h}];
Condition33%1/3
$hdr{$_} || $_
l!l&&r!l&&!r
030
MC/DC0%0/2
$hdr{$_} || $_
$hdr{$_} $_
Truth table33%1/3
A || B
A= $hdr{$_}B= $_
ABresult
1X1
011
000
1646 }
1647 elsif ($hdrs eq "skip") {
1648 # discard;
1649 }
1650 elsif ($hdrs eq "auto") {
1651 48 ▶ $has_h or return;
Branch: 1 branch
BranchTrueFalseTotal
$has_h or return 48 0 48
1652 48 ▶ $hdrs = [map { $hdr{$_} || $_ } @{$h}];
Condition66%2/3
$hdr{$_} || $_
l!l&&r!l&&!r
11350
MC/DC0%0/2
$hdr{$_} || $_
$hdr{$_} $_
Truth table66%2/3
A || B
A= $hdr{$_}B= $_
ABresult
1X1
011
000
1653 }
1654 elsif ($hdrs eq "lc") {
1655 1 ▶ $has_h or return;
Branch: 1 branch
BranchTrueFalseTotal
$has_h or return 1 0 1
1656 1 ▶ $hdrs = [map { lc($hdr{$_} || $_) } @{$h}];
Condition33%1/3
$hdr{$_} || $_
l!l&&r!l&&!r
030
MC/DC0%0/2
$hdr{$_} || $_
$hdr{$_} $_
Truth table33%1/3
A || B
A= $hdr{$_}B= $_
ABresult
1X1
011
000
1657 }
1658 elsif ($hdrs eq "uc") {
1659 1 ▶ $has_h or return;
Branch: 1 branch
BranchTrueFalseTotal
$has_h or return 1 0 1
1660 1 ▶ $hdrs = [map { uc($hdr{$_} || $_) } @{$h}];
Condition33%1/3
$hdr{$_} || $_
l!l&&r!l&&!r
030
MC/DC0%0/2
$hdr{$_} || $_
$hdr{$_} $_
Truth table33%1/3
A || B
A= $hdr{$_}B= $_
ABresult
1X1
011
000
1661 }
1662 }
1663 224 ▶ $c->{kh} and $hdrs and @{$c->{kh}} = @{$hdrs};
Branch: 1 branch
BranchTrueFalseTotal
$c->{"kh"} and $hdrs and @{$$c{"kh"};} = @{$hdrs;} 10 214 224
Condition66%2/3
$c->{"kh"} and $hdrs
!ll&&!rl&&r
214010
MC/DC50%1/2
$c->{"kh"} and $hdrs
$c->{"kh"} $hdrs
Truth table66%2/3
A and B
A= $c->{"kh"}B= $hdrs
ABresult
0X0
100
111
1664 }
1665  
1666 296 ▶ if ($c->{fltr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"fltr"}) 16 280 296
1667 16 my %f = %{$c->{fltr}};
1668 # convert headers to index
1669 16 my @hdr;
1670 16 ▶ if (ref $hdrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hdrs) 7 9 16
1671 7 @hdr = @{$hdrs};
1672 7 for (0 .. $#hdr) {
1673 21 ▶ exists $f{$hdr[$_]} and $f{$_ + 1} = delete $f{$hdr[$_]};
Branch: 1 branch
BranchTrueFalseTotal
exists $f{$hdr[$_]} and $f{$_ + 1} = delete $f{$hdr[$_]} 5 16 21
1674 }
1675 }
1676 114 ▶ $csv->callbacks(after_parse => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1677 114 my ($CSV, $ROW) = @_; # lexical sub-variables in caps
1678 114 foreach my $FLD (sort keys %f) {
1679 115 local $_ = $ROW->[$FLD - 1];
1680 115 local %_;
1681 115 ▶ @hdr and @_{@hdr} = @{$ROW};
Branch: 1 branch
BranchTrueFalseTotal
@hdr and @_{@hdr} = @{$ROW;} 51 64 115
1682 115 ▶ $f{$FLD}->($CSV, $ROW) or return \"skip";
Branch: 1 branch
BranchTrueFalseTotal
$f{$FLD}->($CSV, $ROW) or return \"skip" 52 63 115
1683 52 $ROW->[$FLD - 1] = $_;
1684 }
1685 16 });
1686 }
1687  
1688 296 my $frag = $c->{frag};
1689 my $ref = ref $hdrs
1690 ? # aoh
1691 296 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
ref $hdrs ? : 223 73 296
1692 223 my @h = $csv->column_names($hdrs);
1693 223 my %h; $h{$_}++ for @h;
1694 223 ▶ exists $h{''} and croak($csv->SetDiag(1012));
Branch: 1 branch
BranchTrueFalseTotal
exists $h{""} and croak($csv->SetDiag(1012)) 0 223 223
1695 223 ▶ unless (keys %h == @h) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %h == @h) 0 223 223
1696 croak($csv->_SetDiagInfo(1013, join ", " =>
1697 0 map { "$_ ($h{$_})" } grep { $h{$_} > 1 } keys %h));
1698 }
1699 $frag ? $csv->fragment($fh, $frag) :
1700 223 ▶ $key ? do {
Branch: 2 branches
BranchTrueFalseTotal
$frag ? : 2 221 223
$key ? : 17 204 221
1701 17 ▶ my ($k, $j, @f) = ref $key ? (undef, @{$key}) : ($key);
Branch: 1 branch
BranchTrueFalseTotal
ref $key ? : 5 12 17
1702 17 ▶ if (my @mk = grep { !exists $h{$_} } grep { defined } $k, @f) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@mk) = grep({not exists $h{$_};} grep({defined $_;} $k, @f))) 2 15 17
1703 2 croak($csv->_SetDiagInfo(4001, join ", " => @mk));
1704 }
1705 +{map {
1706 26 my $r = $_;
1707 26 ▶ my $K = defined $k ? $r->{$k} : join $j => @{$r}{@f};
Branch: 1 branch
BranchTrueFalseTotal
defined $k ? : 22 4 26
1708 ($K => (
1709 $val
1710 ? ref $val
1711 4 ? {map { $_ => $r->{$_} } @{$val}}
1712 26 ▶ : $r->{$val}
Branch: 2 branches
BranchTrueFalseTotal
$val ? : 5 21 26
ref $val ? : 2 3 5
1713 : $r));
1714 15 ▶ } @{$csv->getline_hr_all($fh)}};
Branch: 1 branch
BranchTrueFalseTotal
$frag ? : 2 71 73
1715 }
1716 : $csv->getline_hr_all($fh);
1717 }
1718 : # aoa
1719 $frag ? $csv->fragment($fh, $frag)
1720 : $csv->getline_all($fh);
1721 288 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 288 0 288
1722 288 ▶ @row1 && !$c->{hd_c} && !ref $hdrs and unshift @{$ref}, \@row1;
Branch: 1 branch
BranchTrueFalseTotal
@row1 and not $c->{"hd_c"} and not ref $hdrs and unshift @{$ref;}, \@row1 4 284 288
Condition83%5/6
@row1 and not $c->{"hd_c"} and not ref $hdrs
!ll&&!rl&&r
1191654
@row1 and not $c->{"hd_c"}
!ll&&!rl&&r
1190169
MC/DC66%2/3
@row1 and not $c->{"hd_c"} and not ref $hdrs
@row1 not $c->{"hd_c"} not ref $hdrs
Truth table75%3/4
A and not(B) and not(C)
A= @row1B= not $c->{"hd_c"}C= not ref $hdrs
ABCresult
0XX0
10X0
1100
1111
1723 }
1724 else {
1725 0 Text::CSV_PP->auto_diag();
1726 }
1727 288 ▶ $c->{cls} and close $fh;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cls"} and close $fh 270 18 288
1728 288 ▶ $c->{fho_cls} and close $c->{fho};
Branch: 1 branch
BranchTrueFalseTotal
$c->{"fho_cls"} and close $c->{"fho"} 0 288 288
1729 288 ▶ if ($ref and $c->{cbai} || $c->{cboi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and $c->{"cbai"} || $c->{"cboi"}) 23 265 288
Condition83%5/6
$ref and $c->{"cbai"} || $c->{"cboi"}
!ll&&!rl&&r
026523
$c->{"cbai"} or $c->{"cboi"}
l!l&&r!l&&!r
1211265
MC/DC66%2/3
$ref and $c->{"cbai"} || $c->{"cboi"}
$ref $c->{"cbai"} $c->{"cboi"}
Truth table75%3/4
A and B or C
A= $refB= $c->{"cbai"}C= $c->{"cboi"}
ABCresult
0XX0
1000
11X1
1011
1730 # Default is ARRAYref, but with key =>, you'll get a hashref
1731 23 ▶ foreach my $r (ref $ref eq "ARRAY" ? @{$ref} : values %{$ref}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 22 1 23
1732 74 local %_;
1733 74 ▶ ref $r eq "HASH" and *_ = $r;
Branch: 1 branch
BranchTrueFalseTotal
ref $r eq "HASH" and *_ = $r 34 40 74
1734 74 ▶ $c->{cbai} and $c->{cbai}->($csv, $r);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cbai"} and $c->{"cbai"}->($csv, $r) 33 41 74
1735 74 ▶ $c->{cboi} and $c->{cboi}->($csv, $r);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cboi"} and $c->{"cboi"}->($csv, $r) 46 28 74
1736 }
1737 }
1738  
1739 288 ▶ if ($c->{sink}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"sink"}) 14 274 288
1740 14 ▶ my $ro = ref $c->{out} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ro = ref $c->{"out"} or return 7 7 14
1741  
1742 7 ▶ $ro eq "SCALAR" && ${$c->{out}} eq "skip" and
Branch: 1 branch
BranchTrueFalseTotal
$ro eq "SCALAR" and ${$c->{"out"};} eq "skip" and return 2 5 7
Condition66%2/3
$ro eq "SCALAR" and ${$c->{"out"};} eq "skip"
!ll&&!rl&&r
502
MC/DC50%1/2
$ro eq "SCALAR" and ${$c->{"out"};} eq "skip"
$ro eq "SCALAR" ${$c->{"out"};} eq "skip"
Truth table66%2/3
A and B
A= $ro eq "SCALAR"B= ${$c->{"out"};} eq "skip"
ABresult
0X0
100
111
1743 return;
1744  
1745 5 ▶ $ro eq ref $ref or
Branch: 1 branch
BranchTrueFalseTotal
$ro eq ref $ref or croak($csv->_SetDiagInfo(5001, "Output type mismatch")) 5 0 5
1746 croak($csv->_SetDiagInfo(5001, "Output type mismatch"));
1747  
1748 5 ▶ if ($ro eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ro eq "ARRAY") 4 1 5
1749 4 ▶ if (@{$c->{out}} and @$ref and ref $c->{out}[0] eq ref $ref->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$c->{"out"};} and @$ref and ref $c->{"out"}[0] eq ref $ref->[0]) 2 2 4
Condition50%3/6
@{$c->{"out"};} and @$ref and ref $c->{"out"}[0] eq ref $ref->[0]
!ll&&!rl&&r
022
@{$c->{"out"};} and @$ref
!ll&&!rl&&r
004
MC/DC33%1/3
@{$c->{"out"};} and @$ref and ref $c->{"out"}[0] eq ref $ref->[0]
@{$c->{"out"};} @$ref ref $c->{"out"}[0] eq ref $ref->[0]
Truth table50%2/4
A and B and C
A= @{$c->{"out"};}B= @$refC= ref $c->{"out"}[0] eq ref $ref->[0]
ABCresult
0XX0
10X0
1100
1111
1750 2 push @{$c->{out}} => @$ref;
1751 2 return $c->{out};
1752 }
1753 2 croak($csv->_SetDiagInfo(5001, "Output type mismatch"));
1754 }
1755  
1756 1 ▶ if ($ro eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ro eq "HASH") 1 0 1
1757 1 @{$c->{out}}{keys %{$ref}} = values %{$ref};
1758 1 return $c->{out};
1759 }
1760  
1761 0 croak($csv->_SetDiagInfo(5002, "Unsupported output type"));
1762 }
1763  
1764 defined wantarray or
1765 return csv(
1766 in => $ref,
1767 headers => $hdrs,
1768 274 ▶ %{$c->{attr}},
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray or return csv("in", $ref, "headers", $hdrs, %{$$c{"attr"};}) 273 1 274
1769 );
1770  
1771 273 ▶ $last_err ||= $csv->{_ERROR_DIAG};
Condition100%3/3
$last_err ||= $csv->{"_ERROR_DIAG"}
l!l&&r!l&&!r
22674
MC/DC100%2/2
$last_err ||= $csv->{"_ERROR_DIAG"}
$last_err $csv->{"_ERROR_DIAG"}
Truth table100%3/3
A ||= B
A= $last_errB= $csv->{"_ERROR_DIAG"}
ABresult
1X1
011
000
1772 273 return $ref;
1773 }
1774  
1775 # The end of the common pure perl part.
1776  
1777 ################################################################################
1778 #
1779 # The following are methods implemented in XS in Text::CSV_XS or
1780 # helper methods for Text::CSV_PP only
1781 #
1782 ################################################################################
1783  
1784 39 my $last_error;
1785 28222 ▶sub _setup_ctx {
Subroutine _setup_ctx: called CC=57 SCAR=40.7
1786 28222 my $self = shift;
1787  
1788 28222 $last_error = undef;
1789  
1790 28222 my $ctx;
1791 28222 ▶ if ($self->{_CACHE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_CACHE'}) { } 27310 912 28222
1792 27310 %$ctx = %{$self->{_CACHE}};
1793 } else {
1794 912 $ctx->{sep} = ',';
1795 912 ▶ if (defined $self->{sep_char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"sep_char"}) 912 0 912
1796 912 $ctx->{sep} = $self->{sep_char};
1797 }
1798 912 ▶ if (defined $self->{sep} and $self->{sep} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"sep"} and $self->{"sep"} ne "") 5 907 912
Condition100%3/3
defined $self->{"sep"} and $self->{"sep"} ne ""
!ll&&!rl&&r
6872205
MC/DC100%2/2
defined $self->{"sep"} and $self->{"sep"} ne ""
defined $self->{"sep"} $self->{"sep"} ne ""
Truth table100%3/3
A and B
A= defined $self->{"sep"}B= $self->{"sep"} ne ""
ABresult
0X0
100
111
1799 39 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
1800 5 $ctx->{sep} = $self->{sep};
1801 5 my $sep_len = length($ctx->{sep});
1802 5 ▶ $ctx->{sep_len} = $sep_len if $sep_len > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $sep_len > 1 5 0 5
1803 }
1804  
1805 912 $ctx->{quo} = '"';
1806 912 ▶ if (exists $self->{quote_char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"quote_char"}) 912 0 912
1807 912 my $quote_char = $self->{quote_char};
1808 912 ▶ if (defined $quote_char and length $quote_char) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $quote_char and length $quote_char) { } 908 4 912
Condition66%2/3
defined $quote_char and length $quote_char
!ll&&!rl&&r
40908
MC/DC50%1/2
defined $quote_char and length $quote_char
defined $quote_char length $quote_char
Truth table66%2/3
A and B
A= defined $quote_charB= length $quote_char
ABresult
0X0
100
111
1809 908 $ctx->{quo} = $quote_char;
1810 } else {
1811 4 $ctx->{quo} = "\0";
1812 }
1813 }
1814 912 ▶ if (defined $self->{quote} and $self->{quote} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"quote"} and $self->{"quote"} ne "") 4 908 912
Condition100%3/3
defined $self->{"quote"} and $self->{"quote"} ne ""
!ll&&!rl&&r
90714
MC/DC100%2/2
defined $self->{"quote"} and $self->{"quote"} ne ""
defined $self->{"quote"} $self->{"quote"} ne ""
Truth table100%3/3
A and B
A= defined $self->{"quote"}B= $self->{"quote"} ne ""
ABresult
0X0
100
111
1815 39 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
1816 4 $ctx->{quo} = $self->{quote};
1817 4 my $quote_len = length($ctx->{quo});
1818 4 ▶ $ctx->{quo_len} = $quote_len if $quote_len > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $quote_len > 1 4 0 4
1819 }
1820  
1821 912 $ctx->{escape_char} = '"';
1822 912 ▶ if (exists $self->{escape_char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"escape_char"}) 912 0 912
1823 912 my $escape_char = $self->{escape_char};
1824 912 ▶ if (defined $escape_char and length $escape_char) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $escape_char and length $escape_char) { } 904 8 912
Condition100%3/3
defined $escape_char and length $escape_char
!ll&&!rl&&r
62904
MC/DC100%2/2
defined $escape_char and length $escape_char
defined $escape_char length $escape_char
Truth table100%3/3
A and B
A= defined $escape_charB= length $escape_char
ABresult
0X0
100
111
1825 904 $ctx->{escape_char} = $escape_char;
1826 } else {
1827 8 $ctx->{escape_char} = "\0";
1828 }
1829 }
1830  
1831 912 ▶ if (defined $self->{eol}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"eol"}) 907 5 912
1832 907 my $eol = $self->{eol};
1833 907 my $eol_len = length($eol);
1834 907 $ctx->{eol} = $eol;
1835 907 $ctx->{eol_len} = $eol_len;
1836 907 ▶ if ($eol_len == 1 and $eol eq "\015") {
Branch: 3 branches
BranchTrueFalseTotal
if ($eol_len == 1 and $eol eq "\r") { } 42 865 907
elsif ($eol_len == 1 and $eol eq "\n") { } 57 808 865
elsif ($eol_len == 2 and $eol eq "\r\n") { } 51 1509 1560
Condition100%3/3
$eol_len == 1 and $eol eq "\r"
!ll&&!rl&&r
8046142
MC/DC100%2/2
$eol_len == 1 and $eol eq "\r"
$eol_len == 1 $eol eq "\r"
Truth table100%3/3
A and B
A= $eol_len == 1B= $eol eq "\r"
ABresult
0X0
100
111
1837 42 $ctx->{eol_is_cr} = 1;
1838 42 $ctx->{eol_type} = EOL_TYPE_CR;
1839 }
1840 ▶ elsif ($eol_len == 1 && $eol eq "\012") {
Condition100%3/3
$eol_len == 1 and $eol eq "\n"
!ll&&!rl&&r
804457
MC/DC100%2/2
$eol_len == 1 and $eol eq "\n"
$eol_len == 1 $eol eq "\n"
Truth table100%3/3
A and B
A= $eol_len == 1B= $eol eq "\n"
ABresult
0X0
100
111
1841 57 $ctx->{eol_type} = EOL_TYPE_NL;
1842 }
1843 ▶ elsif ($eol_len == 2 && $eol eq "\015\012") {
Condition100%3/3
$eol_len == 2 and $eol eq "\r\n"
!ll&&!rl&&r
752551
MC/DC100%2/2
$eol_len == 2 and $eol eq "\r\n"
$eol_len == 2 $eol eq "\r\n"
Truth table100%3/3
A and B
A= $eol_len == 2B= $eol eq "\r\n"
ABresult
0X0
100
111
1844 51 $ctx->{eol_type} = EOL_TYPE_CRNL;
1845 }
1846 }
1847  
1848 912 $ctx->{undef_flg} = 0;
1849 912 ▶ if (defined $self->{undef_str}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'undef_str'}) { } 1 911 912
1850 1 $ctx->{undef_str} = $self->{undef_str};
1851 1 ▶ $ctx->{undef_flg} = 3 if utf8::is_utf8($self->{undef_str});
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($self->{"undef_str"}) 0 1 1
1852 } else {
1853 911 $ctx->{undef_str} = undef;
1854 }
1855 912 ▶ if (defined $self->{comment_str}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"comment_str"}) 21 891 912
1856 21 $ctx->{comment_str} = $self->{comment_str};
1857 }
1858  
1859 912 ▶ if (defined $self->{_types}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_types"}) 1 911 912
1860 1 $ctx->{types} = $self->{_types};
1861 1 $ctx->{types_len} = length($ctx->{types});
1862 }
1863  
1864 912 ▶ if (defined $self->{_is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_is_bound"}) 12 900 912
1865 12 $ctx->{is_bound} = $self->{_is_bound};
1866 }
1867  
1868 912 ▶ if (defined $self->{callbacks}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"callbacks"}) 324 588 912
1869 324 my $cb = $self->{callbacks};
1870 324 $ctx->{has_hooks} = 0;
1871 324 ▶ if (defined $cb->{after_parse} and ref $cb->{after_parse} eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cb->{"after_parse"} and ref $cb->{"after_parse"} eq "CODE") 16 308 324
Condition66%2/3
defined $cb->{"after_parse"} and ref $cb->{"after_parse"} eq "CODE"
!ll&&!rl&&r
308016
MC/DC50%1/2
defined $cb->{"after_parse"} and ref $cb->{"after_parse"} eq "CODE"
defined $cb->{"after_parse"} ref $cb->{"after_parse"} eq "CODE"
Truth table66%2/3
A and B
A= defined $cb->{"after_parse"}B= ref $cb->{"after_parse"} eq "CODE"
ABresult
0X0
100
111
1872 16 $ctx->{has_hooks} |= HOOK_AFTER_PARSE;
1873 }
1874 324 ▶ if (defined $cb->{before_print} and ref $cb->{before_print} eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cb->{"before_print"} and ref $cb->{"before_print"} eq "CODE") 3 321 324
Condition66%2/3
defined $cb->{"before_print"} and ref $cb->{"before_print"} eq "CODE"
!ll&&!rl&&r
32103
MC/DC50%1/2
defined $cb->{"before_print"} and ref $cb->{"before_print"} eq "CODE"
defined $cb->{"before_print"} ref $cb->{"before_print"} eq "CODE"
Truth table66%2/3
A and B
A= defined $cb->{"before_print"}B= ref $cb->{"before_print"} eq "CODE"
ABresult
0X0
100
111
1875 3 $ctx->{has_hooks} |= HOOK_BEFORE_PRINT;
1876 }
1877 }
1878  
1879 912 for (qw/
1880 binary decode_utf8 always_quote strict strict_eol quote_empty
1881 allow_loose_quotes allow_loose_escapes
1882 allow_unquoted_escape allow_whitespace blank_is_undef
1883 empty_is_undef verbatim auto_diag diag_verbose
1884 keep_meta_info formula skip_empty_rows
1885 /) {
1886 16416 ▶ $ctx->{$_} = defined $self->{$_} ? $self->{$_} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$_} ? : 16416 0 16416
1887 }
1888 912 for (qw/quote_space escape_null quote_binary/) {
1889 2736 ▶ $ctx->{$_} = defined $self->{$_} ? $self->{$_} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$_} ? : 2736 0 2736
1890 }
1891 912 ▶ if ($ctx->{escape_char} eq "\0") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"escape_char"} eq "\0") 8 904 912
1892 8 $ctx->{escape_null} = 0;
1893 }
1894  
1895 # FIXME: readonly
1896 912 %{$self->{_CACHE}} = %$ctx;
1897 }
1898  
1899 28222 $ctx->{utf8} = 0;
1900 28222 $ctx->{size} = 0;
1901 28222 $ctx->{used} = 0;
1902  
1903 28222 ▶ if ($ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"is_bound"}) 121 28101 28222
1904 121 my $bound = $self->{_BOUND_COLUMNS};
1905 121 ▶ if ($bound and ref $bound eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bound and ref $bound eq 'ARRAY') { } 107 14 121
Condition66%2/3
$bound and ref $bound eq "ARRAY"
!ll&&!rl&&r
140107
MC/DC50%1/2
$bound and ref $bound eq "ARRAY"
$bound ref $bound eq "ARRAY"
Truth table66%2/3
A and B
A= $boundB= ref $bound eq "ARRAY"
ABresult
0X0
100
111
1906 107 $ctx->{bound} = $bound;
1907 } else {
1908 14 $ctx->{is_bound} = 0;
1909 }
1910 }
1911  
1912 28222 $ctx->{eol_pos} = -1;
1913 $ctx->{eolx} = $ctx->{eol_len}
1914 ? $ctx->{verbatim} || $ctx->{eol_len} >= 2
1915 ? 1
1916 28222 ▶ : $ctx->{eol} =~ /\A[\015\012]/ ? 0 : 1
Branch: 3 branches
BranchTrueFalseTotal
$ctx->{'eol_len'} ? : 1494 26728 28222
$ctx->{'verbatim'} || $ctx->{'eol_len'} >= 2 ? : 507 987 1494
$ctx->{'eol'} =~ /\A[\015\012]/ ? : 933 54 987
Condition100%3/3
$ctx->{"verbatim"} or $ctx->{"eol_len"} >= 2
l!l&&r!l&&!r
7500987
MC/DC100%2/2
$ctx->{"verbatim"} or $ctx->{"eol_len"} >= 2
$ctx->{"verbatim"} $ctx->{"eol_len"} >= 2
Truth table100%3/3
A or B
A= $ctx->{"verbatim"}B= $ctx->{"eol_len"} >= 2
ABresult
1X1
011
000
1917 : 0;
1918 28222 ▶ if ($ctx->{eol_type} && $ctx->{strict_eol} && !$ctx->{eol}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"eol_type"} and $ctx->{"strict_eol"} and not $ctx->{"eol"}) 1029 27193 28222
Condition100%6/6
$ctx->{"eol_type"} and $ctx->{"strict_eol"} and not $ctx->{"eol"}
!ll&&!rl&&r
269912021029
$ctx->{"eol_type"} and $ctx->{"strict_eol"}
!ll&&!rl&&r
2454724441231
MC/DC100%3/3
$ctx->{"eol_type"} and $ctx->{"strict_eol"} and not $ctx->{"eol"}
$ctx->{"eol_type"} $ctx->{"strict_eol"} not $ctx->{"eol"}
Truth table100%4/4
A and B and not(C)
A= $ctx->{"eol_type"}B= $ctx->{"strict_eol"}C= not $ctx->{"eol"}
ABCresult
0XX0
10X0
1100
1111
1919 1029 $ctx->{eol_is_cr} = 0;
1920 }
1921 28222 ▶ if ($ctx->{sep_len} and $ctx->{sep_len} > 1 and _is_valid_utf8($ctx->{sep})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"sep_len"} and $ctx->{"sep_len"} > 1 and _is_valid_utf8($ctx->{"sep"})) 13 28209 28222
Condition83%5/6
$ctx->{"sep_len"} and $ctx->{"sep_len"} > 1 and _is_valid_utf8($ctx->{"sep"})
!ll&&!rl&&r
281694013
$ctx->{"sep_len"} and $ctx->{"sep_len"} > 1
!ll&&!rl&&r
28169053
MC/DC66%2/3
$ctx->{"sep_len"} and $ctx->{"sep_len"} > 1 and _is_valid_utf8($ctx->{"sep"})
$ctx->{"sep_len"} $ctx->{"sep_len"} > 1 _is_valid_utf8($ctx->{"sep"})
Truth table75%3/4
A and B and C
A= $ctx->{"sep_len"}B= $ctx->{"sep_len"} > 1C= _is_valid_utf8($ctx->{"sep"})
ABCresult
0XX0
10X0
1100
1111
1922 13 $ctx->{utf8} = 1;
1923 }
1924 28222 ▶ if ($ctx->{quo_len} and $ctx->{quo_len} > 1 and _is_valid_utf8($ctx->{quo})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"quo_len"} and $ctx->{"quo_len"} > 1 and _is_valid_utf8($ctx->{"quo"})) 0 28222 28222
Condition66%4/6
$ctx->{"quo_len"} and $ctx->{"quo_len"} > 1 and _is_valid_utf8($ctx->{"quo"})
!ll&&!rl&&r
28194280
$ctx->{"quo_len"} and $ctx->{"quo_len"} > 1
!ll&&!rl&&r
28194028
MC/DC0%0/3
$ctx->{"quo_len"} and $ctx->{"quo_len"} > 1 and _is_valid_utf8($ctx->{"quo"})
$ctx->{"quo_len"} $ctx->{"quo_len"} > 1 _is_valid_utf8($ctx->{"quo"})
Truth table50%2/4
A and B and C
A= $ctx->{"quo_len"}B= $ctx->{"quo_len"} > 1C= _is_valid_utf8($ctx->{"quo"})
ABCresult
0XX0
10X0
1100
1111
1925 0 $ctx->{utf8} = 1;
1926 }
1927  
1928 28222 ▶ if ($ctx->{strict} && !$ctx->{strict_n} && $self->{_COLUMN_NAMES} && ref $self->{_COLUMN_NAMES} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict"} and not $ctx->{"strict_n"} and $self->{"_COLUMN_NAMES"} and ref $self->{"_COLUMN_NAMES"} eq "ARRAY") 2 28220 28222
Condition88%8/9
$ctx->{"strict"} and not $ctx->{"strict_n"} and $self->{"_COLUMN_NAMES"} and ref $self->{"_COLUMN_NAMES"} eq "ARRAY"
!ll&&!rl&&r
2822002
$ctx->{"strict"} and not $ctx->{"strict_n"} and $self->{"_COLUMN_NAMES"}
!ll&&!rl&&r
28195252
$ctx->{"strict"} and not $ctx->{"strict_n"}
!ll&&!rl&&r
281484727
MC/DC75%3/4
$ctx->{"strict"} and not $ctx->{"strict_n"} and $self->{"_COLUMN_NAMES"} and ref $self->{"_COLUMN_NAMES"} eq "ARRAY"
$ctx->{"strict"} not $ctx->{"strict_n"} $self->{"_COLUMN_NAMES"} ref $self->{"_COLUMN_NAMES"} eq "ARRAY"
Truth table80%4/5
A and not(B) and C and D
A= $ctx->{"strict"}B= not $ctx->{"strict_n"}C= $self->{"_COLUMN_NAMES"}D= ref $self->{"_COLUMN_NAMES"} eq "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1929 2 $ctx->{strict_n} = @{$self->{_COLUMN_NAMES}};
1930 }
1931 28222 $ctx;
1932 }
1933  
1934 2876 ▶sub _eol_type {
Subroutine _eol_type: called CC=3 SCAR=11.0
1935 2876 my $c = shift;
1936 2876 ▶ return EOL_TYPE_NL if $c eq "\012";
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "\n" 1976 900 2876
1937 900 ▶ return EOL_TYPE_CR if $c eq "\015";
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "\r" 109 791 900
1938 791 return EOL_TYPE_OTHER;
1939 }
1940  
1941 3337 ▶sub _set_eol_type {
Subroutine _set_eol_type: called CC=2 SCAR=6.9
1942 3337 my ($self, $ctx, $type) = @_;
1943 3337 ▶ if (!$ctx->{eol_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ctx->{"eol_type"}) 630 2707 3337
1944 630 $ctx->{eol_type} = $type;
1945 630 $self->_cache_set($_cache_id{eol_type} => $type);
1946 }
1947 }
1948  
1949 32 ▶sub _cache_get_eolt {
Subroutine _cache_get_eolt: called CC=7 SCAR=19.9
1950 32 my $self = shift;
1951 32 ▶ return unless exists $self->{_CACHE};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_CACHE"} 0 32 32
1952 32 my $cache = $self->{_CACHE};
1953  
1954 32 ▶ my $eol_type = $cache->{eol_type} || 0;
Condition100%2/2
$cache->{'eol_type'} || 0
l!l
2111
MC/DC100%1/1
$cache->{'eol_type'} || 0
$cache->{'eol_type'}
Truth table100%2/2
A
A= $cache->{'eol_type'}
Aresult
11
00
1955 32 ▶ return "\012" if $eol_type == EOL_TYPE_NL;
Branch: 1 branch
BranchTrueFalseTotal
if $eol_type == 1 0 32 32
1956 32 ▶ return "\015" if $eol_type == EOL_TYPE_CR;
Branch: 1 branch
BranchTrueFalseTotal
if $eol_type == 2 0 32 32
1957 32 ▶ return "\015\012" if $eol_type == EOL_TYPE_CRNL;
Branch: 1 branch
BranchTrueFalseTotal
if $eol_type == 3 21 11 32
1958 11 ▶ return $cache->{eol} if $eol_type == EOL_TYPE_OTHER;
Branch: 1 branch
BranchTrueFalseTotal
if $eol_type == 4 0 11 11
1959 11 return;
1960 }
1961  
1962 24322 ▶sub _cache_set {
Subroutine _cache_set: called CC=27 SCAR=33.0
1963 24322 my ($self, $idx, $value) = @_;
1964 24322 ▶ return unless exists $self->{_CACHE};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_CACHE"} 995 23327 24322
1965 23327 my $cache = $self->{_CACHE};
1966  
1967 23327 my $key = $_reverse_cache_id{$idx};
1968 23327 ▶ if (!defined $key) {
Branch: 10 branches
BranchTrueFalseTotal
if (not defined $key) { } 2 23325 23327
elsif ($key eq 'sep_char') { } 3122 20203 23325
elsif ($key eq 'quote_char') { } 3369 16834 20203
elsif ($key eq '_has_ahead') { } 251 16583 16834
elsif ($key eq '_has_hooks') { } 11 16572 16583
elsif ($key eq '_is_bound') { } 12 16560 16572
elsif ($key eq 'sep') { } 3223 13337 16560
elsif ($key eq 'quote') { } 3377 9960 13337
elsif ($key eq 'eol') { } 218 9742 9960
elsif ($key eq 'undef_str') { } 11 9731 9742
1969 2 warn(sprintf "Unknown cache index %d ignored\n", $idx);
1970 } elsif ($key eq 'sep_char') {
1971 3122 $cache->{sep} = $value;
1972 3122 $cache->{sep_len} = 0;
1973 }
1974 elsif ($key eq 'quote_char') {
1975 3369 $cache->{quo} = $value;
1976 3369 $cache->{quo_len} = 0;
1977 }
1978 elsif ($key eq '_has_ahead') {
1979 251 $cache->{has_ahead} = $value;
1980 }
1981 elsif ($key eq '_has_hooks') {
1982 11 $cache->{has_hooks} = $value;
1983 }
1984 elsif ($key eq '_is_bound') {
1985 12 $cache->{is_bound} = $value;
1986 }
1987 elsif ($key eq 'sep') {
1988 39 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
1989 3223 my $len = bytes::length($value);
1990 3223 ▶ $cache->{sep} = $value if $len;
Branch: 1 branch
BranchTrueFalseTotal
if $len 11 3212 3223
1991 3223 ▶ $cache->{sep_len} = $len == 1 ? 0 : $len;
Branch: 1 branch
BranchTrueFalseTotal
$len == 1 ? : 0 3223 3223
1992 }
1993 elsif ($key eq 'quote') {
1994 39 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
1995 3377 my $len = bytes::length($value);
1996 3377 ▶ $cache->{quo} = $value if $len;
Branch: 1 branch
BranchTrueFalseTotal
if $len 3 3374 3377
1997 3377 ▶ $cache->{quo_len} = $len == 1 ? 0 : $len;
Branch: 1 branch
BranchTrueFalseTotal
$len == 1 ? : 0 3377 3377
1998 }
1999 elsif ($key eq 'eol') {
2000 218 $cache->{eol} = $value;
2001 218 ▶ $cache->{eol_len} = my $len = defined $value ? length($value) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 218 0 218
2002 218 ▶ $cache->{eol_type} = $len == 0 ? EOL_TYPE_UNDEF
Branch: 4 branches
BranchTrueFalseTotal
$len == 0 ? : 131 87 218
$len == 1 && $value eq "\n" ? : 4 83 87
$len == 1 && $value eq "\r" ? : 75 8 83
$len == 2 && $value eq "\r\n" ? : 4 4 8
Condition88%8/9
$len == 1 and $value eq "\n"
!ll&&!rl&&r
6774
$len == 1 and $value eq "\r"
!ll&&!rl&&r
6275
$len == 2 and $value eq "\r\n"
!ll&&!rl&&r
404
MC/DC100%2/2
$len == 1 and $value eq "\n"
$len == 1 $value eq "\n"
MC/DC100%2/2
$len == 1 and $value eq "\r"
$len == 1 $value eq "\r"
MC/DC50%1/2
$len == 2 and $value eq "\r\n"
$len == 2 $value eq "\r\n"
Truth table100%3/3
A and B
A= $len == 1B= $value eq "\n"
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= $len == 1B= $value eq "\r"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $len == 2B= $value eq "\r\n"
ABresult
0X0
100
111
2003 : $len == 1 && $value eq "\012" ? EOL_TYPE_NL
2004 : $len == 1 && $value eq "\015" ? EOL_TYPE_CR
2005 : $len == 2 && $value eq "\015\012" ? EOL_TYPE_CRNL
2006 : EOL_TYPE_OTHER;
2007 218 ▶ $cache->{eol_is_cr} = $cache->{eol_type} == EOL_TYPE_CR ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cache->{'eol_type'} == 2 ? : 75 143 218
2008 }
2009 elsif ($key eq 'undef_str') {
2010 11 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 9 2 11
2011 9 $cache->{undef_str} = $value;
2012 9 ▶ $cache->{undef_flg} = 3 if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 1 8 9
2013 } else {
2014 2 $cache->{undef_str} = undef;
2015 2 $cache->{undef_flg} = 0;
2016 }
2017 }
2018 else {
2019 9731 $cache->{$key} = $value;
2020 }
2021 23327 return 1;
2022 }
2023  
2024 2 ▶sub _cache_diag {
Subroutine _cache_diag: called CC=10 SCAR=24.6
2025 2 my $self = shift;
2026 2 ▶ unless (exists $self->{_CACHE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_CACHE"}) 1 1 2
2027 1 warn("CACHE: invalid\n");
2028 1 return;
2029 }
2030  
2031 1 my $cache = $self->{_CACHE};
2032 1 warn("CACHE:\n");
2033 1 $self->__cache_show_char(quote_char => $cache->{quo});
2034 1 $self->__cache_show_char(escape_char => $cache->{escape_char});
2035 1 $self->__cache_show_char(sep_char => $cache->{sep});
2036 1 for (qw/
2037 binary decode_utf8 allow_loose_escapes allow_loose_quotes allow_unquoted_escape
2038 allow_whitespace always_quote quote_empty quote_space
2039 escape_null quote_binary auto_diag diag_verbose formula strict strict_n strict_eol eol_type skip_empty_rows
2040 has_error_input blank_is_undef empty_is_undef has_ahead
2041 keep_meta_info verbatim useIO has_hooks eol_is_cr eol_len
2042 /) {
2043 29 $self->__cache_show_byte($_ => $cache->{$_});
2044 }
2045 1 $self->__cache_show_str(eol => $cache->{eol_len}, $cache->{eol});
2046 1 $self->__cache_show_byte(sep_len => $cache->{sep_len});
2047 1 ▶ if ($cache->{sep_len} and $cache->{sep_len} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->{"sep_len"} and $cache->{"sep_len"} > 1) 1 0 1
Condition33%1/3
$cache->{"sep_len"} and $cache->{"sep_len"} > 1
!ll&&!rl&&r
001
MC/DC0%0/2
$cache->{"sep_len"} and $cache->{"sep_len"} > 1
$cache->{"sep_len"} $cache->{"sep_len"} > 1
Truth table33%1/3
A and B
A= $cache->{"sep_len"}B= $cache->{"sep_len"} > 1
ABresult
0X0
100
111
2048 1 $self->__cache_show_str(sep => $cache->{sep_len}, $cache->{sep});
2049 }
2050 1 $self->__cache_show_byte(quo_len => $cache->{quo_len});
2051 1 ▶ if ($cache->{quo_len} and $cache->{quo_len} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->{"quo_len"} and $cache->{"quo_len"} > 1) 1 0 1
Condition33%1/3
$cache->{"quo_len"} and $cache->{"quo_len"} > 1
!ll&&!rl&&r
001
MC/DC0%0/2
$cache->{"quo_len"} and $cache->{"quo_len"} > 1
$cache->{"quo_len"} $cache->{"quo_len"} > 1
Truth table33%1/3
A and B
A= $cache->{"quo_len"}B= $cache->{"quo_len"} > 1
ABresult
0X0
100
111
2052 1 $self->__cache_show_str(quote => $cache->{quo_len}, $cache->{quo});
2053 }
2054 1 ▶ if ($cache->{types_len}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->{'types_len'}) { } 0 1 1
2055 0 $self->__cache_show_str(types => $cache->{types_len}, $cache->{types});
2056 } else {
2057 1 $self->__cache_show_str(types => 0, "");
2058 }
2059 1 ▶ if ($cache->{bptr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->{"bptr"}) 0 1 1
2060 0 $self->__cache_show_str(bptr => length($cache->{bptr}), $cache->{bptr});
2061 }
2062 1 ▶ if ($cache->{tmp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->{"tmp"}) 1 0 1
2063 1 $self->__cache_show_str(tmp => length($cache->{tmp}), $cache->{tmp});
2064 }
2065 }
2066  
2067 31 ▶sub __cache_show_byte {
Subroutine __cache_show_byte: called CC=3 SCAR=11.0
2068 31 my ($self, $key, $value) = @_;
2069 31 ▶ warn(sprintf " %-21s %02x:%3d\n", $key, defined $value ? ord($value) : 0, defined $value ? $value : 0);
Branch: 2 branches
BranchTrueFalseTotal
defined $value ? : 25 6 31
defined $value ? : 25 6 31
2070 }
2071  
2072 3 ▶sub __cache_show_char {
Subroutine __cache_show_char: called CC=3 SCAR=11.2
2073 3 my ($self, $key, $value) = @_;
2074 3 my $v = $value;
2075 3 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 3 0 3
2076 3 my @b = unpack "U0C*", $value;
2077 3 $v = pack "U*", $b[0];
2078 }
2079 3 ▶ warn(sprintf " %-21s %02x:%s\n", $key, defined $v ? ord($v) : 0, $self->__pretty_str($v, 1));
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 3 0 3
2080 }
2081  
2082 5 ▶sub __cache_show_str {
Subroutine __cache_show_str: called CC=1 SCAR=0.0
2083 5 my ($self, $key, $len, $value) = @_;
2084 5 warn(sprintf " %-21s %02d:%s\n", $key, $len, $self->__pretty_str($value, $len));
2085 }
2086  
2087 8 ▶sub __pretty_str { # FIXME
Subroutine __pretty_str: called CC=2 SCAR=7.1
2088 8 my ($self, $str, $len) = @_;
2089 8 ▶ return '' unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 8 8
2090 8 $str = substr($str, 0, $len);
2091 8 $str =~ s/"/\\"/g;
2092 0 $str =~ s/([^\x09\x20-\x7e])/sprintf '\\x{%x}', ord($1)/eg;
2093 8 qq{"$str"};
2094 }
2095  
2096 20453 ▶sub _hook {
Subroutine _hook: called CC=7 SCAR=19.6
2097 20453 my ($self, $name, $fields) = @_;
2098 20453 ▶ return 0 unless $self->{callbacks};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"callbacks"} 20235 218 20453
2099  
2100 218 my $cb = $self->{callbacks}{$name};
2101 218 ▶ return 0 unless $cb && ref $cb eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb and ref $cb eq "CODE" 66 152 218
Condition66%2/3
$cb and ref $cb eq "CODE"
!ll&&!rl&&r
660152
MC/DC50%1/2
$cb and ref $cb eq "CODE"
$cb ref $cb eq "CODE"
Truth table66%2/3
A and B
A= $cbB= ref $cb eq "CODE"
ABresult
0X0
100
111
2102  
2103 152 my (@res) = $cb->($self, $fields);
2104 152 ▶ if (@res) {
Branch: 1 branch
BranchTrueFalseTotal
if (@res) 152 0 152
2105 152 ▶ return 0 if ref $res[0] eq 'SCALAR' and ${$res[0]} eq "skip";
Branch: 1 branch
BranchTrueFalseTotal
if ref $res[0] eq "SCALAR" and ${$res[0];} eq "skip" 64 88 152
Condition66%2/3
ref $res[0] eq "SCALAR" and ${$res[0];} eq "skip"
!ll&&!rl&&r
88064
MC/DC50%1/2
ref $res[0] eq "SCALAR" and ${$res[0];} eq "skip"
ref $res[0] eq "SCALAR" ${$res[0];} eq "skip"
Truth table66%2/3
A and B
A= ref $res[0] eq "SCALAR"B= ${$res[0];} eq "skip"
ABresult
0X0
100
111
2106 }
2107 88 scalar @res;
2108 }
2109  
2110 ################################################################################
2111 # methods for combine
2112 ################################################################################
2113  
2114 21708 ▶sub __combine {
Subroutine __combine: called CC=50 SCAR=39.2
2115 21708 my ($self, $dst, $fields, $useIO) = @_;
2116  
2117 21708 my $ctx = $self->_setup_ctx;
2118  
2119 21708 my ($binary, $quot, $sep, $esc, $quote_space) = @{$ctx}{qw/binary quo sep escape_char quote_space/};
2120  
2121 21708 ▶ if (!defined $quot or $quot eq "\0") { $quot = ''; }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $quot or $quot eq "\0") 2 21706 21708
Condition100%3/3
not defined $quot or $quot eq "\0"
l!l&&r!l&&!r
1121706
MC/DC100%2/2
not defined $quot or $quot eq "\0"
not defined $quot $quot eq "\0"
Truth table100%3/3
not(A) or B
A= not defined $quotB= $quot eq "\0"
ABresult
1X1
011
000
2122  
2123 21708 my $re_esc;
2124 21708 ▶ if ($esc ne '' and $esc ne "\0") {
Branch: 1 branch
BranchTrueFalseTotal
if ($esc ne "" and $esc ne "\0") 21706 2 21708
Condition66%2/3
$esc ne "" and $esc ne "\0"
!ll&&!rl&&r
0221706
MC/DC50%1/2
$esc ne "" and $esc ne "\0"
$esc ne "" $esc ne "\0"
Truth table66%2/3
A and B
A= $esc ne ""B= $esc ne "\0"
ABresult
0X0
100
111
2125 21706 ▶ if ($quot ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($quot ne '') { } 21704 2 21706
2126 21704 ▶ $re_esc = $self->{_re_comb_escape}->{$quot}->{$esc} ||= qr/(\Q$quot\E|\Q$esc\E)/;
Condition100%2/2
$self->{"_re_comb_escape"}{$quot}{$esc} ||= qr/(\Q$quot\E|\Q$esc\E)/
l!l
21505199
MC/DC100%1/1
$self->{"_re_comb_escape"}{$quot}{$esc} ||= qr/(\Q$quot\E|\Q$esc\E)/
$self->{"_re_comb_escape"}{$quot}{$esc}
Truth table100%2/2
A
A= $self->{"_re_comb_escape"}{$quot}{$esc}
Aresult
11
00
2127 } else {
2128 2 ▶ $re_esc = $self->{_re_comb_escape}->{$quot}->{$esc} ||= qr/(\Q$esc\E)/;
Condition50%1/2
$self->{"_re_comb_escape"}{$quot}{$esc} ||= qr/(\Q$esc\E)/
l!l
02
MC/DC0%0/1
$self->{"_re_comb_escape"}{$quot}{$esc} ||= qr/(\Q$esc\E)/
$self->{"_re_comb_escape"}{$quot}{$esc}
Truth table50%1/2
A
A= $self->{"_re_comb_escape"}{$quot}{$esc}
Aresult
11
00
2129 }
2130 }
2131  
2132 21708 my $bound = 0;
2133 21708 my $n = @$fields - 1;
2134 21708 ▶ if ($n < 0 and $ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0 and $ctx->{"is_bound"}) 5 21703 21708
Condition100%3/3
$n < 0 and $ctx->{"is_bound"}
!ll&&!rl&&r
2170215
MC/DC100%2/2
$n < 0 and $ctx->{"is_bound"}
$n < 0 $ctx->{"is_bound"}
Truth table100%3/3
A and B
A= $n < 0B= $ctx->{"is_bound"}
ABresult
0X0
100
111
2135 5 $n = $ctx->{is_bound} - 1;
2136 5 $bound = 1;
2137 }
2138  
2139 21708 ▶ my $check_meta = ($ctx->{keep_meta_info} >= 10 and @{$self->{_FFLAGS} || []} >= $n) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'keep_meta_info'} >= 10 && @{$self->{'_FFLAGS'} or [];} >= $n ? : 2 21706 21708
Condition60%3/5
$ctx->{"keep_meta_info"} >= 10 and @{$self->{"_FFLAGS"} or [];} >= $n
!ll&&!rl&&r
2170602
$self->{'_FFLAGS'} || []
l!l
20
MC/DC50%1/2
$ctx->{"keep_meta_info"} >= 10 and @{$self->{"_FFLAGS"} or [];} >= $n
$ctx->{"keep_meta_info"} >= 10 @{$self->{"_FFLAGS"} or [];} >= $n
MC/DC0%0/1
$self->{'_FFLAGS'} || []
$self->{'_FFLAGS'}
Truth table66%2/3
A and B
A= $ctx->{"keep_meta_info"} >= 10B= @{$self->{"_FFLAGS"} or [];} >= $n
ABresult
0X0
100
111
Truth table50%1/2
A
A= $self->{'_FFLAGS'}
Aresult
11
00
2140  
2141 21708 my $must_be_quoted;
2142 my @results;
2143 21708 ▶ for (my $i = 0; $i <= $n; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $n) 54005 21697 75702
2144 54005 my $v_ref;
2145 54005 ▶ if ($bound) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bound) { } 14 53991 54005
2146 14 $v_ref = $self->__bound_field($ctx, $i, 1);
2147 } else {
2148 53991 ▶ if (@$fields > $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$fields > $i) 53991 0 53991
2149 53991 $v_ref = \($fields->[$i]);
2150 }
2151 }
2152 54005 ▶ next unless $v_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $v_ref 0 54005 54005
2153  
2154 54005 my $value = $$v_ref;
2155  
2156 54005 ▶ if (!defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 56 53949 54005
2157 56 ▶ if ($ctx->{undef_str}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'undef_str'}) { } 8 48 56
2158 8 ▶ if ($ctx->{undef_flg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"undef_flg"}) 3 5 8
2159 3 $ctx->{utf8} = 1;
2160 3 $ctx->{binary} = 1;
2161 }
2162 8 push @results, $ctx->{undef_str};
2163 } else {
2164 48 push @results, '';
2165 }
2166 56 next;
2167 }
2168  
2169 53949 ▶ if (substr($value, 0, 1) eq '=' && $ctx->{formula}) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($value, 0, 1) eq "=" and $ctx->{"formula"}) 10 53939 53949
Condition100%3/3
substr($value, 0, 1) eq "=" and $ctx->{"formula"}
!ll&&!rl&&r
53933610
MC/DC100%2/2
substr($value, 0, 1) eq "=" and $ctx->{"formula"}
substr($value, 0, 1) eq "=" $ctx->{"formula"}
Truth table100%3/3
A and B
A= substr($value, 0, 1) eq "="B= $ctx->{"formula"}
ABresult
0X0
100
111
2170 10 $value = $self->_formula($ctx, $value, $i);
2171 6 ▶ if (!defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 2 4 6
2172 2 push @results, '';
2173 2 next;
2174 }
2175 }
2176  
2177 53943 ▶ $must_be_quoted = $ctx->{always_quote} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'always_quote'} ? : 6282 47661 53943
2178 53943 ▶ if ($value eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq '') { } 1414 52529 53943
2179 1414 ▶ $must_be_quoted++ if $ctx->{quote_empty} or ($check_meta && $self->is_quoted($i));
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"quote_empty"} or $check_meta and $self->is_quoted($i) 6 1408 1414
Condition100%6/6
$ctx->{"quote_empty"} or $check_meta and $self->is_quoted($i)
l!l&&r!l&&!r
421408
$check_meta and $self->is_quoted($i)
!ll&&!rl&&r
140532
MC/DC100%3/3
$ctx->{"quote_empty"} or $check_meta and $self->is_quoted($i)
$ctx->{"quote_empty"} $check_meta $self->is_quoted($i)
Truth table100%4/4
A or B and C
A= $ctx->{"quote_empty"}B= $check_metaC= $self->is_quoted($i)
ABCresult
1XX1
0111
00X0
0100
2180 }
2181 else {
2182  
2183 52529 ▶ if (utf8::is_utf8 $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($value)) 20041 32488 52529
2184 20041 $ctx->{utf8} = 1;
2185 20041 $ctx->{binary} = 1;
2186 }
2187  
2188 52529 ▶ $must_be_quoted++ if $check_meta && $self->is_quoted($i);
Branch: 1 branch
BranchTrueFalseTotal
if $check_meta and $self->is_quoted($i) 5 52524 52529
Condition100%3/3
$check_meta and $self->is_quoted($i)
!ll&&!rl&&r
5251775
MC/DC100%2/2
$check_meta and $self->is_quoted($i)
$check_meta $self->is_quoted($i)
Truth table100%3/3
A and B
A= $check_metaB= $self->is_quoted($i)
ABresult
0X0
100
111
2189  
2190 52529 ▶ if (!$must_be_quoted and $quot ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $must_be_quoted and $quot ne "") 46887 5642 52529
Condition100%3/3
not $must_be_quoted and $quot ne ""
!ll&&!rl&&r
5636646887
MC/DC100%2/2
not $must_be_quoted and $quot ne ""
not $must_be_quoted $quot ne ""
Truth table100%3/3
not(A) and B
A= not $must_be_quotedB= $quot ne ""
ABresult
0X0
100
111
2191 39 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
2192 $must_be_quoted++ if
2193 ($value =~ /\Q$quot\E/) ||
2194 ($sep ne '' and $sep ne "\0" and $value =~ /\Q$sep\E/) ||
2195 ($esc ne '' and $esc ne "\0" and $value =~ /\Q$esc\E/) ||
2196 ($ctx->{quote_binary} && $value =~ /[\x00-\x1f\x7f-\xa0]/) ||
2197 46887 ▶ ($ctx->{quote_space} && $value =~ /[\x09\x20]/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\Q$quot\E/ or $sep ne "" and $sep ne "\0" and $value =~ /\Q$sep\E/ or $esc ne "" and $esc ne "\0" and $value =~ /\Q$esc\E/ or $ctx->{"quote_binary"} and $value =~ /[\x00-\x1f\x7f-\xa0]/ or $ctx->{"quote_space"} and $value =~ /[\x09\x20]/ 23163 23724 46887
Condition93%28/30
$value =~ /\Q$quot\E/ or $sep ne "" and $sep ne "\0" and $value =~ /\Q$sep\E/ or $esc ne "" and $esc ne "\0" and $value =~ /\Q$esc\E/ or $ctx->{"quote_binary"} and $value =~ /[\x00-\x1f\x7f-\xa0]/ or $ctx->{"quote_space"} and $value =~ /[\x09\x20]/
l!l&&r!l&&!r
21926123723724
$value =~ /\Q$quot\E/ or $sep ne "" and $sep ne "\0" and $value =~ /\Q$sep\E/ or $esc ne "" and $esc ne "\0" and $value =~ /\Q$esc\E/ or $ctx->{"quote_binary"} and $value =~ /[\x00-\x1f\x7f-\xa0]/
l!l&&r!l&&!r
16022032424961
$value =~ /\Q$quot\E/ or $sep ne "" and $sep ne "\0" and $value =~ /\Q$sep\E/ or $esc ne "" and $esc ne "\0" and $value =~ /\Q$esc\E/
l!l&&r!l&&!r
128232045285
$value =~ /\Q$quot\E/ or $sep ne "" and $sep ne "\0" and $value =~ /\Q$sep\E/
l!l&&r!l&&!r
95732545605
$sep ne "" and $sep ne "\0" and $value =~ /\Q$sep\E/
!ll&&!rl&&r
76244843325
$sep ne "" and $sep ne "\0"
!ll&&!rl&&r
076245168
$esc ne "" and $esc ne "\0" and $value =~ /\Q$esc\E/
!ll&&!rl&&r
245283320
$esc ne "" and $esc ne "\0"
!ll&&!rl&&r
0245603
$ctx->{"quote_binary"} and $value =~ /[\x00-\x1f\x7f-\xa0]/
!ll&&!rl&&r
62495520324
$ctx->{"quote_space"} and $value =~ /[\x09\x20]/
!ll&&!rl&&r
122236021237
MC/DC72%8/11
$value =~ /\Q$quot\E/ or $sep ne "" and $sep ne "\0" and $value =~ /\Q$sep\E/ or $esc ne "" and $esc ne "\0" and $value =~ /\Q$esc\E/ or $ctx->{"quote_binary"} and $value =~ /[\x00-\x1f\x7f-\xa0]/ or $ctx->{"quote_space"} and $value =~ /[\x09\x20]/
$value =~ /\Q$quot\E/ $sep ne "" $sep ne "\0" $value =~ /\Q$sep\E/ $esc ne "" $esc ne "\0" $value =~ /\Q$esc\E/ $ctx->{"quote_binary"} $value =~ /[\x00-\x1f\x7f-\xa0]/ $ctx->{"quote_space"} $value =~ /[\x09\x20]/
Truth table20%14/68
A or B and C and D or E and F and G or H and I or J and K
A= $value =~ /\Q$quot\E/B= $sep ne ""C= $sep ne "\0"D= $value =~ /\Q$sep\E/E= $esc ne ""F= $esc ne "\0"G= $value =~ /\Q$esc\E/H= $ctx->{"quote_binary"}I= $value =~ /[\x00-\x1f\x7f-\xa0]/J= $ctx->{"quote_space"}K= $value =~ /[\x09\x20]/
ABCDEFGHIJKresult
1XXXXXXXXXX1
0111XXXXXXX1
00XX111XXXX1
010X111XXXX1
0110111XXXX1
00XX0XX11XX1
00XX10X11XX1
00XX11011XX1
010X0XX11XX1
010X10X11XX1
010X11011XX1
01100XX11XX1
011010X11XX1
011011011XX1
00XX0XX0X111
00XX0XX10111
00XX10X0X111
00XX10X10111
00XX1100X111
00XX11010111
010X0XX0X111
010X0XX10111
010X10X0X111
010X10X10111
010X1100X111
010X11010111
01100XX0X111
01100XX10111
011010X0X111
011010X10111
01101100X111
011011010111
00XX0XX0X0X0
00XX0XX0X100
00XX0XX100X0
00XX0XX10100
00XX10X0X0X0
00XX10X0X100
00XX10X100X0
00XX10X10100
00XX1100X0X0
00XX1100X100
00XX110100X0
00XX11010100
010X0XX0X0X0
010X0XX0X100
010X0XX100X0
010X0XX10100
010X10X0X0X0
010X10X0X100
010X10X100X0
010X10X10100
010X1100X0X0
010X1100X100
010X110100X0
010X11010100
01100XX0X0X0
01100XX0X100
01100XX100X0
01100XX10100
011010X0X0X0
011010X0X100
011010X100X0
011010X10100
01101100X0X0
01101100X100
0110110100X0
011011010100
2198 }
2199  
2200 52529 ▶ if (!$ctx->{binary} and $value =~ /[^\x09\x20-\x7E]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ctx->{"binary"} and $value =~ /[^\x09\x20-\x7E]/) 7 52522 52529
Condition100%3/3
not $ctx->{"binary"} and $value =~ /[^\x09\x20-\x7E]/
!ll&&!rl&&r
521273957
MC/DC100%2/2
not $ctx->{"binary"} and $value =~ /[^\x09\x20-\x7E]/
not $ctx->{"binary"} $value =~ /[^\x09\x20-\x7E]/
Truth table100%3/3
not(A) and B
A= not $ctx->{"binary"}B= $value =~ /[^\x09\x20-\x7E]/
ABresult
0X0
100
111
2201 # an argument contained an invalid character...
2202 7 $self->{_ERROR_INPUT} = $value;
2203 7 $self->SetDiag(2110);
2204 7 return 0;
2205 }
2206  
2207 52522 ▶ if ($re_esc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_esc) 52520 2 52522
2208 52520 $value =~ s/($re_esc)/$esc$1/g;
2209 }
2210 52522 ▶ if ($ctx->{escape_null}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"escape_null"}) 52308 214 52522
2211 52308 $value =~ s/\0/${esc}0/g;
2212 }
2213 }
2214  
2215 53936 ▶ if ($must_be_quoted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($must_be_quoted) 29448 24488 53936
2216 29448 $value = $quot . $value . $quot;
2217 }
2218 53936 push @results, $value;
2219 }
2220  
2221 21697 ▶ $$dst = join($sep, @results) . (defined $ctx->{eol} ? $ctx->{eol} : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $ctx->{'eol'} ? : 21691 6 21697
2222  
2223 21697 return 1;
2224 }
2225  
2226 37 ▶sub _formula {
Subroutine _formula: called CC=13 SCAR=25.9
2227 37 my ($self, $ctx, $value, $i) = @_;
2228  
2229 37 ▶ my $fa = $ctx->{formula} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fa = $ctx->{"formula"} or return 37 0 37
2230 37 ▶ if ($fa == 1) { die "Formulas are forbidden\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($fa == 1) 3 34 37
2231 34 ▶ if ($fa == 2) { die "Formulas are forbidden\n" } # XS croak behaves like PP's "die"
Branch: 1 branch
BranchTrueFalseTotal
if ($fa == 2) 3 31 34
2232  
2233 31 ▶ if ($fa == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fa == 3) 6 25 31
2234 6 my $rec = '';
2235 6 ▶ if ($ctx->{recno}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"recno"}) 3 3 6
2236 3 $rec = sprintf " in record %lu", $ctx->{recno} + 1;
2237 }
2238 6 my $field = '';
2239 6 my $column_names = $self->{_COLUMN_NAMES};
2240 6 ▶ if (ref $column_names eq 'ARRAY' and @$column_names >= $i - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $column_names eq "ARRAY" and @$column_names >= $i - 1) 1 5 6
Condition66%2/3
ref $column_names eq "ARRAY" and @$column_names >= $i - 1
!ll&&!rl&&r
501
MC/DC50%1/2
ref $column_names eq "ARRAY" and @$column_names >= $i - 1
ref $column_names eq "ARRAY" @$column_names >= $i - 1
Truth table66%2/3
A and B
A= ref $column_names eq "ARRAY"B= @$column_names >= $i - 1
ABresult
0X0
100
111
2241 1 my $column_name = $column_names->[$i - 1];
2242 1 ▶ $field = sprintf " (column: '%.100s')", $column_name if defined $column_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $column_name 1 0 1
2243 }
2244 6 warn sprintf("Field %d%s%s contains formula '%s'\n", $i, $field, $rec, $value);
2245 6 return $value;
2246 }
2247  
2248 25 ▶ if ($fa == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fa == 4) 5 20 25
2249 5 return '';
2250 }
2251 20 ▶ if ($fa == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fa == 5) 5 15 20
2252 5 return undef;
2253 }
2254  
2255 15 ▶ if ($fa == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fa == 6) 15 0 15
2256 15 ▶ if (ref $self->{_FORMULA_CB} eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"_FORMULA_CB"} eq "CODE") 15 0 15
2257 15 local $_ = $value;
2258 15 return $self->{_FORMULA_CB}->();
2259 }
2260 }
2261 0 return;
2262 }
2263  
2264 20315 ▶sub print {
Subroutine print: called CC=5 SCAR=16.1
Pod documented
2265 20315 my ($self, $io, $fields) = @_;
2266  
2267 20315 require IO::Handle;
2268  
2269 20315 ▶ if (!defined $fields) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $fields) { } 5 20310 20315
elsif (ref $fields ne 'ARRAY') { } 5 20305 20310
2270 5 $fields = [];
2271 } elsif (ref($fields) ne 'ARRAY') {
2272 5 Carp::croak("Expected fields to be an array ref");
2273 }
2274  
2275 20310 $self->_hook(before_print => $fields);
2276  
2277 20310 my $str = "";
2278 20310 ▶ $self->__combine(\$str, $fields, 1) or return '';
Branch: 1 branch
BranchTrueFalseTotal
$self->__combine(\$str, $fields, 1) or return "" 20304 6 20310
2279  
2280 20304 local $\ = '';
2281  
2282 20304 ▶ $io->print($str) or $self->_set_error_diag(2200);
Branch: 1 branch
BranchTrueFalseTotal
$io->print($str) or $self->_set_error_diag(2200) 20303 1 20304
2283 }
2284  
2285 ################################################################################
2286 # methods for parse
2287 ################################################################################
2288  
2289 3910 ▶sub __parse { # cx_xsParse
Subroutine __parse: called CC=5 SCAR=16.1
2290 3910 my ($self, $fields, $fflags, $src, $useIO) = @_;
2291  
2292 3910 my $ctx = $self->_setup_ctx;
2293  
2294 3910 my $state = $self->___parse($ctx, $fields, $fflags, $src, $useIO);
2295 3905 ▶ if ($state and ($ctx->{has_hooks} || 0) & HOOK_AFTER_PARSE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state and ($ctx->{"has_hooks"} || 0) & 2) 5 3900 3905
Condition100%5/5
$state and ($ctx->{"has_hooks"} || 0) & 2
!ll&&!rl&&r
38235185
$ctx->{'has_hooks'} || 0
l!l
53518
MC/DC100%2/2
$state and ($ctx->{"has_hooks"} || 0) & 2
$state $ctx->{'has_hooks'}
Truth table100%3/3
A and B
A= $stateB= $ctx->{'has_hooks'}
ABresult
0X0
100
111
2296 5 $self->_hook(after_parse => $fields);
2297 }
2298 3905 ▶ return $state || !$last_error;
Condition100%3/3
$state || !$last_error
l!l&&r!l&&!r
35232380
MC/DC100%2/2
$state || !$last_error
$state !$last_error
Truth table100%3/3
A || not(B)
A= $stateB= !$last_error
ABresult
1X1
011
000
2299 }
2300  
2301 5032 ▶sub ___parse { # cx_c_xsParse
Subroutine ___parse: called CC=32 SCAR=34.7
2302 5032 my ($self, $ctx, $fields, $fflags, $src, $useIO) = @_;
2303  
2304 5032 ▶ local $/ = $ctx->{eol} if $ctx->{eolx} or $ctx->{eol_is_cr};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"eolx"} or $ctx->{"eol_is_cr"} 916 4116 5032
Condition100%3/3
$ctx->{"eolx"} or $ctx->{"eol_is_cr"}
l!l&&r!l&&!r
4274894116
MC/DC100%2/2
$ctx->{"eolx"} or $ctx->{"eol_is_cr"}
$ctx->{"eolx"} $ctx->{"eol_is_cr"}
Truth table100%3/3
A or B
A= $ctx->{"eolx"}B= $ctx->{"eol_is_cr"}
ABresult
1X1
011
000
2305  
2306 5032 ▶ if ($ctx->{useIO} = $useIO) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'useIO'} = $useIO) { } 3080 1952 5032
2307 3080 require IO::Handle;
2308  
2309 3080 $ctx->{tmp} = undef;
2310 3080 ▶ if ($ctx->{has_ahead} and defined $self->{_AHEAD}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"has_ahead"} and defined $self->{"_AHEAD"}) 231 2849 3080
Condition66%2/3
$ctx->{"has_ahead"} and defined $self->{"_AHEAD"}
!ll&&!rl&&r
28490231
MC/DC50%1/2
$ctx->{"has_ahead"} and defined $self->{"_AHEAD"}
$ctx->{"has_ahead"} defined $self->{"_AHEAD"}
Truth table66%2/3
A and B
A= $ctx->{"has_ahead"}B= defined $self->{"_AHEAD"}
ABresult
0X0
100
111
2311 231 $ctx->{tmp} = $self->{_AHEAD};
2312 231 $ctx->{size} = length $ctx->{tmp};
2313 231 $ctx->{used} = 0;
2314 }
2315 } else {
2316 1952 $ctx->{tmp} = $src;
2317 1952 $ctx->{size} = length $src;
2318 1952 $ctx->{used} = 0;
2319 1952 $ctx->{utf8} = utf8::is_utf8($src);
2320 }
2321 5032 ▶ if ($ctx->{has_error_input}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"has_error_input"}) 0 5032 5032
2322 0 $self->{_ERROR_INPUT} = undef;
2323 0 $ctx->{has_error_input} = 0;
2324 }
2325  
2326 5032 my $result = $self->____parse($ctx, $src, $fields, $fflags);
2327 5021 $self->{_RECNO} = ++($ctx->{recno});
2328 5021 $self->{_EOF} = '';
2329  
2330 5021 ▶ if ($ctx->{strict}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict"}) 60 4961 5021
2331 60 ▶ my $nf = $ctx->{is_bound} ? $ctx->{fld_idx} : @$fields;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'is_bound'} ? : 11 49 60
2332 60 ▶ if ($nf and !$ctx->{strict_n}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nf and not $ctx->{"strict_n"}) 20 40 60
Condition100%3/3
$nf and not $ctx->{"strict_n"}
!ll&&!rl&&r
83220
MC/DC100%2/2
$nf and not $ctx->{"strict_n"}
$nf not $ctx->{"strict_n"}
Truth table100%3/3
A and not(B)
A= $nfB= not $ctx->{"strict_n"}
ABresult
0X0
100
111
2333 20 $ctx->{strict_n} = $nf;
2334 }
2335 60 ▶ if ($ctx->{strict_n} > 0 and $nf != $ctx->{strict_n}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict_n"} > 0 and $nf != $ctx->{"strict_n"}) 25 35 60
Condition66%2/3
$ctx->{"strict_n"} > 0 and $nf != $ctx->{"strict_n"}
!ll&&!rl&&r
03525
MC/DC50%1/2
$ctx->{"strict_n"} > 0 and $nf != $ctx->{"strict_n"}
$ctx->{"strict_n"} > 0 $nf != $ctx->{"strict_n"}
Truth table66%2/3
A and B
A= $ctx->{"strict_n"} > 0B= $nf != $ctx->{"strict_n"}
ABresult
0X0
100
111
2336 25 ▶ unless ($ctx->{useIO} & useIO_EOF) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"useIO"} & 16) 18 7 25
2337 18 ▶ unless ($last_error || (!$ctx->{useIO} and $ctx->{has_ahead})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($last_error or not $ctx->{"useIO"} and $ctx->{"has_ahead"}) 16 2 18
Condition100%6/6
$last_error or not $ctx->{"useIO"} and $ctx->{"has_ahead"}
l!l&&r!l&&!r
1116
not $ctx->{"useIO"} and $ctx->{"has_ahead"}
!ll&&!rl&&r
1241
MC/DC100%3/3
$last_error or not $ctx->{"useIO"} and $ctx->{"has_ahead"}
$last_error not $ctx->{"useIO"} $ctx->{"has_ahead"}
Truth table100%4/4
A or not(B) and C
A= $last_errorB= not $ctx->{"useIO"}C= $ctx->{"has_ahead"}
ABCresult
1XX1
0111
00X0
0100
2338 16 $self->__parse_error($ctx, 2014, $ctx->{used});
2339 }
2340 }
2341 25 ▶ if ($last_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_error) 20 5 25
2342 20 $result = undef;
2343 }
2344 }
2345 }
2346  
2347 5021 ▶ if ($ctx->{useIO}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'useIO'}) { } 3072 1949 5021
2348 3072 ▶ if (defined $ctx->{tmp} and $ctx->{used} < $ctx->{size} and $ctx->{has_ahead}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ctx->{'tmp'} and $ctx->{'used'} < $ctx->{'size'} and $ctx->{'has_ahead'}) { } 94 2978 3072
Condition83%5/6
defined $ctx->{"tmp"} and $ctx->{"used"} < $ctx->{"size"} and $ctx->{"has_ahead"}
!ll&&!rl&&r
29017794
defined $ctx->{"tmp"} and $ctx->{"used"} < $ctx->{"size"}
!ll&&!rl&&r
02901171
MC/DC66%2/3
defined $ctx->{"tmp"} and $ctx->{"used"} < $ctx->{"size"} and $ctx->{"has_ahead"}
defined $ctx->{"tmp"} $ctx->{"used"} < $ctx->{"size"} $ctx->{"has_ahead"}
Truth table75%3/4
A and B and C
A= defined $ctx->{"tmp"}B= $ctx->{"used"} < $ctx->{"size"}C= $ctx->{"has_ahead"}
ABCresult
0XX0
10X0
1100
1111
2349 94 $self->{_AHEAD} = substr($ctx->{tmp}, $ctx->{used}, $ctx->{size} - $ctx->{used});
2350 } else {
2351 2978 $ctx->{has_ahead} = 0;
2352 2978 ▶ if ($ctx->{useIO} & useIO_EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"useIO"} & 16) 582 2396 2978
2353 582 $self->{_EOF} = 1;
2354 }
2355 }
2356 3072 %{$self->{_CACHE}} = %$ctx;
2357  
2358 3072 ▶ if ($fflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fflags) 1956 1116 3072
2359 1956 ▶ if ($ctx->{keep_meta_info}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'keep_meta_info'}) { } 11 1945 1956
2360 11 $self->{_FFLAGS} = $fflags;
2361 } else {
2362 1945 undef $fflags;
2363 }
2364 }
2365 } else {
2366 1949 %{$self->{_CACHE}} = %$ctx;
2367 }
2368  
2369 5021 ▶ if ($result and $ctx->{types}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result and $ctx->{"types"}) 2 5019 5021
Condition100%3/3
$result and $ctx->{"types"}
!ll&&!rl&&r
70243172
MC/DC100%2/2
$result and $ctx->{"types"}
$result $ctx->{"types"}
Truth table100%3/3
A and B
A= $resultB= $ctx->{"types"}
ABresult
0X0
100
111
2370 2 my $len = @$fields;
2371 2 ▶ for (my $i = 0; $i <= $len && $i <= $ctx->{types_len}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $len and $i <= $ctx->{"types_len"}) 8 2 10
Condition66%2/3
$i <= $len and $i <= $ctx->{"types_len"}
!ll&&!rl&&r
208
MC/DC50%1/2
$i <= $len and $i <= $ctx->{"types_len"}
$i <= $len $i <= $ctx->{"types_len"}
Truth table66%2/3
A and B
A= $i <= $lenB= $i <= $ctx->{"types_len"}
ABresult
0X0
100
111
2372 8 my $value = $fields->[$i];
2373 8 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 6 8
2374 6 my $type = ord(substr($ctx->{types}, $i, 1));
2375 6 ▶ if ($type == IV) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == IV()) { } 2 4 6
elsif ($type == NV()) { } 2 2 4
2376 2 $fields->[$i] = int($value);
2377 } elsif ($type == NV) {
2378 2 $fields->[$i] = $value + 0.0;
2379 }
2380 }
2381 }
2382  
2383 5021 $result;
2384 }
2385  
2386 5036 ▶sub ____parse { # cx_Parse
Subroutine ____parse: called CC=304 SCAR=70.3
2387 5036 my ($self, $ctx, $src, $fields, $fflags) = @_;
2388  
2389 5036 my ($quot, $sep, $esc, $eol) = @{$ctx}{qw/quo sep escape_char eol/};
2390  
2391 5036 ▶ utf8::encode($sep) if !$ctx->{utf8} and $ctx->{sep_len};
Branch: 1 branch
BranchTrueFalseTotal
if not $ctx->{"utf8"} and $ctx->{"sep_len"} 30 5006 5036
Condition100%3/3
not $ctx->{"utf8"} and $ctx->{"sep_len"}
!ll&&!rl&&r
22498430
MC/DC100%2/2
not $ctx->{"utf8"} and $ctx->{"sep_len"}
not $ctx->{"utf8"} $ctx->{"sep_len"}
Truth table100%3/3
not(A) and B
A= not $ctx->{"utf8"}B= $ctx->{"sep_len"}
ABresult
0X0
100
111
2392 5036 ▶ utf8::encode($quot) if !$ctx->{utf8} and $ctx->{quo_len};
Branch: 1 branch
BranchTrueFalseTotal
if not $ctx->{"utf8"} and $ctx->{"quo_len"} 18 5018 5036
Condition100%3/3
not $ctx->{"utf8"} and $ctx->{"quo_len"}
!ll&&!rl&&r
22499618
MC/DC100%2/2
not $ctx->{"utf8"} and $ctx->{"quo_len"}
not $ctx->{"utf8"} $ctx->{"quo_len"}
Truth table100%3/3
not(A) and B
A= not $ctx->{"utf8"}B= $ctx->{"quo_len"}
ABresult
0X0
100
111
2393 5036 ▶ utf8::encode($eol) if !$ctx->{utf8} and $ctx->{eol_len};
Branch: 1 branch
BranchTrueFalseTotal
if not $ctx->{"utf8"} and $ctx->{"eol_len"} 1123 3913 5036
Condition100%3/3
not $ctx->{"utf8"} and $ctx->{"eol_len"}
!ll&&!rl&&r
2238911123
MC/DC100%2/2
not $ctx->{"utf8"} and $ctx->{"eol_len"}
not $ctx->{"utf8"} $ctx->{"eol_len"}
Truth table100%3/3
not(A) and B
A= not $ctx->{"utf8"}B= $ctx->{"eol_len"}
ABresult
0X0
100
111
2394  
2395 5036 my $seenSomething = 0;
2396 5036 my $spl = -1;
2397 5036 my $waitingForField = 1;
2398 5036 my ($value, $v_ref, $c0);
2399 5036 $ctx->{fld_idx} = my $fnum = 0;
2400 5036 $ctx->{flag} = 0;
2401  
2402 5036 ▶ my $re_str = join '|', map({ $_ eq "\0" ? '[\\0]' : quotemeta($_) } sort { length $b <=> length $a } grep { defined $_ and $_ ne '' } $sep, $quot, $esc, $eol), "\015", "\012", "\x09", " ";
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "\000" ? : 227 15999 16226
Condition100%3/3
defined $_ && $_ ne ''
!ll&&!rl&&r
32388616226
MC/DC100%2/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
Truth table100%3/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
2403 5036 $ctx->{_re} = qr/$re_str/;
2404 5036 my $re = qr/$re_str|[^\x09\x20-\x7E]|$/;
2405  
2406 LOOP:
2407 5036 ▶ while ($self->__get_from_src($ctx, $src)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__get_from_src($ctx, $src)) 5130 463 5593
2408 5130 ▶ while ($ctx->{tmp} =~ /\G(.*?)($re)/gs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"tmp"} =~ /\G(.*?)($re)/gs) 76615 0 76615
2409 76615 my ($hit, $c) = ($1, $2);
2410 76615 $ctx->{used} = pos($ctx->{tmp});
2411 76615 ▶ if (!$waitingForField and $c eq '' and $hit ne '' and $ctx->{useIO} and !($ctx->{useIO} & useIO_EOF)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $waitingForField and $c eq "" and $hit ne "" and $ctx->{"useIO"} and not $ctx->{"useIO"} & 16) 147 76468 76615
Condition100%12/12
not $waitingForField and $c eq "" and $hit ne "" and $ctx->{"useIO"} and not $ctx->{"useIO"} & 16
!ll&&!rl&&r
76321147147
not $waitingForField and $c eq "" and $hit ne "" and $ctx->{"useIO"}
!ll&&!rl&&r
763138294
not $waitingForField and $c eq "" and $hit ne ""
!ll&&!rl&&r
75974339302
not $waitingForField and $c eq ""
!ll&&!rl&&r
2413351841641
MC/DC100%5/5
not $waitingForField and $c eq "" and $hit ne "" and $ctx->{"useIO"} and not $ctx->{"useIO"} & 16
not $waitingForField $c eq "" $hit ne "" $ctx->{"useIO"} not $ctx->{"useIO"} & 16
Truth table100%6/6
not(A) and B and C and D and not(E)
A= not $waitingForFieldB= $c eq ""C= $hit ne ""D= $ctx->{"useIO"}E= not $ctx->{"useIO"} & 16
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
2412 147 $self->{_AHEAD} = $hit;
2413 147 $ctx->{has_ahead} = 1;
2414 147 $ctx->{has_leftover} = 1;
2415 147 last;
2416 }
2417 76468 ▶ last if $seenSomething and $hit eq '' and $c eq ''; # EOF
Branch: 1 branch
BranchTrueFalseTotal
if $seenSomething and $hit eq "" and $c eq "" 371 76097 76468
Condition100%6/6
$seenSomething and $hit eq "" and $c eq ""
!ll&&!rl&&r
4915126946371
$seenSomething and $hit eq ""
!ll&&!rl&&r
46934445827317
MC/DC100%3/3
$seenSomething and $hit eq "" and $c eq ""
$seenSomething $hit eq "" $c eq ""
Truth table100%4/4
A and B and C
A= $seenSomethingB= $hit eq ""C= $c eq ""
ABCresult
0XX0
10X0
1100
1111
2418  
2419 # new field
2420 76097 ▶ if (!$v_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v_ref) 24070 52027 76097
2421 24070 ▶ if ($ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'is_bound'}) { } 152 23918 24070
2422 152 $v_ref = $self->__bound_field($ctx, $fnum, 0);
2423 } else {
2424 23918 $value = '';
2425 23918 $v_ref = \$value;
2426 }
2427 24070 $fnum++;
2428 24070 ▶ return unless $v_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $v_ref 4 24066 24070
2429 24066 $ctx->{flag} = 0;
2430 24066 $ctx->{fld_idx}++;
2431 24066 $c0 = '';
2432 }
2433  
2434 76093 $seenSomething = 1;
2435 76093 $spl++;
2436  
2437 76093 ▶ if (defined $hit and $hit ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hit and $hit ne "") 46993 29100 76093
Condition66%2/3
defined $hit and $hit ne ""
!ll&&!rl&&r
02910046993
MC/DC50%1/2
defined $hit and $hit ne ""
defined $hit $hit ne ""
Truth table66%2/3
A and B
A= defined $hitB= $hit ne ""
ABresult
0X0
100
111
2438 46993 ▶ if ($waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if ($waitingForField) 10901 36092 46993
2439 10901 ▶ if (!$spl && $ctx->{comment_str} && $ctx->{tmp} =~ /\A\Q$ctx->{comment_str}/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $spl and $ctx->{"comment_str"} and $ctx->{"tmp"} =~ /\A\Q$ctx->{"comment_str"}\E/) 29 10872 10901
Condition100%6/6
not $spl and $ctx->{"comment_str"} and $ctx->{"tmp"} =~ /\A\Q$ctx->{"comment_str"}\E/
!ll&&!rl&&r
108373529
not $spl and $ctx->{"comment_str"}
!ll&&!rl&&r
8394244364
MC/DC100%3/3
not $spl and $ctx->{"comment_str"} and $ctx->{"tmp"} =~ /\A\Q$ctx->{"comment_str"}\E/
not $spl $ctx->{"comment_str"} $ctx->{"tmp"} =~ /\A\Q$ctx->{"comment_str"}\E/
Truth table100%4/4
not(A) and B and C
A= not $splB= $ctx->{"comment_str"}C= $ctx->{"tmp"} =~ /\A\Q$ctx->{"comment_str"}\E/
ABCresult
0XX0
10X0
1100
1111
2440 29 $ctx->{used} = $ctx->{size};
2441 29 ▶ $ctx->{fld_idx} = $ctx->{strict_n} ? $ctx->{strict_n} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'strict_n'} ? : 6 23 29
2442 29 $seenSomething = 0;
2443 29 ▶ unless ($ctx->{useIO}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"useIO"}) 1 28 29
2444 1 $ctx->{has_ahead} = 214;
2445 }
2446 29 next LOOP;
2447 }
2448 10872 $waitingForField = 0;
2449 }
2450 46964 ▶ if ($hit =~ /[^\x09\x20-\x7E]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hit =~ /[^\x09\x20-\x7E]/) 0 46964 46964
2451 0 $ctx->{flag} |= IS_BINARY;
2452 }
2453 46964 $$v_ref .= $hit;
2454 }
2455  
2456 RESTART:
2457 76799 ▶ if (defined $c and defined $sep and $c eq $sep) {
Branch: 5 branches
BranchTrueFalseTotal
if (defined $c and defined $sep and $c eq $sep) { } 12548 64251 76799
elsif (defined $c and defined $quot and $quot ne "\000" and $c eq $quot) { } 23321 40930 64251
elsif (defined $c and defined $esc and $esc ne "\000" and $c eq $esc) { } 4655 36275 40930
elsif (defined $c and $c eq "\n" || $c eq '' || defined $eol && $c eq $eol && $eol ne "\r") { } 2702 33573 36275
elsif (defined $c and $c eq "\r" and not $ctx->{'verbatim'}) { } 1255 32318 33573
Condition83%5/6
defined $c and defined $sep and $c eq $sep
!ll&&!rl&&r
106424112548
defined $c and defined $sep
!ll&&!rl&&r
10076789
MC/DC66%2/3
defined $c and defined $sep and $c eq $sep
defined $c defined $sep $c eq $sep
Truth table75%3/4
A and B and C
A= defined $cB= defined $sepC= $c eq $sep
ABCresult
0XX0
10X0
1100
1111
2458 12548 ▶ if ($waitingForField) {
Branch: 2 branches
BranchTrueFalseTotal
if ($waitingForField) { } 1311 11237 12548
elsif ($ctx->{'flag'} & 1) { } 2195 9042 11237
2459 # ,1,"foo, 3",,bar,
2460 # ^ ^
2461 1311 ▶ if ($ctx->{blank_is_undef} or $ctx->{empty_is_undef}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'blank_is_undef'} or $ctx->{'empty_is_undef'}) { } 53 1258 1311
Condition100%3/3
$ctx->{"blank_is_undef"} or $ctx->{"empty_is_undef"}
l!l&&r!l&&!r
29241258
MC/DC100%2/2
$ctx->{"blank_is_undef"} or $ctx->{"empty_is_undef"}
$ctx->{"blank_is_undef"} $ctx->{"empty_is_undef"}
Truth table100%3/3
A or B
A= $ctx->{"blank_is_undef"}B= $ctx->{"empty_is_undef"}
ABresult
1X1
011
000
2462 53 $$v_ref = undef;
2463 } else {
2464 1258 $$v_ref = "";
2465 }
2466 1311 ▶ unless ($ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"is_bound"}) 1311 0 1311
2467 1311 push @$fields, $$v_ref;
2468 }
2469 1311 $v_ref = undef;
2470 1311 ▶ if ($ctx->{keep_meta_info} and $fflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"keep_meta_info"} and $fflags) 8 1303 1311
Condition66%2/3
$ctx->{"keep_meta_info"} and $fflags
!ll&&!rl&&r
130308
MC/DC50%1/2
$ctx->{"keep_meta_info"} and $fflags
$ctx->{"keep_meta_info"} $fflags
Truth table66%2/3
A and B
A= $ctx->{"keep_meta_info"}B= $fflags
ABresult
0X0
100
111
2471 8 push @$fflags, $ctx->{flag};
2472 }
2473 } elsif ($ctx->{flag} & IS_QUOTED) {
2474 # ,1,"foo, 3",,bar,
2475 # ^
2476 2195 $$v_ref .= $c;
2477 } else {
2478 # ,1,"foo, 3",,bar,
2479 # ^ ^ ^
2480 9042 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2481 9040 $v_ref = undef;
2482 9040 $waitingForField = 1;
2483 }
2484 }
2485 ▶ elsif (defined $c and defined $quot and $quot ne "\0" and $c eq $quot) {
Condition88%8/9
defined $c and defined $quot and $quot ne "\0" and $c eq $quot
!ll&&!rl&&r
1494078123321
defined $c and defined $quot and $quot ne "\0"
!ll&&!rl&&r
1013964102
defined $c and defined $quot
!ll&&!rl&&r
10064241
MC/DC75%3/4
defined $c and defined $quot and $quot ne "\0" and $c eq $quot
defined $c defined $quot $quot ne "\0" $c eq $quot
Truth table80%4/5
A and B and C and D
A= defined $cB= defined $quotC= $quot ne "\0"D= $c eq $quot
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2486 23321 ▶ if ($waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if ($waitingForField) 11127 12194 23321
2487 # ,1,"foo, 3",,bar,\r\n
2488 # ^
2489 11127 $ctx->{flag} |= IS_QUOTED;
2490 11127 $waitingForField = 0;
2491 11127 next;
2492 }
2493 12194 ▶ if ($ctx->{flag} & IS_QUOTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"flag"} & 1) 12126 68 12194
2494 # ,1,"foo, 3",,bar,\r\n
2495 # ^
2496 12126 my $quoesc = 0;
2497 12126 my $c2 = $self->__get($ctx, $src);
2498  
2499 12126 ▶ if ($ctx->{allow_whitespace}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"allow_whitespace"}) 4290 7836 12126
2500 # , 1 , "foo, 3" , , bar , \r\n
2501 # ^
2502 4290 ▶ while ($self->__is_whitespace($ctx, $c2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__is_whitespace($ctx, $c2)) 90 4290 4380
2503 90 ▶ if ($ctx->{allow_loose_quotes} and !(defined $esc and $c2 eq $esc)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"allow_loose_quotes"} and not defined $esc && $c2 eq $esc) 1 89 90
Condition50%3/6
$ctx->{"allow_loose_quotes"} and not defined $esc && $c2 eq $esc
!ll&&!rl&&r
8901
defined $esc && $c2 eq $esc
!ll&&!rl&&r
010
MC/DC33%1/3
$ctx->{"allow_loose_quotes"} and not defined $esc && $c2 eq $esc
$ctx->{"allow_loose_quotes"} defined $esc $c2 eq $esc
Truth table50%2/4
A and not(B && C)
A= $ctx->{"allow_loose_quotes"}B= defined $escC= $c2 eq $esc
ABCresult
0XX0
1110
10X1
1101
2504 1 $$v_ref .= $c;
2505 1 $c = $c2;
2506 }
2507 90 $c2 = $self->__get($ctx, $src);
2508 }
2509 }
2510  
2511 12126 ▶ if (!defined $c2) { # EOF
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c2) 1313 10813 12126
2512 # ,1,"foo, 3"
2513 # ^
2514 1313 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2515 1313 return 1;
2516 }
2517  
2518 10813 ▶ if (defined $c2 and defined $sep and $c2 eq $sep) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c2 and defined $sep and $c2 eq $sep) 9089 1724 10813
Condition50%3/6
defined $c2 and defined $sep and $c2 eq $sep
!ll&&!rl&&r
017249089
defined $c2 and defined $sep
!ll&&!rl&&r
0010813
MC/DC33%1/3
defined $c2 and defined $sep and $c2 eq $sep
defined $c2 defined $sep $c2 eq $sep
Truth table50%2/4
A and B and C
A= defined $c2B= defined $sepC= $c2 eq $sep
ABCresult
0XX0
10X0
1100
1111
2519 # ,1,"foo, 3",,bar,\r\n
2520 # ^
2521 9089 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2522 9089 $v_ref = undef;
2523 9089 $waitingForField = 1;
2524 9089 next;
2525 }
2526 1724 ▶ if (defined $c2 and ($c2 eq "\012" or (defined $eol and $c2 eq $eol))) { # FIXME: EOLX
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c2 and $c2 eq "\n" || defined $eol && $c2 eq $eol) 362 1362 1724
Condition88%8/9
defined $c2 and $c2 eq "\n" || defined $eol && $c2 eq $eol
!ll&&!rl&&r
01362362
$c2 eq "\n" or defined $eol and $c2 eq $eol
l!l&&r!l&&!r
2081541362
defined $eol and $c2 eq $eol
!ll&&!rl&&r
121350154
MC/DC75%3/4
defined $c2 and $c2 eq "\n" || defined $eol && $c2 eq $eol
defined $c2 $c2 eq "\n" defined $eol $c2 eq $eol
Truth table80%4/5
A and B or C and D
A= defined $c2B= $c2 eq "\n"C= defined $eolD= $c2 eq $eol
ABCDresult
0XXX0
100X0
10100
11XX1
10111
2527 # ,1,"foo, 3",,"bar"\n
2528 # ^
2529 362 my $eolt = _eol_type($c2);
2530 362 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type} and $ctx->{eol_type} != $eolt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != $eolt) 27 335 362
Condition100%6/6
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != $eolt
!ll&&!rl&&r
2686727
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
2491994
MC/DC100%3/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != $eolt
$ctx->{"strict_eol"} $ctx->{"eol_type"} $ctx->{"eol_type"} != $eolt
Truth table100%4/4
A and B and C
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}C= $ctx->{"eol_type"} != $eolt
ABCresult
0XX0
10X0
1100
1111
2531 27 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 25 2 27
2532 }
2533 360 $self->_set_eol_type($ctx, $eolt);
2534 360 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2535 360 return 1;
2536 }
2537  
2538 1362 ▶ if (defined $esc and $c eq $esc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $esc and $c eq $esc) 1341 21 1362
Condition100%3/3
defined $esc and $c eq $esc
!ll&&!rl&&r
8131341
MC/DC100%2/2
defined $esc and $c eq $esc
defined $esc $c eq $esc
Truth table100%3/3
A and B
A= defined $escB= $c eq $esc
ABresult
0X0
100
111
2539 1341 $quoesc = 1;
2540 1341 ▶ if (defined $c2 and $c2 eq '0') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c2 and $c2 eq 0) 51 1290 1341
Condition66%2/3
defined $c2 and $c2 eq 0
!ll&&!rl&&r
0129051
MC/DC50%1/2
defined $c2 and $c2 eq 0
defined $c2 $c2 eq 0
Truth table66%2/3
A and B
A= defined $c2B= $c2 eq 0
ABresult
0X0
100
111
2541 # ,1,"foo, 3"056",,bar,\r\n
2542 # ^
2543 51 $$v_ref .= "\0";
2544 51 next;
2545 }
2546 1290 ▶ if (defined $c2 and defined $quot and $c2 eq $quot) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c2 and defined $quot and $c2 eq $quot) 1081 209 1290
Condition50%3/6
defined $c2 and defined $quot and $c2 eq $quot
!ll&&!rl&&r
02091081
defined $c2 and defined $quot
!ll&&!rl&&r
001290
MC/DC33%1/3
defined $c2 and defined $quot and $c2 eq $quot
defined $c2 defined $quot $c2 eq $quot
Truth table50%2/4
A and B and C
A= defined $c2B= defined $quotC= $c2 eq $quot
ABCresult
0XX0
10X0
1100
1111
2547 # ,1,"foo, 3""56",,bar,\r\n
2548 # ^
2549 1081 ▶ if ($ctx->{utf8}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"utf8"}) 1 1080 1081
2550 1 $ctx->{flag} |= IS_BINARY;
2551 }
2552 1081 $$v_ref .= $c2;
2553 1081 next;
2554 }
2555 209 ▶ if ($ctx->{allow_loose_escapes} and defined $c2 and $c2 ne "\015") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"allow_loose_escapes"} and defined $c2 and $c2 ne "\r") 4 205 209
Condition83%5/6
$ctx->{"allow_loose_escapes"} and defined $c2 and $c2 ne "\r"
!ll&&!rl&&r
20414
$ctx->{"allow_loose_escapes"} and defined $c2
!ll&&!rl&&r
20405
MC/DC66%2/3
$ctx->{"allow_loose_escapes"} and defined $c2 and $c2 ne "\r"
$ctx->{"allow_loose_escapes"} defined $c2 $c2 ne "\r"
Truth table75%3/4
A and B and C
A= $ctx->{"allow_loose_escapes"}B= defined $c2C= $c2 ne "\r"
ABCresult
0XX0
10X0
1100
1111
2556 # ,1,"foo, 3"56",,bar,\r\n
2557 # ^
2558 4 $$v_ref .= $c;
2559 4 $c = $c2;
2560 4 goto RESTART;
2561 }
2562 }
2563 226 ▶ if (defined $c2 and $c2 eq "\015") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c2 and $c2 eq "\r") 169 57 226
Condition66%2/3
defined $c2 and $c2 eq "\r"
!ll&&!rl&&r
057169
MC/DC50%1/2
defined $c2 and $c2 eq "\r"
defined $c2 $c2 eq "\r"
Truth table66%2/3
A and B
A= defined $c2B= $c2 eq "\r"
ABresult
0X0
100
111
2564 169 ▶ if ($ctx->{eol_is_cr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"eol_is_cr"}) 0 169 169
2565 # ,1,"foo, 3"\r
2566 # ^
2567 0 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2568 0 return 1;
2569 }
2570  
2571 169 my $c3 = $self->__get($ctx, $src);
2572 169 ▶ if (defined $c3 and $c3 eq "\012") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c3 and $c3 eq "\n") 137 32 169
Condition100%3/3
defined $c3 and $c3 eq "\n"
!ll&&!rl&&r
527137
MC/DC100%2/2
defined $c3 and $c3 eq "\n"
defined $c3 $c3 eq "\n"
Truth table100%3/3
A and B
A= defined $c3B= $c3 eq "\n"
ABresult
0X0
100
111
2573 # ,1,"foo, 3"\r\n
2574 # ^
2575 137 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type} and $ctx->{eol_type} != EOL_TYPE_CRNL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3) 21 116 137
Condition100%6/6
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3
!ll&&!rl&&r
764021
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
522461
MC/DC100%3/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3
$ctx->{"strict_eol"} $ctx->{"eol_type"} $ctx->{"eol_type"} != 3
Truth table100%4/4
A and B and C
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}C= $ctx->{"eol_type"} != 3
ABCresult
0XX0
10X0
1100
1111
2576 21 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 21 0 21
2577 }
2578 137 $self->_set_eol_type($ctx, EOL_TYPE_CRNL);
2579 137 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2580 137 return 1;
2581 }
2582  
2583 32 ▶ if ($ctx->{useIO} and !$ctx->{eol_len}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"useIO"} and not $ctx->{"eol_len"}) 19 13 32
Condition66%2/3
$ctx->{"useIO"} and not $ctx->{"eol_len"}
!ll&&!rl&&r
13019
MC/DC50%1/2
$ctx->{"useIO"} and not $ctx->{"eol_len"}
$ctx->{"useIO"} not $ctx->{"eol_len"}
Truth table66%2/3
A and not(B)
A= $ctx->{"useIO"}B= not $ctx->{"eol_len"}
ABresult
0X0
100
111
2584 19 ▶ if ($c3 eq "\015") { # \r followed by an empty line
Branch: 1 branch
BranchTrueFalseTotal
if ($c3 eq "\r") 8 11 19
2585 # ,1,"foo, 3"\r\r
2586 # ^
2587 8 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict_eol"} and $ctx->{"eol_type"}) 2 6 8
Condition100%3/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
242
MC/DC100%2/2
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
$ctx->{"strict_eol"} $ctx->{"eol_type"}
Truth table100%3/3
A and B
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}
ABresult
0X0
100
111
2588 2 ▶ unless ($ctx->{eol_type} == EOL_TYPE_CR) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"eol_type"} == 2) 2 0 2
2589 2 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 2 0 2
2590 }
2591 2 $ctx->{used}--;
2592 2 $ctx->{has_ahead}++;
2593 2 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2594 2 return 1;
2595 }
2596 6 $self->__set_eol_is_cr($ctx);
2597 6 ▶ if ($ctx->{flag} & IS_QUOTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"flag"} & 1) 6 0 6
2598 6 $ctx->{flag} ^= IS_QUOTED;
2599 }
2600 6 $c = $c0 = "\015";
2601 6 goto EOLX;
2602 }
2603 11 ▶ if ($c3 !~ /[^\x09\x20-\x7E]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c3 =~ /[^\x09\x20-\x7E]/) 11 0 11
2604 # ,1,"foo\n 3",,"bar"\r
2605 # baz,4
2606 # ^
2607 11 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'strict_eol'} and $ctx->{'eol_type'}) { } 2 9 11
Condition100%3/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
542
MC/DC100%2/2
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
$ctx->{"strict_eol"} $ctx->{"eol_type"}
Truth table100%3/3
A and B
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}
ABresult
0X0
100
111
2608 2 ▶ unless ($ctx->{eol_type} == EOL_TYPE_CR) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"eol_type"} == 2) 2 0 2
2609 2 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 2 0 2
2610 }
2611 2 $ctx->{eol_is_cr} = 1;
2612 } else {
2613 9 $self->__set_eol_is_cr($ctx);
2614 }
2615 11 $ctx->{used}--;
2616 11 $ctx->{has_ahead} = 1;
2617 11 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2618 11 return 1;
2619 }
2620 }
2621  
2622 13 ▶ $self->__parse_error($ctx, $quoesc ? 2023 : 2010, $ctx->{used} - 2);
Branch: 1 branch
BranchTrueFalseTotal
$quoesc ? : 12 1 13
2623 13 return;
2624 }
2625  
2626 57 ▶ if ($ctx->{allow_loose_quotes} and !$quoesc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"allow_loose_quotes"} and not $quoesc) 10 47 57
Condition100%3/3
$ctx->{"allow_loose_quotes"} and not $quoesc
!ll&&!rl&&r
45210
MC/DC100%2/2
$ctx->{"allow_loose_quotes"} and not $quoesc
$ctx->{"allow_loose_quotes"} not $quoesc
Truth table100%3/3
A and not(B)
A= $ctx->{"allow_loose_quotes"}B= not $quoesc
ABresult
0X0
100
111
2627 # ,1,"foo, 3"456",,bar,\r\n
2628 # ^
2629 10 $$v_ref .= $c;
2630 10 $c = $c2;
2631 10 goto RESTART;
2632 }
2633 # 1,"foo" ",3
2634 # ^
2635 47 ▶ if ($quoesc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quoesc) 39 8 47
2636 39 $ctx->{used}--;
2637 39 $self->__error_inside_quotes($ctx, 2023);
2638 37 return;
2639 }
2640 8 $self->__error_inside_quotes($ctx, 2011);
2641 8 return;
2642 }
2643 # !waitingForField, !InsideQuotes
2644 68 ▶ if ($ctx->{allow_loose_quotes}) { # 1,foo "boo" d'uh,1
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'allow_loose_quotes'}) { } 16 52 68
2645 16 $ctx->{flag} |= IS_ERROR;
2646 16 $$v_ref .= $c;
2647 } else {
2648 52 $self->__error_inside_field($ctx, 2034);
2649 52 return;
2650 }
2651 }
2652 ▶ elsif (defined $c and defined $esc and $esc ne "\0" and $c eq $esc) {
Condition100%9/9
defined $c and defined $esc and $esc ne "\0" and $c eq $esc
!ll&&!rl&&r
165361104655
defined $c and defined $esc and $esc ne "\0"
!ll&&!rl&&r
2613940765
defined $c and defined $esc
!ll&&!rl&&r
101640904
MC/DC100%4/4
defined $c and defined $esc and $esc ne "\0" and $c eq $esc
defined $c defined $esc $esc ne "\0" $c eq $esc
Truth table100%5/5
A and B and C and D
A= defined $cB= defined $escC= $esc ne "\0"D= $c eq $esc
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2653 # This means quote_char != escape_char
2654 4655 ▶ if ($waitingForField) {
Branch: 3 branches
BranchTrueFalseTotal
if ($waitingForField) { } 34 4621 4655
elsif ($ctx->{'flag'} & 1) { } 4612 9 4621
elsif ($v_ref) { } 9 0 9
2655 34 $waitingForField = 0;
2656 34 ▶ if ($ctx->{allow_unquoted_escape}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"allow_unquoted_escape"}) 4 30 34
2657 # The escape character is the first character of an
2658 # unquoted field
2659 # ... get and store next character
2660 4 my $c2 = $self->__get($ctx, $src);
2661 4 $$v_ref = "";
2662  
2663 4 ▶ if (!defined $c2) { # EOF
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c2) 1 3 4
2664 1 $ctx->{used}--;
2665 1 $self->__error_inside_field($ctx, 2035);
2666 1 return;
2667 }
2668 3 ▶ if ($c2 eq '0') {
Branch: 2 branches
BranchTrueFalseTotal
if ($c2 eq '0') { } 1 2 3
elsif (defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep or defined $esc and $c2 eq $esc or $ctx->{'allow_loose_escapes'}) { } 2 0 2
2669 1 $$v_ref .= "\0";
2670 }
2671 ▶ elsif (
Condition27%5/18
defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep or defined $esc and $c2 eq $esc or $ctx->{"allow_loose_escapes"}
l!l&&r!l&&!r
200
defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep or defined $esc and $c2 eq $esc
l!l&&r!l&&!r
200
defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep
l!l&&r!l&&!r
020
defined $quot and $c2 eq $quot
!ll&&!rl&&r
020
defined $sep and $c2 eq $sep
!ll&&!rl&&r
002
defined $esc and $c2 eq $esc
!ll&&!rl&&r
000
MC/DC0%0/7
defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep or defined $esc and $c2 eq $esc or $ctx->{"allow_loose_escapes"}
defined $quot $c2 eq $quot defined $sep $c2 eq $sep defined $esc $c2 eq $esc $ctx->{"allow_loose_escapes"}
Truth table4%1/23
A and B or C and D or E and F or G
A= defined $quotB= $c2 eq $quotC= defined $sepD= $c2 eq $sepE= defined $escF= $c2 eq $escG= $ctx->{"allow_loose_escapes"}
ABCDEFGresult
11XXXXX1
0X11XXX1
1011XXX1
0X0X11X1
0X1011X1
100X11X1
101011X1
0X0X0X11
0X0X1011
0X100X11
0X101011
100X0X11
100X1011
10100X11
10101011
0X0X0X00
0X0X1000
0X100X00
0X101000
100X0X00
100X1000
10100X00
10101000
2672 (defined $quot and $c2 eq $quot) or
2673 (defined $sep and $c2 eq $sep) or
2674 (defined $esc and $c2 eq $esc) or
2675 $ctx->{allow_loose_escapes}
2676 ) {
2677 2 ▶ if ($ctx->{utf8}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"utf8"}) 0 2 2
2678 0 $ctx->{flag} |= IS_BINARY;
2679 }
2680 2 $$v_ref .= $c2;
2681 } else {
2682 0 $self->__parse_inside_quotes($ctx, 2025);
2683 0 return;
2684 }
2685 }
2686 }
2687 elsif ($ctx->{flag} & IS_QUOTED) {
2688 4612 my $c2 = $self->__get($ctx, $src);
2689 4612 ▶ if (!defined $c2) { # EOF
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c2) 3 4609 4612
2690 3 $ctx->{used}--;
2691 3 $self->__error_inside_quotes($ctx, 2024);
2692 3 return;
2693 }
2694 4609 ▶ if ($c2 eq '0') {
Branch: 2 branches
BranchTrueFalseTotal
if ($c2 eq '0') { } 2 4607 4609
elsif (defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep or defined $esc and $c2 eq $esc or $ctx->{'allow_loose_escapes'}) { } 4581 26 4607
2695 2 $$v_ref .= "\0";
2696 }
2697 ▶ elsif (
Condition83%15/18
defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep or defined $esc and $c2 eq $esc or $ctx->{"allow_loose_escapes"}
l!l&&r!l&&!r
4579226
defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep or defined $esc and $c2 eq $esc
l!l&&r!l&&!r
2414216528
defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep
l!l&&r!l&&!r
241132193
defined $quot and $c2 eq $quot
!ll&&!rl&&r
021962411
defined $sep and $c2 eq $sep
!ll&&!rl&&r
021933
defined $esc and $c2 eq $esc
!ll&&!rl&&r
0282165
MC/DC57%4/7
defined $quot and $c2 eq $quot or defined $sep and $c2 eq $sep or defined $esc and $c2 eq $esc or $ctx->{"allow_loose_escapes"}
defined $quot $c2 eq $quot defined $sep $c2 eq $sep defined $esc $c2 eq $esc $ctx->{"allow_loose_escapes"}
Truth table21%5/23
A and B or C and D or E and F or G
A= defined $quotB= $c2 eq $quotC= defined $sepD= $c2 eq $sepE= defined $escF= $c2 eq $escG= $ctx->{"allow_loose_escapes"}
ABCDEFGresult
11XXXXX1
0X11XXX1
1011XXX1
0X0X11X1
0X1011X1
100X11X1
101011X1
0X0X0X11
0X0X1011
0X100X11
0X101011
100X0X11
100X1011
10100X11
10101011
0X0X0X00
0X0X1000
0X100X00
0X101000
100X0X00
100X1000
10100X00
10101000
2698 (defined $quot and $c2 eq $quot) or
2699 (defined $sep and $c2 eq $sep) or
2700 (defined $esc and $c2 eq $esc) or
2701 $ctx->{allow_loose_escapes}
2702 ) {
2703 4581 ▶ if ($ctx->{utf8}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"utf8"}) 0 4581 4581
2704 0 $ctx->{flag} |= IS_BINARY;
2705 }
2706 4581 $$v_ref .= $c2;
2707 } else {
2708 26 $ctx->{used}--;
2709 26 $self->__error_inside_quotes($ctx, 2025);
2710 26 return;
2711 }
2712 }
2713 elsif ($v_ref) {
2714 9 my $c2 = $self->__get($ctx, $src);
2715 9 ▶ if (!defined $c2) { # EOF
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c2) 4 5 9
2716 4 $ctx->{used}--;
2717 4 $self->__error_inside_field($ctx, 2035);
2718 4 return;
2719 }
2720 5 $$v_ref .= $c2;
2721 }
2722 else {
2723 0 $self->__error_inside_field($ctx, 2036);
2724 0 return;
2725 }
2726 }
2727 ▶ elsif (defined $c and ($c eq "\012" or $c eq '' or (defined $eol and $c eq $eol and $eol ne "\015"))) { # EOL
Condition100%15/15
defined $c and $c eq "\n" || $c eq "" || defined $eol && $c eq $eol && $eol ne "\r"
!ll&&!rl&&r
10335632702
$c eq "\n" or $c eq "" or defined $eol and $c eq $eol and $eol ne "\r"
l!l&&r!l&&!r
229141133563
$c eq "\n" or $c eq ""
l!l&&r!l&&!r
195633533974
defined $eol and $c eq $eol and $eol ne "\r"
!ll&&!rl&&r
33083480411
defined $eol and $c eq $eol
!ll&&!rl&&r
3633047891
MC/DC100%6/6
defined $c and $c eq "\n" || $c eq "" || defined $eol && $c eq $eol && $eol ne "\r"
defined $c $c eq "\n" $c eq "" defined $eol $c eq $eol $eol ne "\r"
Truth table100%7/7
A and B or C or D and E and F
A= defined $cB= $c eq "\n"C= $c eq ""D= defined $eolE= $c eq $eolF= $eol ne "\r"
ABCDEFresult
0XXXXX0
1000XX0
10010X0
1001100
11XXXX1
101XXX1
1001111
2728 3289 ▶ EOLX:
Branch: 1 branch
BranchTrueFalseTotal
($c eq "\n" || $c eq "\r") && $c0 eq "\r" ? : 775 2514 3289
Condition100%6/6
$c eq "\n" || $c eq "\r" and $c0 eq "\r"
!ll&&!rl&&r
7461768775
$c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
2094449746
MC/DC100%3/3
$c eq "\n" || $c eq "\r" and $c0 eq "\r"
$c eq "\n" $c eq "\r" $c0 eq "\r"
Truth table80%4/5
A or B and C
A= $c eq "\n"B= $c eq "\r"C= $c0 eq "\r"
ABCresult
00X0
1X00
0100
1X11
0111
2729 my $eolt = (($c eq "\012" || $c eq "\015") && $c0 eq "\015") ? EOL_TYPE_CRNL : _eol_type($c);
2730 3289 $c0 = '';
2731 3289 ▶ unless ($ctx->{flag} & CSV_FLAGS_IS_QUOTED) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"flag"} & CSV_FLAGS_IS_QUOTED()) 2504 785 3289
2732 2504 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type} and $ctx->{eol_type} != $eolt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != $eolt) 39 2465 2504
Condition100%6/6
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != $eolt
!ll&&!rl&&r
196350239
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
1731232541
MC/DC100%3/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != $eolt
$ctx->{"strict_eol"} $ctx->{"eol_type"} $ctx->{"eol_type"} != $eolt
Truth table100%4/4
A and B and C
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}C= $ctx->{"eol_type"} != $eolt
ABCresult
0XX0
10X0
1100
1111
2733 39 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 34 5 39
2734 }
2735 2499 $self->_set_eol_type($ctx, $eolt);
2736 }
2737 3284 ▶ if ($fnum == 1 && $ctx->{flag} == 0 && (!$v_ref || $$v_ref eq '') && $ctx->{skip_empty_rows}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}) 89 3195 3284
Condition91%11/12
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}
!ll&&!rl&&r
31276889
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq ""
!ll&&!rl&&r
3010117157
$fnum == 1 and $ctx->{"flag"} == 0
!ll&&!rl&&r
2899111274
not $v_ref or $$v_ref eq ""
l!l&&r!l&&!r
0157117
MC/DC80%4/5
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}
$fnum == 1 $ctx->{"flag"} == 0 not $v_ref $$v_ref eq "" $ctx->{"skip_empty_rows"}
Truth table71%5/7
A and B and not(C) or D and E
A= $fnum == 1B= $ctx->{"flag"} == 0C= not $v_refD= $$v_ref eq ""E= $ctx->{"skip_empty_rows"}
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
2738 ### SkipEmptyRow
2739 89 my $ser = $ctx->{skip_empty_rows};
2740 89 ▶ if ($ser == 3) { $self->SetDiag(2015); die "Empty row\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 3) 3 86 89
2741 86 ▶ if ($ser == 4) { $self->SetDiag(2015); die "Empty row\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 4) 3 83 86
2742 83 ▶ if ($ser == 5) { $self->SetDiag(2015); return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 5) 2 81 83
2743  
2744 81 ▶ if ($ser <= 2) { # skip & eof
Branch: 1 branch
BranchTrueFalseTotal
if ($ser <= 2) 71 10 81
2745 71 $ctx->{fld_idx} = 0;
2746 71 $c = $self->__get($ctx, $src);
2747 71 ▶ if (!defined $c or $ser == 2) { # EOF
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c or $ser == 2) 8 63 71
Condition100%3/3
not defined $c or $ser == 2
l!l&&r!l&&!r
6263
MC/DC100%2/2
not defined $c or $ser == 2
not defined $c $ser == 2
Truth table100%3/3
not(A) or B
A= not defined $cB= $ser == 2
ABresult
1X1
011
000
2748 8 $v_ref = undef;
2749 8 $seenSomething = 0;
2750 8 ▶ if ($ser == 2) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 2) 2 6 8
2751 6 last LOOP;
2752 }
2753 }
2754  
2755 73 ▶ if ($ser == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 6) 10 63 73
2756 10 my $cb = $self->{_EMPTROW_CB};
2757 10 ▶ unless ($cb && ref $cb eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cb and ref $cb eq "CODE") 0 10 10
Condition33%1/3
$cb and ref $cb eq "CODE"
!ll&&!rl&&r
0010
MC/DC0%0/2
$cb and ref $cb eq "CODE"
$cb ref $cb eq "CODE"
Truth table33%1/3
A and B
A= $cbB= ref $cb eq "CODE"
ABresult
0X0
100
111
2758 0 return undef; # A callback is wanted, but none found
2759 }
2760 10 local $_ = $v_ref;
2761 10 my $rv = $cb->();
2762 # Result should be a ref to a list.
2763 10 ▶ unless (ref $rv eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $rv eq "ARRAY") 2 8 10
2764 2 return undef;
2765 }
2766 8 my $n = @$rv;
2767 8 ▶ if ($n <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= 0) 0 8 8
2768 0 return 1;
2769 }
2770 8 ▶ if ($ctx->{is_bound} && $ctx->{is_bound} < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"is_bound"} and $ctx->{"is_bound"} < $n) 0 8 8
Condition33%1/3
$ctx->{"is_bound"} and $ctx->{"is_bound"} < $n
!ll&&!rl&&r
800
MC/DC0%0/2
$ctx->{"is_bound"} and $ctx->{"is_bound"} < $n
$ctx->{"is_bound"} $ctx->{"is_bound"} < $n
Truth table33%1/3
A and B
A= $ctx->{"is_bound"}B= $ctx->{"is_bound"} < $n
ABresult
0X0
100
111
2771 0 $n = $ctx->{is_bound} - 1;
2772 }
2773 8 ▶ for (my $i = 0; $i < $n; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 32 8 40
2774 32 my $rvi = $rv->[$i];
2775 32 $self->__push_value($ctx, \$rvi, $fields, $fflags, $ctx->{flag}, $fnum);
2776 }
2777 8 return 1;
2778 }
2779 63 goto RESTART;
2780 }
2781  
2782 3195 ▶ if ($waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if ($waitingForField) 263 2932 3195
2783 # ,1,"foo, 3",,bar,
2784 # ^
2785 263 ▶ if ($ctx->{blank_is_undef} or $ctx->{empty_is_undef}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'blank_is_undef'} or $ctx->{'empty_is_undef'}) { } 16 247 263
Condition100%3/3
$ctx->{"blank_is_undef"} or $ctx->{"empty_is_undef"}
l!l&&r!l&&!r
88247
MC/DC100%2/2
$ctx->{"blank_is_undef"} or $ctx->{"empty_is_undef"}
$ctx->{"blank_is_undef"} $ctx->{"empty_is_undef"}
Truth table100%3/3
A or B
A= $ctx->{"blank_is_undef"}B= $ctx->{"empty_is_undef"}
ABresult
1X1
011
000
2786 16 $$v_ref = undef;
2787 } else {
2788 247 $$v_ref = "";
2789 }
2790 263 ▶ unless ($ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"is_bound"}) 262 1 263
2791 262 push @$fields, $$v_ref;
2792 }
2793 263 ▶ if ($ctx->{keep_meta_info} and $fflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"keep_meta_info"} and $fflags) 14 249 263
Condition66%2/3
$ctx->{"keep_meta_info"} and $fflags
!ll&&!rl&&r
249014
MC/DC50%1/2
$ctx->{"keep_meta_info"} and $fflags
$ctx->{"keep_meta_info"} $fflags
Truth table66%2/3
A and B
A= $ctx->{"keep_meta_info"}B= $fflags
ABresult
0X0
100
111
2794 14 push @$fflags, $ctx->{flag};
2795 }
2796 263 return 1;
2797 }
2798 2932 ▶ if ($ctx->{flag} & IS_QUOTED) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctx->{'flag'} & 1) { } 785 2147 2932
elsif ($ctx->{'verbatim'}) { } 11 2136 2147
2799 # ,1,"foo\n 3",,bar,
2800 # ^
2801 785 $ctx->{flag} |= IS_BINARY;
2802 785 ▶ unless ($ctx->{binary}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"binary"}) 29 756 785
2803 29 $self->__error_inside_quotes($ctx, 2021);
2804 29 return;
2805 }
2806 756 $$v_ref .= $c;
2807 }
2808 elsif ($ctx->{verbatim}) {
2809 # ,1,foo\n 3,,bar,
2810 # This feature should be deprecated
2811 11 $ctx->{flag} |= IS_BINARY;
2812 11 ▶ unless ($ctx->{binary}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"binary"}) 1 10 11
2813 1 $self->__error_inside_field($ctx, 2030);
2814 1 return;
2815 }
2816 10 ▶ $$v_ref .= $c unless $ctx->{eol} eq $c and $ctx->{useIO};
Branch: 1 branch
BranchTrueFalseTotal
unless $ctx->{"eol"} eq $c and $ctx->{"useIO"} 8 2 10
Condition100%3/3
$ctx->{"eol"} eq $c and $ctx->{"useIO"}
!ll&&!rl&&r
622
MC/DC100%2/2
$ctx->{"eol"} eq $c and $ctx->{"useIO"}
$ctx->{"eol"} eq $c $ctx->{"useIO"}
Truth table100%3/3
A and B
A= $ctx->{"eol"} eq $cB= $ctx->{"useIO"}
ABresult
0X0
100
111
2817 }
2818 else {
2819 # sep=,
2820 # ^
2821 2136 ▶ if (!$ctx->{recno} and $ctx->{fld_idx} == 1 and $ctx->{useIO} and $hit =~ /^sep=(.{1,16})$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ctx->{"recno"} and $ctx->{"fld_idx"} == 1 and $ctx->{"useIO"} and $hit =~ /^sep=(.{1,16})$/i) 4 2132 2136
Condition100%9/9
not $ctx->{"recno"} and $ctx->{"fld_idx"} == 1 and $ctx->{"useIO"} and $hit =~ /^sep=(.{1,16})$/i
!ll&&!rl&&r
2107254
not $ctx->{"recno"} and $ctx->{"fld_idx"} == 1 and $ctx->{"useIO"}
!ll&&!rl&&r
2104329
not $ctx->{"recno"} and $ctx->{"fld_idx"} == 1
!ll&&!rl&&r
161648832
MC/DC100%4/4
not $ctx->{"recno"} and $ctx->{"fld_idx"} == 1 and $ctx->{"useIO"} and $hit =~ /^sep=(.{1,16})$/i
not $ctx->{"recno"} $ctx->{"fld_idx"} == 1 $ctx->{"useIO"} $hit =~ /^sep=(.{1,16})$/i
Truth table100%5/5
not(A) and B and C and D
A= not $ctx->{"recno"}B= $ctx->{"fld_idx"} == 1C= $ctx->{"useIO"}D= $hit =~ /^sep=(.{1,16})$/i
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2822 4 $ctx->{sep} = $1;
2823 39 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
2824 4 my $len = length $ctx->{sep};
2825 4 ▶ if ($len <= 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len <= 16) 4 0 4
2826 4 ▶ $ctx->{sep_len} = $len == 1 ? 0 : $len;
Branch: 1 branch
BranchTrueFalseTotal
$len == 1 ? : 3 1 4
2827 4 return $self->____parse($ctx, $src, $fields, $fflags);
2828 }
2829 }
2830  
2831 # ,1,"foo\n 3",,bar
2832 # ^
2833 2132 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2834 2132 return 1;
2835 }
2836 }
2837 ▶ elsif (defined $c and $c eq "\015" and !$ctx->{verbatim}) {
Condition100%6/6
defined $c and $c eq "\r" and not $ctx->{"verbatim"}
!ll&&!rl&&r
3231531255
defined $c and $c eq "\r"
!ll&&!rl&&r
10323051258
MC/DC100%3/3
defined $c and $c eq "\r" and not $ctx->{"verbatim"}
defined $c $c eq "\r" not $ctx->{"verbatim"}
Truth table100%4/4
A and B and not(C)
A= defined $cB= $c eq "\r"C= not $ctx->{"verbatim"}
ABCresult
0XX0
10X0
1100
1111
2838 1255 $c0 = "\015";
2839 1255 ▶ if ($waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if ($waitingForField) 164 1091 1255
2840 164 ▶ if ($ctx->{eol_is_cr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"eol_is_cr"}) 48 116 164
2841 # ,1,"foo\n 3",,bar,\r
2842 # ^
2843 48 $c = "\012";
2844 48 goto EOLX;
2845 }
2846  
2847 116 my $c2 = $self->__get($ctx, $src);
2848 116 ▶ if (!defined $c2) { # EOF
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c2) 5 111 116
2849 # ,1,"foo\n 3",,bar,\r
2850 # ^
2851 5 $c = undef;
2852 5 ▶ last unless $seenSomething;
Branch: 1 branch
BranchTrueFalseTotal
unless $seenSomething 0 5 5
2853 5 goto RESTART;
2854 }
2855 111 ▶ if ($c2 eq "\012") { # \r is not optional before EOLX!
Branch: 1 branch
BranchTrueFalseTotal
if ($c2 eq "\n") 90 21 111
2856 # ,1,"foo\n 3",,bar,\r\n
2857 # ^
2858 90 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type} and $ctx->{eol_type} != EOL_TYPE_CRNL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3) 0 90 90
Condition83%5/6
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3
!ll&&!rl&&r
79110
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
71811
MC/DC0%0/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3
$ctx->{"strict_eol"} $ctx->{"eol_type"} $ctx->{"eol_type"} != 3
Truth table75%3/4
A and B and C
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}C= $ctx->{"eol_type"} != 3
ABCresult
0XX0
10X0
1100
1111
2859 0 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 0 0 0
2860 }
2861 90 $self->_set_eol_type($ctx, EOL_TYPE_CRNL);
2862 90 $c = $c2;
2863 90 goto EOLX;
2864 }
2865  
2866 21 ▶ if ($ctx->{useIO} and !$ctx->{eol_len}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"useIO"} and not $ctx->{"eol_len"}) 16 5 21
Condition66%2/3
$ctx->{"useIO"} and not $ctx->{"eol_len"}
!ll&&!rl&&r
5016
MC/DC50%1/2
$ctx->{"useIO"} and not $ctx->{"eol_len"}
$ctx->{"useIO"} not $ctx->{"eol_len"}
Truth table66%2/3
A and not(B)
A= $ctx->{"useIO"}B= not $ctx->{"eol_len"}
ABresult
0X0
100
111
2867 16 ▶ if ($c2 eq "\012") { # \r followed by an empty line
Branch: 1 branch
BranchTrueFalseTotal
if ($c2 eq "\n") 0 16 16
2868 # ,1,"foo\n 3",,bar,\r\r
2869 # ^
2870 0 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'strict_eol'} and $ctx->{'eol_type'}) { } 0 0 0
Condition0%0/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
$ctx->{"strict_eol"} $ctx->{"eol_type"}
Truth table0%0/3
A and B
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}
ABresult
0X0
100
111
2871 0 ▶ unless ($ctx->{eol_type} == EOL_TYPE_CR) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"eol_type"} == 2) 0 0 0
2872 0 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 0 0 0
2873 }
2874 0 $ctx->{eol_is_cr} = 1;
2875 } else {
2876 0 $self->__set_eol_is_cr($ctx);
2877 }
2878 0 goto EOLX;
2879 }
2880 16 $waitingForField = 0;
2881 16 ▶ if ($c2 !~ /[^\x09\x20-\x7E]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c2 =~ /[^\x09\x20-\x7E]/) 13 3 16
2882 # ,1,"foo\n 3",,bar,\r
2883 # baz,4
2884 # ^
2885 13 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'strict_eol'} and $ctx->{'eol_type'}) { } 4 9 13
Condition100%3/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
454
MC/DC100%2/2
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
$ctx->{"strict_eol"} $ctx->{"eol_type"}
Truth table100%3/3
A and B
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}
ABresult
0X0
100
111
2886 4 ▶ unless ($ctx->{eol_type} == EOL_TYPE_CR) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"eol_type"} == 2) 4 0 4
2887 4 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 4 0 4
2888 }
2889 } else {
2890 9 $self->__set_eol_is_cr($ctx);
2891 }
2892 13 $ctx->{used}--;
2893 13 $ctx->{has_ahead} = 1;
2894 13 ▶ if ($fnum == 1 && $ctx->{flag} == 0 && (!$v_ref or $$v_ref eq '') && $ctx->{skip_empty_rows}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}) 6 7 13
Condition66%8/12
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}
!ll&&!rl&&r
256
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq ""
!ll&&!rl&&r
2011
$fnum == 1 and $ctx->{"flag"} == 0
!ll&&!rl&&r
2011
not $v_ref or $$v_ref eq ""
l!l&&r!l&&!r
0110
MC/DC40%2/5
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}
$fnum == 1 $ctx->{"flag"} == 0 not $v_ref $$v_ref eq "" $ctx->{"skip_empty_rows"}
Truth table42%3/7
A and B and not(C) or D and E
A= $fnum == 1B= $ctx->{"flag"} == 0C= not $v_refD= $$v_ref eq ""E= $ctx->{"skip_empty_rows"}
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
2895 ### SkipEmptyRow
2896 6 my $ser = $ctx->{skip_empty_rows};
2897 0 ▶ if ($ser == 3) { $self->SetDiag(2015); die "Empty row\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 3) 0 6 6
2898 0 ▶ if ($ser == 4) { $self->SetDiag(2015); die "Empty row\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 4) 0 6 6
2899 0 ▶ if ($ser == 5) { $self->SetDiag(2015); return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 5) 0 6 6
2900  
2901 6 ▶ if ($ser <= 2) { # skip & eof
Branch: 1 branch
BranchTrueFalseTotal
if ($ser <= 2) 6 0 6
2902 6 $ctx->{fld_idx} = 0;
2903 6 $c = $self->__get($ctx, $src);
2904 6 ▶ if (!defined $c) { # EOF
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c) 0 6 6
2905 0 $v_ref = undef;
2906 0 $waitingForField = 1;
2907 0 $seenSomething = 0;
2908 0 last LOOP;
2909 }
2910 }
2911  
2912 6 ▶ if ($ser == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 6) 0 6 6
2913 0 my $cb = $self->{_EMPTROW_CB};
2914 0 ▶ unless ($cb && ref $cb eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cb and ref $cb eq "CODE") 0 0 0
Condition0%0/3
$cb and ref $cb eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$cb and ref $cb eq "CODE"
$cb ref $cb eq "CODE"
Truth table0%0/3
A and B
A= $cbB= ref $cb eq "CODE"
ABresult
0X0
100
111
2915 0 return undef; # A callback is wanted, but none found
2916 }
2917 0 local $_ = $v_ref;
2918 0 my $rv = $cb->();
2919 # Result should be a ref to a list.
2920 0 ▶ unless (ref $rv eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $rv eq "ARRAY") 0 0 0
2921 0 return undef;
2922 }
2923 0 my $n = @$rv;
2924 0 ▶ if ($n <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= 0) 0 0 0
2925 0 return 1;
2926 }
2927 0 ▶ if ($ctx->{is_bound} && $ctx->{is_bound} < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"is_bound"} and $ctx->{"is_bound"} < $n) 0 0 0
Condition0%0/3
$ctx->{"is_bound"} and $ctx->{"is_bound"} < $n
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->{"is_bound"} and $ctx->{"is_bound"} < $n
$ctx->{"is_bound"} $ctx->{"is_bound"} < $n
Truth table0%0/3
A and B
A= $ctx->{"is_bound"}B= $ctx->{"is_bound"} < $n
ABresult
0X0
100
111
2928 0 $n = $ctx->{is_bound} - 1;
2929 }
2930 0 ▶ for (my $i = 0; $i < $n; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 0 0 0
2931 0 my $rvi = $rv->[$i];
2932 0 $self->__push_value($ctx, \$rvi, $fields, $fflags, $ctx->{flag}, $fnum);
2933 }
2934 0 return 1;
2935 }
2936  
2937 6 $$v_ref = $c2;
2938 6 goto RESTART;
2939 }
2940 7 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
2941 7 return 1;
2942 }
2943 }
2944  
2945 # ,1,"foo\n 3",,bar,\r\t
2946 # ^
2947 8 $ctx->{used}--;
2948 8 $self->__error_inside_field($ctx, 2031);
2949 8 return;
2950 }
2951 1091 ▶ if ($ctx->{flag} & IS_QUOTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'flag'} & 1) { } 614 477 1091
2952 # ,1,"foo\r 3",,bar,\r\t
2953 # ^
2954 614 $ctx->{flag} |= IS_BINARY;
2955 614 ▶ unless ($ctx->{binary}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"binary"}) 70 544 614
2956 70 $self->__error_inside_quotes($ctx, 2022);
2957 70 return;
2958 }
2959 544 $$v_ref .= $c;
2960 }
2961 else {
2962 477 ▶ if ($ctx->{eol_is_cr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"eol_is_cr"}) 192 285 477
2963 # ,1,"foo\n 3",,bar\r
2964 # ^
2965 192 goto EOLX;
2966 }
2967  
2968 285 my $c2 = $self->__get($ctx, $src);
2969 285 ▶ if (defined $c2 and $c2 eq "\012") { # \r is not optional before EOLX!
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c2 and $c2 eq "\n") 251 34 285
Condition100%3/3
defined $c2 and $c2 eq "\n"
!ll&&!rl&&r
529251
MC/DC100%2/2
defined $c2 and $c2 eq "\n"
defined $c2 $c2 eq "\n"
Truth table100%3/3
A and B
A= defined $c2B= $c2 eq "\n"
ABresult
0X0
100
111
2970 # ,1,"foo\n 3",,bar\r\n
2971 # ^
2972 251 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type} and $ctx->{eol_type} != EOL_TYPE_CRNL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3) 10 241 251
Condition100%6/6
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3
!ll&&!rl&&r
1657610
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
897686
MC/DC100%3/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"} and $ctx->{"eol_type"} != 3
$ctx->{"strict_eol"} $ctx->{"eol_type"} $ctx->{"eol_type"} != 3
Truth table100%4/4
A and B and C
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}C= $ctx->{"eol_type"} != 3
ABCresult
0XX0
10X0
1100
1111
2973 10 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 10 0 10
2974 }
2975 251 $self->_set_eol_type($ctx, EOL_TYPE_CRNL);
2976 251 goto EOLX;
2977 }
2978  
2979 34 ▶ if ($ctx->{useIO} and !$ctx->{eol_len}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"useIO"} and not $ctx->{"eol_len"}) 29 5 34
Condition66%2/3
$ctx->{"useIO"} and not $ctx->{"eol_len"}
!ll&&!rl&&r
5029
MC/DC50%1/2
$ctx->{"useIO"} and not $ctx->{"eol_len"}
$ctx->{"useIO"} not $ctx->{"eol_len"}
Truth table66%2/3
A and not(B)
A= $ctx->{"useIO"}B= not $ctx->{"eol_len"}
ABresult
0X0
100
111
2980 29 ▶ if ($c2 !~ /[^\x09\x20-\x7E]/
Branch: 1 branch
BranchTrueFalseTotal
if (not $c2 =~ /[^\x09\x20-\x7E]/ or $c2 eq "\r") 23 6 29
Condition100%3/3
not $c2 =~ /[^\x09\x20-\x7E]/ or $c2 eq "\r"
l!l&&r!l&&!r
1496
MC/DC100%2/2
not $c2 =~ /[^\x09\x20-\x7E]/ or $c2 eq "\r"
not $c2 =~ /[^\x09\x20-\x7E]/ $c2 eq "\r"
Truth table100%3/3
not(A) or B
A= not $c2 =~ /[^\x09\x20-\x7E]/B= $c2 eq "\r"
ABresult
1X1
011
000
2981 # ,1,"foo\n 3",,bar\r
2982 # baz,4
2983 # ^
2984 or $c2 eq "\015"
2985 # ,1,"foo\n 3",,bar,\r\r
2986 # ^
2987 ) {
2988 23 ▶ if ($ctx->{strict_eol} and $ctx->{eol_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'strict_eol'} and $ctx->{'eol_type'}) { } 4 19 23
Condition100%3/3
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
!ll&&!rl&&r
1184
MC/DC100%2/2
$ctx->{"strict_eol"} and $ctx->{"eol_type"}
$ctx->{"strict_eol"} $ctx->{"eol_type"}
Truth table100%3/3
A and B
A= $ctx->{"strict_eol"}B= $ctx->{"eol_type"}
ABresult
0X0
100
111
2989 4 ▶ unless ($ctx->{eol_type} == EOL_TYPE_CR) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"eol_type"} == 2) 4 0 4
2990 4 ▶ $self->__error_eol($ctx) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->__error_eol($ctx) or return 4 0 4
2991 }
2992 } else {
2993 19 $self->__set_eol_is_cr($ctx);
2994 }
2995 23 $ctx->{used}--;
2996 23 $ctx->{has_ahead} = 1;
2997 23 ▶ if ($fnum == 1 && $ctx->{flag} == 0 && (!$v_ref or $$v_ref eq '') && $ctx->{skip_empty_rows}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}) 0 23 23
Condition25%3/12
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}
!ll&&!rl&&r
2300
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq ""
!ll&&!rl&&r
2300
$fnum == 1 and $ctx->{"flag"} == 0
!ll&&!rl&&r
2300
not $v_ref or $$v_ref eq ""
l!l&&r!l&&!r
000
MC/DC0%0/5
$fnum == 1 and $ctx->{"flag"} == 0 and !$v_ref || $$v_ref eq "" and $ctx->{"skip_empty_rows"}
$fnum == 1 $ctx->{"flag"} == 0 not $v_ref $$v_ref eq "" $ctx->{"skip_empty_rows"}
Truth table14%1/7
A and B and not(C) or D and E
A= $fnum == 1B= $ctx->{"flag"} == 0C= not $v_refD= $$v_ref eq ""E= $ctx->{"skip_empty_rows"}
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
2998 ### SKipEmptyRow
2999 0 my $ser = $ctx->{skip_empty_rows};
3000 0 ▶ if ($ser == 3) { $self->SetDiag(2015); die "Empty row\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 3) 0 0 0
3001 0 ▶ if ($ser == 4) { $self->SetDiag(2015); die "Empty row\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 4) 0 0 0
3002 0 ▶ if ($ser == 5) { $self->SetDiag(2015); return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 5) 0 0 0
3003  
3004 0 ▶ if ($ser <= 2) { # skip & eof
Branch: 1 branch
BranchTrueFalseTotal
if ($ser <= 2) 0 0 0
3005 0 $ctx->{fld_idx} = 0;
3006 0 $c = $self->__get($ctx, $src);
3007 0 ▶ if (!defined $c) { # EOL
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c) 0 0 0
3008 0 $v_ref = undef;
3009 0 $seenSomething = 0;
3010 0 last LOOP;
3011 }
3012 }
3013  
3014 0 ▶ if ($ser == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ser == 6) 0 0 0
3015 0 my $cb = $self->{_EMPTROW_CB};
3016 0 ▶ unless ($cb && ref $cb eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cb and ref $cb eq "CODE") 0 0 0
Condition0%0/3
$cb and ref $cb eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$cb and ref $cb eq "CODE"
$cb ref $cb eq "CODE"
Truth table0%0/3
A and B
A= $cbB= ref $cb eq "CODE"
ABresult
0X0
100
111
3017 0 return undef; # A callback is wanted, but none found
3018 }
3019 0 local $_ = $v_ref;
3020 0 my $rv = $cb->();
3021 # Result should be a ref to a list.
3022 0 ▶ unless (ref $rv eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $rv eq "ARRAY") 0 0 0
3023 0 return undef;
3024 }
3025 0 my $n = @$rv;
3026 0 ▶ if ($n <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= 0) 0 0 0
3027 0 return 1;
3028 }
3029 0 ▶ if ($ctx->{is_bound} && $ctx->{is_bound} < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"is_bound"} and $ctx->{"is_bound"} < $n) 0 0 0
Condition0%0/3
$ctx->{"is_bound"} and $ctx->{"is_bound"} < $n
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->{"is_bound"} and $ctx->{"is_bound"} < $n
$ctx->{"is_bound"} $ctx->{"is_bound"} < $n
Truth table0%0/3
A and B
A= $ctx->{"is_bound"}B= $ctx->{"is_bound"} < $n
ABresult
0X0
100
111
3030 0 $n = $ctx->{is_bound} - 1;
3031 }
3032 0 ▶ for (my $i = 0; $i < $n; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 0 0 0
3033 0 my $rvi = $rv->[$i];
3034 0 $self->__push_value($ctx, \$rvi, $fields, $fflags, $ctx->{flag}, $fnum);
3035 }
3036 0 return 1;
3037 }
3038 0 goto RESTART;
3039 }
3040 23 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
3041 23 return 1;
3042 }
3043 }
3044  
3045 # ,1,"foo\n 3",,bar\r\t
3046 # ^
3047 11 $self->__error_inside_field($ctx, 2032);
3048 11 return;
3049 }
3050 }
3051 else {
3052 32318 ▶ if ($ctx->{eolx} and $c eq $eol) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"eolx"} and $c eq $eol) 0 32318 32318
Condition66%2/3
$ctx->{"eolx"} and $c eq $eol
!ll&&!rl&&r
315707480
MC/DC0%0/2
$ctx->{"eolx"} and $c eq $eol
$ctx->{"eolx"} $c eq $eol
Truth table66%2/3
A and B
A= $ctx->{"eolx"}B= $c eq $eol
ABresult
0X0
100
111
3053 0 $c = '';
3054 0 goto EOLX;
3055 }
3056  
3057 32318 ▶ if ($waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if ($waitingForField) 654 31664 32318
3058 654 ▶ if (!$spl && $ctx->{comment_str} && $ctx->{tmp} =~ /\A$ctx->{comment_str}/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $spl and $ctx->{"comment_str"} and $ctx->{"tmp"} =~ /\A$ctx->{"comment_str"}/) 6 648 654
Condition100%6/6
not $spl and $ctx->{"comment_str"} and $ctx->{"tmp"} =~ /\A$ctx->{"comment_str"}/
!ll&&!rl&&r
636126
not $spl and $ctx->{"comment_str"}
!ll&&!rl&&r
44319318
MC/DC100%3/3
not $spl and $ctx->{"comment_str"} and $ctx->{"tmp"} =~ /\A$ctx->{"comment_str"}/
not $spl $ctx->{"comment_str"} $ctx->{"tmp"} =~ /\A$ctx->{"comment_str"}/
Truth table100%4/4
not(A) and B and C
A= not $splB= $ctx->{"comment_str"}C= $ctx->{"tmp"} =~ /\A$ctx->{"comment_str"}/
ABCresult
0XX0
10X0
1100
1111
3059 6 $ctx->{used} = $ctx->{size};
3060 6 ▶ $ctx->{fld_idx} = $ctx->{strict_n} ? $ctx->{strict_n} - 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'strict_n'} ? : 0 6 6
3061 6 $seenSomething = 0;
3062 6 ▶ unless ($ctx->{useIO}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"useIO"}) 0 6 6
3063 0 $ctx->{has_ahead} = 214; # abuse
3064 }
3065 6 next LOOP;
3066 }
3067 648 ▶ if ($ctx->{allow_whitespace} and $self->__is_whitespace($ctx, $c)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"allow_whitespace"} and $self->__is_whitespace($ctx, $c)) 241 407 648
Condition100%3/3
$ctx->{"allow_whitespace"} and $self->__is_whitespace($ctx, $c)
!ll&&!rl&&r
284123241
MC/DC100%2/2
$ctx->{"allow_whitespace"} and $self->__is_whitespace($ctx, $c)
$ctx->{"allow_whitespace"} $self->__is_whitespace($ctx, $c)
Truth table100%3/3
A and B
A= $ctx->{"allow_whitespace"}B= $self->__is_whitespace($ctx, $c)
ABresult
0X0
100
111
3068 241 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->__is_whitespace($ctx, $c) and do { do { $c = $self->__get($ctx, $src); last unless defined $c } } 110 240 350
3069 351 $c = $self->__get($ctx, $src);
3070 351 ▶ last if !defined $c;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 1 350 351
3071 } while $self->__is_whitespace($ctx, $c);
3072 240 goto RESTART;
3073 }
3074 407 $waitingForField = 0;
3075 407 goto RESTART;
3076 }
3077 31664 ▶ if ($ctx->{flag} & IS_QUOTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'flag'} & 1) { } 29475 2189 31664
3078 29475 ▶ if (!defined $c or $c =~ /[^\x09\x20-\x7E]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c or $c =~ /[^\x09\x20-\x7E]/) 3297 26178 29475
Condition66%2/3
not defined $c or $c =~ /[^\x09\x20-\x7E]/
l!l&&r!l&&!r
0329726178
MC/DC50%1/2
not defined $c or $c =~ /[^\x09\x20-\x7E]/
not defined $c $c =~ /[^\x09\x20-\x7E]/
Truth table66%2/3
not(A) or B
A= not defined $cB= $c =~ /[^\x09\x20-\x7E]/
ABresult
1X1
011
000
3079 3297 $ctx->{flag} |= IS_BINARY;
3080 3297 ▶ unless ($ctx->{binary} or $ctx->{utf8}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"binary"} or $ctx->{"utf8"}) 5 3292 3297
Condition100%3/3
$ctx->{"binary"} or $ctx->{"utf8"}
l!l&&r!l&&!r
3282105
MC/DC100%2/2
$ctx->{"binary"} or $ctx->{"utf8"}
$ctx->{"binary"} $ctx->{"utf8"}
Truth table100%3/3
A or B
A= $ctx->{"binary"}B= $ctx->{"utf8"}
ABresult
1X1
011
000
3081 5 $self->__error_inside_quotes($ctx, 2026);
3082 5 return;
3083 }
3084 }
3085 29470 $$v_ref .= $c;
3086 } else {
3087 2189 ▶ if (!defined $c or $c =~ /[^\x09\x20-\x7E]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c or $c =~ /[^\x09\x20-\x7E]/) 450 1739 2189
Condition100%3/3
not defined $c or $c =~ /[^\x09\x20-\x7E]/
l!l&&r!l&&!r
54451739
MC/DC100%2/2
not defined $c or $c =~ /[^\x09\x20-\x7E]/
not defined $c $c =~ /[^\x09\x20-\x7E]/
Truth table100%3/3
not(A) or B
A= not defined $cB= $c =~ /[^\x09\x20-\x7E]/
ABresult
1X1
011
000
3088 450 ▶ last if $ctx->{useIO} && !defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"useIO"} and not defined $c 3 447 450
Condition100%3/3
$ctx->{"useIO"} and not defined $c
!ll&&!rl&&r
394083
MC/DC100%2/2
$ctx->{"useIO"} and not defined $c
$ctx->{"useIO"} not defined $c
Truth table100%3/3
A and not(B)
A= $ctx->{"useIO"}B= not defined $c
ABresult
0X0
100
111
3089 447 $ctx->{flag} |= IS_BINARY;
3090 447 ▶ unless ($ctx->{binary} or $ctx->{utf8}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"binary"} or $ctx->{"utf8"}) 9 438 447
Condition66%2/3
$ctx->{"binary"} or $ctx->{"utf8"}
l!l&&r!l&&!r
43809
MC/DC50%1/2
$ctx->{"binary"} or $ctx->{"utf8"}
$ctx->{"binary"} $ctx->{"utf8"}
Truth table66%2/3
A or B
A= $ctx->{"binary"}B= $ctx->{"utf8"}
ABresult
1X1
011
000
3091 9 $self->__error_inside_field($ctx, 2037);
3092 9 return;
3093 }
3094 }
3095 2177 $$v_ref .= $c;
3096 }
3097 }
3098 50140 ▶ last LOOP if $ctx->{useIO} and $ctx->{verbatim} and $ctx->{used} == $ctx->{size};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"useIO"} and $ctx->{"verbatim"} and $ctx->{"used"} == $ctx->{"size"} 3 50137 50140
Condition100%6/6
$ctx->{"useIO"} and $ctx->{"verbatim"} and $ctx->{"used"} == $ctx->{"size"}
!ll&&!rl&&r
5012893
$ctx->{"useIO"} and $ctx->{"verbatim"}
!ll&&!rl&&r
40889923912
MC/DC100%3/3
$ctx->{"useIO"} and $ctx->{"verbatim"} and $ctx->{"used"} == $ctx->{"size"}
$ctx->{"useIO"} $ctx->{"verbatim"} $ctx->{"used"} == $ctx->{"size"}
Truth table100%4/4
A and B and C
A= $ctx->{"useIO"}B= $ctx->{"verbatim"}C= $ctx->{"used"} == $ctx->{"size"}
ABCresult
0XX0
10X0
1100
1111
3099 }
3100 }
3101  
3102 472 ▶ if ($waitingForField) {
Branch: 1 branch
BranchTrueFalseTotal
if ($waitingForField) 417 55 472
3103 417 ▶ unless ($ctx->{useIO}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"useIO"}) 25 392 417
3104 25 ▶ if ($ctx->{has_ahead} and $ctx->{has_ahead} == 214) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"has_ahead"} and $ctx->{"has_ahead"} == 214) 1 24 25
Condition66%2/3
$ctx->{"has_ahead"} and $ctx->{"has_ahead"} == 214
!ll&&!rl&&r
2401
MC/DC50%1/2
$ctx->{"has_ahead"} and $ctx->{"has_ahead"} == 214
$ctx->{"has_ahead"} $ctx->{"has_ahead"} == 214
Truth table66%2/3
A and B
A= $ctx->{"has_ahead"}B= $ctx->{"has_ahead"} == 214
ABresult
0X0
100
111
3105 1 return 1;
3106 }
3107 24 $seenSomething++;
3108 }
3109 416 ▶ if ($seenSomething) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seenSomething) 33 383 416
3110 # new field
3111 33 ▶ if (!$v_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v_ref) 32 1 33
3112 32 ▶ if ($ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'is_bound'}) { } 0 32 32
3113 0 $v_ref = $self->__bound_field($ctx, $fnum, 0);
3114 } else {
3115 32 $value = '';
3116 32 $v_ref = \$value;
3117 }
3118 32 $fnum++;
3119 32 ▶ return unless $v_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $v_ref 0 32 32
3120 32 $ctx->{flag} = 0;
3121 32 $ctx->{fld_idx}++;
3122 }
3123 33 ▶ if ($ctx->{blank_is_undef} or $ctx->{empty_is_undef}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'blank_is_undef'} or $ctx->{'empty_is_undef'}) { } 9 24 33
Condition100%3/3
$ctx->{"blank_is_undef"} or $ctx->{"empty_is_undef"}
l!l&&r!l&&!r
5424
MC/DC100%2/2
$ctx->{"blank_is_undef"} or $ctx->{"empty_is_undef"}
$ctx->{"blank_is_undef"} $ctx->{"empty_is_undef"}
Truth table100%3/3
A or B
A= $ctx->{"blank_is_undef"}B= $ctx->{"empty_is_undef"}
ABresult
1X1
011
000
3124 9 $$v_ref = undef;
3125 } else {
3126 24 $$v_ref = "";
3127 }
3128 33 ▶ unless ($ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"is_bound"}) 33 0 33
3129 33 push @$fields, $$v_ref;
3130 }
3131 33 ▶ if ($ctx->{keep_meta_info} and $fflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"keep_meta_info"} and $fflags) 3 30 33
Condition66%2/3
$ctx->{"keep_meta_info"} and $fflags
!ll&&!rl&&r
3003
MC/DC50%1/2
$ctx->{"keep_meta_info"} and $fflags
$ctx->{"keep_meta_info"} $fflags
Truth table66%2/3
A and B
A= $ctx->{"keep_meta_info"}B= $fflags
ABresult
0X0
100
111
3132 3 push @$fflags, $ctx->{flag};
3133 }
3134 33 return 1;
3135 }
3136 383 $self->SetDiag(2012);
3137 383 return;
3138 }
3139  
3140 55 ▶ if ($ctx->{flag} & IS_QUOTED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"flag"} & 1) 14 41 55
3141 14 $self->__error_inside_quotes($ctx, 2027);
3142 13 return;
3143 }
3144  
3145 41 ▶ if ($v_ref) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v_ref) { } 41 0 41
elsif ($ctx->{'flag'} == 0 and $fnum == 1 and $ctx->{'skip_empty_rows'} == 1) { } 0 0 0
3146 41 $self->__push_value($ctx, $v_ref, $fields, $fflags, $ctx->{flag}, $fnum);
3147 ▶ } elsif ($ctx->{flag} == 0 && $fnum == 1 && $ctx->{skip_empty_rows} == 1) {
Condition0%0/6
$ctx->{"flag"} == 0 and $fnum == 1 and $ctx->{"skip_empty_rows"} == 1
!ll&&!rl&&r
000
$ctx->{"flag"} == 0 and $fnum == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$ctx->{"flag"} == 0 and $fnum == 1 and $ctx->{"skip_empty_rows"} == 1
$ctx->{"flag"} == 0 $fnum == 1 $ctx->{"skip_empty_rows"} == 1
Truth table0%0/4
A and B and C
A= $ctx->{"flag"} == 0B= $fnum == 1C= $ctx->{"skip_empty_rows"} == 1
ABCresult
0XX0
10X0
1100
1111
3148 0 return undef;
3149 }
3150 41 return 1;
3151 }
3152  
3153 6988 ▶sub __get_from_src {
Subroutine __get_from_src: called CC=14 SCAR=26.4
3154 6988 my ($self, $ctx, $src) = @_;
3155 6988 ▶ return 1 if defined $ctx->{tmp} and $ctx->{used} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctx->{"tmp"} and $ctx->{"used"} <= 0 2183 4805 6988
Condition100%3/3
defined $ctx->{"tmp"} and $ctx->{"used"} <= 0
!ll&&!rl&&r
284919562183
MC/DC100%2/2
defined $ctx->{"tmp"} and $ctx->{"used"} <= 0
defined $ctx->{"tmp"} $ctx->{"used"} <= 0
Truth table100%3/3
A and B
A= defined $ctx->{"tmp"}B= $ctx->{"used"} <= 0
ABresult
0X0
100
111
3156 4805 ▶ return 1 if $ctx->{used} < $ctx->{size};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"used"} < $ctx->{"size"} 0 4805 4805
3157 4805 ▶ return unless $ctx->{useIO};
Branch: 1 branch
BranchTrueFalseTotal
unless $ctx->{"useIO"} 1368 3437 4805
3158 3437 my $res = $src->getline;
3159 3437 ▶ if (defined $res) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $res) { } 2852 585 3437
elsif (delete $ctx->{'has_leftover'}) { } 147 438 585
3160 2852 ▶ if ($ctx->{has_ahead}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'has_ahead'}) { } 4 2848 2852
3161 4 $ctx->{tmp} = $self->{_AHEAD};
3162 4 ▶ $ctx->{tmp} .= $ctx->{eol} if $ctx->{eol_len};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"eol_len"} 2 2 4
3163 4 $ctx->{tmp} .= $res;
3164 4 $ctx->{has_ahead} = 0;
3165 } else {
3166 2848 $ctx->{tmp} = $res;
3167 }
3168 2852 ▶ if ($ctx->{size} = length $ctx->{tmp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"size"} = length $ctx->{"tmp"}) 2852 0 2852
3169 2852 $ctx->{used} = -1;
3170 2852 ▶ $ctx->{utf8} = 1 if utf8::is_utf8($ctx->{tmp});
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($ctx->{"tmp"}) 70 2782 2852
3171 2852 pos($ctx->{tmp}) = 0;
3172 2852 return 1;
3173 }
3174 } elsif (delete $ctx->{has_leftover}) {
3175 147 $ctx->{tmp} = $self->{_AHEAD};
3176 147 $ctx->{has_ahead} = 0;
3177 147 $ctx->{useIO} |= useIO_EOF;
3178 147 ▶ if ($ctx->{size} = length $ctx->{tmp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"size"} = length $ctx->{"tmp"}) 147 0 147
3179 147 $ctx->{used} = -1;
3180 147 ▶ $ctx->{utf8} = 1 if utf8::is_utf8($ctx->{tmp});
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($ctx->{"tmp"}) 0 147 147
3181 147 pos($ctx->{tmp}) = 0;
3182 147 return 1;
3183 }
3184 }
3185 438 ▶ $ctx->{tmp} = '' unless defined $ctx->{tmp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctx->{"tmp"} 374 64 438
3186 438 $ctx->{useIO} |= useIO_EOF;
3187 438 return;
3188 }
3189  
3190 43 ▶sub __set_eol_is_cr {
Subroutine __set_eol_is_cr: called CC=1 SCAR=0.0
3191 43 my ($self, $ctx) = @_;
3192 43 $ctx->{eol_is_cr} = 1;
3193 43 $ctx->{eol_len} = 1;
3194 43 $ctx->{eol} = "\015";
3195 43 $ctx->{eol_type} = EOL_TYPE_CR;
3196 43 %{$self->{_CACHE}} = %$ctx;
3197  
3198 43 $self->{eol} = $ctx->{eol};
3199 }
3200  
3201 166 ▶sub __bound_field {
Subroutine __bound_field: called CC=6 SCAR=18.0
3202 166 my ($self, $ctx, $i, $keep) = @_;
3203 166 ▶ if ($i >= $ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $ctx->{"is_bound"}) 3 163 166
3204 3 $self->SetDiag(3006);
3205 3 return;
3206 }
3207 163 ▶ if (ref $ctx->{bound} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ctx->{"bound"} eq "ARRAY") 163 0 163
3208 163 my $ref = $ctx->{bound}[$i];
3209 163 ▶ if (ref $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref) 163 0 163
3210 163 ▶ if ($keep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keep) 14 149 163
3211 14 return $ref;
3212 }
3213 149 ▶ unless (Scalar::Util::readonly($$ref)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Scalar::Util::readonly($$ref)) 148 1 149
3214 148 $$ref = "";
3215 148 return $ref;
3216 }
3217 }
3218 }
3219 1 $self->SetDiag(3008);
3220 1 return;
3221 }
3222  
3223 17891 ▶sub __get {
Subroutine __get: called CC=7 SCAR=20.8
3224 17891 my ($self, $ctx, $src) = @_;
3225 17891 ▶ return unless defined $ctx->{used};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctx->{"used"} 0 17891 17891
3226 17891 ▶ if ($ctx->{used} >= $ctx->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"used"} >= $ctx->{"size"}) 1395 16496 17891
3227 1395 ▶ if ($self->__get_from_src($ctx, $src)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__get_from_src($ctx, $src)) 52 1343 1395
3228 52 return $self->__get($ctx, $src);
3229 }
3230 1343 return;
3231 }
3232 16496 my $pos = pos($ctx->{tmp});
3233 16496 ▶ if ($ctx->{tmp} =~ /\G($ctx->{_re}|.)/gs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'tmp'} =~ /\G($ctx->{'_re'}|.)/gs) { } 16496 0 16496
3234 16496 my $c = $1;
3235 16496 ▶ if ($c =~ /[^\x09\012\015\x20-\x7e]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /[^\x09\012\015\x20-\x7e]/) 1222 15274 16496
3236 1222 $ctx->{flag} |= IS_BINARY;
3237 }
3238 16496 $ctx->{used} = pos($ctx->{tmp});
3239 16496 return $c;
3240 } else {
3241 0 ▶ if ($self->__get_from_src($ctx, $src)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__get_from_src($ctx, $src)) 0 0 0
3242 0 return $self->__get($ctx, $src);
3243 }
3244 0 pos($ctx->{tmp}) = $pos;
3245 0 return;
3246 }
3247 }
3248  
3249 194 ▶sub __error_inside_quotes {
Subroutine __error_inside_quotes: called CC=1 SCAR=0.0
3250 194 my ($self, $ctx, $error) = @_;
3251 194 $self->__parse_error($ctx, $error, $ctx->{used} - 1);
3252 }
3253  
3254 86 ▶sub __error_inside_field {
Subroutine __error_inside_field: called CC=1 SCAR=0.0
3255 86 my ($self, $ctx, $error) = @_;
3256 86 $self->__parse_error($ctx, $error, $ctx->{used} - 1);
3257 }
3258  
3259 370 ▶sub __parse_error {
Subroutine __parse_error: called CC=3 SCAR=11.4
3260 370 my ($self, $ctx, $error, $pos, $line) = @_;
3261 370 ▶ $line ||= (caller(1))[2];
Condition33%1/3
$line ||= (caller 1)[2]
l!l&&r!l&&!r
03700
MC/DC0%0/2
$line ||= (caller 1)[2]
$line (caller 1)[2]
Truth table33%1/3
A ||= B
A= $lineB= (caller 1)[2]
ABresult
1X1
011
000
3262 370 $self->{_ERROR_POS} = $pos;
3263 370 $self->{_ERROR_FLD} = $ctx->{fld_idx};
3264 370 ▶ $self->{_ERROR_INPUT} = $ctx->{tmp} if $ctx->{tmp};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"tmp"} 370 0 370
3265 370 $self->_set_diag($ctx, $error, $line);
3266 367 return;
3267 }
3268  
3269 109 ▶sub __error_eol {
Subroutine __error_eol: called CC=4 SCAR=13.9
3270 109 my ($self, $ctx) = @_;
3271 109 ▶ unless ($ctx->{strict_eol} & 0x40) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"strict_eol"} & 64) 61 48 109
3272 61 $self->__parse_error($ctx, 2016, $ctx->{used} - 1);
3273 }
3274 109 ▶ if ($ctx->{strict_eol} & 0x0e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"strict_eol"} & 14) 7 102 109
3275 7 ▶ if (!$ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"is_bound"}) 7 0 7
3276 7 return;
3277 }
3278 }
3279 102 $ctx->{strict_eol} |= 0x40;
3280 }
3281  
3282 5094 ▶sub __is_whitespace {
Subroutine __is_whitespace: called CC=9 SCAR=22.6
3283 5094 my ($self, $ctx, $c) = @_;
3284 5094 ▶ return unless defined $c;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 535 4559 5094
3285 return (
3286 (!defined $ctx->{sep} or $c ne $ctx->{sep}) &&
3287 (!defined $ctx->{quo} or $c ne $ctx->{quo}) &&
3288 4559 ▶ (!defined $ctx->{escape_char} or $c ne $ctx->{escape_char}) &&
Condition76%16/21
(!defined($ctx->{'sep'}) || $c ne $ctx->{'sep'}) && (!defined($ctx->{'quo'}) || $c ne $ctx->{'quo'}) && (!defined($ctx->{'escape_char'}) || $c ne $ctx->{'escape_char'}) && ($c eq ' ' || $c eq "\t")
!ll&&!rl&&r
3805313441
!defined($ctx->{"sep"}) || $c ne $ctx->{"sep"} and !defined($ctx->{"quo"}) || $c ne $ctx->{"quo"} and !defined($ctx->{"escape_char"}) || $c ne $ctx->{"escape_char"}
!ll&&!rl&&r
38050754
!defined($ctx->{"sep"}) || $c ne $ctx->{"sep"} and !defined($ctx->{"quo"}) || $c ne $ctx->{"quo"}
!ll&&!rl&&r
3486319754
not defined $ctx->{"sep"} or $c ne $ctx->{"sep"}
l!l&&r!l&&!r
010733486
not defined $ctx->{"quo"} or $c ne $ctx->{"quo"}
l!l&&r!l&&!r
0754319
not defined $ctx->{"escape_char"} or $c ne $ctx->{"escape_char"}
l!l&&r!l&&!r
07540
$c eq " " or $c eq "\t"
l!l&&r!l&&!r
42021313
MC/DC50%4/8
(!defined($ctx->{'sep'}) || $c ne $ctx->{'sep'}) && (!defined($ctx->{'quo'}) || $c ne $ctx->{'quo'}) && (!defined($ctx->{'escape_char'}) || $c ne $ctx->{'escape_char'}) && ($c eq ' ' || $c eq "\t")
not defined $ctx->{"sep"} $c ne $ctx->{"sep"} not defined $ctx->{"quo"} $c ne $ctx->{"quo"} not defined $ctx->{"escape_char"} $c ne $ctx->{"escape_char"} $c eq " " $c eq "\t"
Truth table16%5/31
not(A) or B and not(C) or D and not(E) or F && G or H
A= not defined $ctx->{"sep"}B= $c ne $ctx->{"sep"}C= not defined $ctx->{"quo"}D= $c ne $ctx->{"quo"}E= not defined $ctx->{"escape_char"}F= $c ne $ctx->{"escape_char"}G= $c eq " "H= $c eq "\t"
ABCDEFGHresult
00XXXXXX0
1X00XXXX0
0100XXXX0
1X1X00XX0
1X0100XX0
011X00XX0
010100XX0
1X1X1X000
1X1X01000
1X011X000
1X0101000
011X1X000
011X01000
01011X000
010101000
1X1X1X1X1
1X1X1X011
1X1X011X1
1X1X01011
1X011X1X1
1X011X011
1X01011X1
1X0101011
011X1X1X1
011X1X011
011X011X1
011X01011
01011X1X1
01011X011
0101011X1
010101011
3289 ($c eq " " or $c eq "\t")
3290 );
3291 }
3292  
3293 22189 ▶sub __push_value { # AV_PUSH (part of)
Subroutine __push_value: called CC=20 SCAR=30.1
3294 22189 my ($self, $ctx, $v_ref, $fields, $fflags, $flag, $fnum) = @_;
3295 22189 ▶ utf8::encode($$v_ref) if $ctx->{utf8};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"utf8"} 206 21983 22189
3296 22189 ▶ if ($ctx->{formula} && defined $$v_ref && substr($$v_ref, 0, 1) eq '=') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"formula"} and defined $$v_ref and substr($$v_ref, 0, 1) eq "=") 27 22162 22189
Condition83%5/6
$ctx->{"formula"} and defined $$v_ref and substr($$v_ref, 0, 1) eq "="
!ll&&!rl&&r
2205510727
$ctx->{"formula"} and defined $$v_ref
!ll&&!rl&&r
220550134
MC/DC66%2/3
$ctx->{"formula"} and defined $$v_ref and substr($$v_ref, 0, 1) eq "="
$ctx->{"formula"} defined $$v_ref substr($$v_ref, 0, 1) eq "="
Truth table75%3/4
A and B and C
A= $ctx->{"formula"}B= defined $$v_refC= substr($$v_ref, 0, 1) eq "="
ABCresult
0XX0
10X0
1100
1111
3297 27 my $value = $self->_formula($ctx, $$v_ref, $fnum);
3298 25 ▶ push @$fields, defined $value ? $value : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 22 3 25
3299 25 return;
3300 }
3301 22162 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($$v_ref) || $$v_ref eq '' and $ctx->{'empty_is_undef'} || !($flag & 1) && $ctx->{'blank_is_undef'}) { } 12 22150 22162
Condition75%9/12
!defined($$v_ref) || $$v_ref eq "" and $ctx->{"empty_is_undef"} || !($flag & 1) && $ctx->{"blank_is_undef"}
!ll&&!rl&&r
2140075012
not defined $$v_ref or $$v_ref eq ""
l!l&&r!l&&!r
076221400
$ctx->{"empty_is_undef"} or not $flag & 1 and $ctx->{"blank_is_undef"}
l!l&&r!l&&!r
120750
not $flag & 1 and $ctx->{"blank_is_undef"}
!ll&&!rl&&r
724260
MC/DC40%2/5
!defined($$v_ref) || $$v_ref eq "" and $ctx->{"empty_is_undef"} || !($flag & 1) && $ctx->{"blank_is_undef"}
not defined $$v_ref $$v_ref eq "" $ctx->{"empty_is_undef"} not $flag & 1 $ctx->{"blank_is_undef"}
Truth table44%4/9
not(A) or B and C or not(D) and E
A= not defined $$v_refB= $$v_ref eq ""C= $ctx->{"empty_is_undef"}D= not $flag & 1E= $ctx->{"blank_is_undef"}
ABCDEresult
00XXX0
1X00X0
1X0100
0100X0
010100
1X1XX1
1X0111
011XX1
010111
3302 (!defined $$v_ref or $$v_ref eq '') and
3303 ($ctx->{empty_is_undef} or (!($flag & IS_QUOTED) and $ctx->{blank_is_undef}))
3304 ) {
3305 12 $$v_ref = undef;
3306 } else {
3307 22150 ▶ if ($ctx->{allow_whitespace} && !($flag & IS_QUOTED)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"allow_whitespace"} and not $flag & 1) 1747 20403 22150
Condition100%3/3
$ctx->{"allow_whitespace"} and not $flag & 1
!ll&&!rl&&r
1639140121747
MC/DC100%2/2
$ctx->{"allow_whitespace"} and not $flag & 1
$ctx->{"allow_whitespace"} not $flag & 1
Truth table100%3/3
A and not(B)
A= $ctx->{"allow_whitespace"}B= not $flag & 1
ABresult
0X0
100
111
3308 1747 $$v_ref =~ s/[ \t]+$//;
3309 }
3310 22150 ▶ if ($flag & IS_BINARY and $ctx->{decode_utf8} and ($ctx->{utf8} || _is_valid_utf8($$v_ref))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 2 and $ctx->{"decode_utf8"} and $ctx->{"utf8"} || _is_valid_utf8($$v_ref)) 2182 19968 22150
Condition88%8/9
$flag & 2 and $ctx->{"decode_utf8"} and $ctx->{"utf8"} || _is_valid_utf8($$v_ref)
!ll&&!rl&&r
1839715712182
$flag & 2 and $ctx->{"decode_utf8"}
!ll&&!rl&&r
1839703753
$ctx->{"utf8"} or _is_valid_utf8($$v_ref)
l!l&&r!l&&!r
7521071571
MC/DC75%3/4
$flag & 2 and $ctx->{"decode_utf8"} and $ctx->{"utf8"} || _is_valid_utf8($$v_ref)
$flag & 2 $ctx->{"decode_utf8"} $ctx->{"utf8"} _is_valid_utf8($$v_ref)
Truth table80%4/5
A and B and C or D
A= $flag & 2B= $ctx->{"decode_utf8"}C= $ctx->{"utf8"}D= _is_valid_utf8($$v_ref)
ABCDresult
0XXX0
10XX0
11000
111X1
11011
3311 2182 utf8::decode($$v_ref);
3312 }
3313 }
3314 22162 ▶ unless ($ctx->{is_bound}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"is_bound"}) 22016 146 22162
3315 22016 push @$fields, $$v_ref;
3316 }
3317 22162 ▶ if ($ctx->{keep_meta_info} and $fflags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"keep_meta_info"} and $fflags) 88 22074 22162
Condition66%2/3
$ctx->{"keep_meta_info"} and $fflags
!ll&&!rl&&r
22074088
MC/DC50%1/2
$ctx->{"keep_meta_info"} and $fflags
$ctx->{"keep_meta_info"} $fflags
Truth table66%2/3
A and B
A= $ctx->{"keep_meta_info"}B= $fflags
ABresult
0X0
100
111
3318 88 push @$fflags, $flag;
3319 }
3320 }
3321  
3322 1958 ▶sub getline {
Subroutine getline: called CC=2 SCAR=6.9
Pod documented
3323 1958 my ($self, $io) = @_;
3324  
3325 1958 my (@fields, @fflags);
3326 1958 my $res = $self->__parse(\@fields, \@fflags, $io, 1);
3327 1956 ▶ $res ? \@fields : undef;
Branch: 1 branch
BranchTrueFalseTotal
$res ? : 1781 175 1956
3328 }
3329  
3330 358 ▶sub getline_all {
Subroutine getline_all: called CC=15 SCAR=27.1
Pod documented
3331 358 my ($self, $io, $offset, $len) = @_;
3332  
3333 358 my $ctx = $self->_setup_ctx;
3334  
3335 358 my $tail = 0;
3336 358 my $n = 0;
3337 358 ▶ $offset ||= 0;
Condition100%2/2
$offset ||= 0
l!l
28330
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
3338  
3339 358 ▶ if ($offset < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < 0) 12 346 358
3340 12 $tail = -$offset;
3341 12 $offset = -1;
3342 }
3343  
3344 358 my (@row, @list);
3345 358 ▶ while ($self->___parse($ctx, \@row, undef, $io, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->___parse($ctx, \@row, undef, $io, 1)) 796 320 1116
3346 796 $ctx = $self->_setup_ctx;
3347  
3348 796 ▶ if ($offset > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset > 0) 20 776 796
3349 20 $offset--;
3350 20 @row = ();
3351 20 next;
3352 }
3353 776 ▶ if ($n++ >= $tail and $tail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n++ >= $tail and $tail) 12 764 776
Condition100%3/3
$n++ >= $tail and $tail
!ll&&!rl&&r
3672812
MC/DC100%2/2
$n++ >= $tail and $tail
$n++ >= $tail $tail
Truth table100%3/3
A and B
A= $n++ >= $tailB= $tail
ABresult
0X0
100
111
3354 12 shift @list;
3355 12 $n--;
3356 }
3357 776 ▶ if (($ctx->{has_hooks} || 0) & HOOK_AFTER_PARSE) {
Branch: 1 branch
BranchTrueFalseTotal
if (($ctx->{"has_hooks"} || 0) & 2) 138 638 776
Condition100%2/2
$ctx->{'has_hooks'} || 0
l!l
141635
MC/DC100%1/1
$ctx->{'has_hooks'} || 0
$ctx->{'has_hooks'}
Truth table100%2/2
A
A= $ctx->{'has_hooks'}
Aresult
11
00
3358 138 ▶ unless ($self->_hook(after_parse => \@row)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_hook("after_parse", \@row)) 63 75 138
3359 63 @row = ();
3360 63 next;
3361 }
3362 }
3363 713 push @list, [@row];
3364 713 @row = ();
3365  
3366 713 ▶ last if defined $len && $n >= $len and $offset >= 0; # exceeds limit size
Branch: 1 branch
BranchTrueFalseTotal
if defined $len and $n >= $len and $offset >= 0 32 681 713
Condition100%6/6
defined $len and $n >= $len and $offset >= 0
!ll&&!rl&&r
6612032
defined $len and $n >= $len
!ll&&!rl&&r
6174452
MC/DC100%3/3
defined $len and $n >= $len and $offset >= 0
defined $len $n >= $len $offset >= 0
Truth table100%4/4
A and B and C
A= defined $lenB= $n >= $lenC= $offset >= 0
ABCresult
0XX0
10X0
1100
1111
3367 }
3368  
3369 352 ▶ if (defined $len && $n > $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $len and $n > $len) 8 344 352
Condition100%3/3
defined $len and $n > $len
!ll&&!rl&&r
308368
MC/DC100%2/2
defined $len and $n > $len
defined $len $n > $len
Truth table100%3/3
A and B
A= defined $lenB= $n > $len
ABresult
0X0
100
111
3370 8 @list = splice(@list, 0, $len);
3371 }
3372  
3373 352 return \@list;
3374 }
3375  
3376 3759 ▶sub _is_valid_utf8 {
Subroutine _is_valid_utf8: called CC=2 SCAR=6.9
3377 3759 ▶ return ($_[0] =~ /^(?:
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^(?: [\x00-\x7F] |[\xC2-\xDF][\x80-\xBF] |[\xE0][\xA0-\xBF][\x80-\xBF] |[\xE1-\xEC][\x80-\xBF][\x80-\xBF] |[\xED][\x80-\x9F][\x80-\xBF] |[\xEE-\xEF][\x80-\xBF][\x80-\xBF] |[\xF0][\x90-\xBF][\x80-\xBF][\x80-\xBF] |[\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF] |[\xF4][\x80-\x8F][\x80-\xBF][\x80-\xBF] )+$/x ? : 2120 1639 3759
3378 [\x00-\x7F]
3379 |[\xC2-\xDF][\x80-\xBF]
3380 |[\xE0][\xA0-\xBF][\x80-\xBF]
3381 |[\xE1-\xEC][\x80-\xBF][\x80-\xBF]
3382 |[\xED][\x80-\x9F][\x80-\xBF]
3383 |[\xEE-\xEF][\x80-\xBF][\x80-\xBF]
3384 |[\xF0][\x90-\xBF][\x80-\xBF][\x80-\xBF]
3385 |[\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF]
3386 |[\xF4][\x80-\x8F][\x80-\xBF][\x80-\xBF]
3387 )+$/x) ? 1 : 0;
3388 }
3389  
3390 ################################################################################
3391 # methods for errors
3392 ################################################################################
3393  
3394 1 ▶sub _set_error_diag {
Subroutine _set_error_diag: called CC=2 SCAR=7.4
3395 1 my ($self, $error, $pos) = @_;
3396  
3397 1 $self->SetDiag($error);
3398  
3399 1 ▶ if (defined $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 0 1 1
3400 0 $_[0]->{_ERROR_POS} = $pos;
3401 }
3402  
3403 1 return;
3404 }
3405  
3406 8 ▶sub error_input {
Subroutine error_input: called CC=5 SCAR=16.1
Pod documented
3407 8 my $self = shift;
3408 8 ▶ if ($self and ((Scalar::Util::reftype($self) || '') eq 'HASH' or (ref $self) =~ /^Text::CSV/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self and (builtin::reftype($self) || "") eq "HASH" || ref($self) =~ /^Text::CSV/) 4 4 8
Condition87%7/8
$self and (builtin::reftype($self) || "") eq "HASH" || ref($self) =~ /^Text::CSV/
!ll&&!rl&&r
224
(builtin::reftype($self) || "") eq "HASH" or ref($self) =~ /^Text::CSV/
l!l&&r!l&&!r
402
builtin::reftype($self) || ''
l!l
51
MC/DC66%2/3
$self and (builtin::reftype($self) || "") eq "HASH" || ref($self) =~ /^Text::CSV/
$self builtin::reftype($self) ref($self) =~ /^Text::CSV/
Truth table75%3/4
A and B or C
A= $selfB= builtin::reftype($self)C= ref($self) =~ /^Text::CSV/
ABCresult
0XX0
1000
11X1
1011
3409 4 return $self->{_ERROR_INPUT};
3410 }
3411 4 return;
3412 }
3413  
3414 3902 ▶sub _sv_diag {
Subroutine _sv_diag: called CC=1 SCAR=0.0
3415 3902 my ($self, $error) = @_;
3416 3902 bless [$error, $ERRORS->{$error}], 'Text::CSV::ErrorDiag';
3417 }
3418  
3419 1820 ▶sub _set_diag {
Subroutine _set_diag: called CC=5 SCAR=16.1
3420 1820 my ($self, $ctx, $error, $line) = @_;
3421  
3422 1820 $last_error = $self->_sv_diag($error);
3423 1820 $self->{_ERROR_DIAG} = $last_error;
3424 1820 ▶ if ($error == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error == 0) 6 1814 1820
3425 6 $self->{_ERROR_POS} = 0;
3426 6 $self->{_ERROR_FLD} = 0;
3427 6 $self->{_ERROR_INPUT} = undef;
3428 6 $ctx->{has_error_input} = 0;
3429 }
3430 1820 ▶ if ($line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line) 370 1450 1820
3431 370 $self->{_ERROR_SRC} = $line;
3432 }
3433 1820 ▶ if ($error == 2012) { # EOF
Branch: 1 branch
BranchTrueFalseTotal
if ($error == 2012) 384 1436 1820
3434 384 $self->{_EOF} = 1;
3435 }
3436 1820 ▶ if ($ctx->{auto_diag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"auto_diag"}) 387 1433 1820
3437 387 $self->error_diag;
3438 }
3439 1817 return $last_error;
3440 }
3441  
3442 3532 ▶sub SetDiag {
Subroutine SetDiag: called CC=3 SCAR=11.0
Pod documented
3443 3532 my ($self, $error, $errstr) = @_;
3444 3532 my $res;
3445 3532 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 1450 2082 3532
3446 1450 my $ctx = $self->_setup_ctx;
3447 1450 $res = $self->_set_diag($ctx, $error);
3448 } else {
3449 2082 $last_error = $error;
3450 2082 $res = $self->_sv_diag($error);
3451 }
3452 3532 ▶ if (defined $errstr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $errstr) 1032 2500 3532
3453 1032 $res->[1] = $errstr;
3454 }
3455 3532 $res;
3456 }
3457  
3458 ################################################################################
3459 package Text::CSV::ErrorDiag;
3460  
3461 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3462 39 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
3463 39 '""' => \&stringify,
3464 '+' => \&numeric,
3465 '-' => \&numeric,
3466 '*' => \&numeric,
3467 '/' => \&numeric,
3468 fallback => 1,
3469 39 );
3470  
3471 4707 ▶sub numeric {
Subroutine numeric: called CC=2 SCAR=7.2
3472 4707 my ($left, $right) = @_;
3473 4707 ▶ return ref $left ? $left->[0] : $right->[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $left ? : 4707 0 4707
3474 }
3475  
3476 2719 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
3477 2719 $_[0]->[1];
3478 }
3479 ################################################################################
3480 39 1;
3481 __END__
↑ Summary CSV.pm »