blib/lib/Text/CSV_XS.pm

filter: Statementstmt 84.2% 965 / 1145 Branchbran 81.2% 749 / 922 Conditioncond 78.3% 427 / 544 (1 uncoverable) MC/DCmcdc 67.0% 210 / 313 Subroutinesub 81.8% 90 / 110 Podpod 100% 82 / 82 totaltotal 80.9% 2523 / 3116 (1 uncoverable) CC 1167 SCAR 41.5
CC
1167
Cov
82%
new
157.3
new
157.3
csv
142.7
CRAP 63.2
↑ Summary CSV_XS.xs »
1 package Text::CSV_XS;
2  
3 # Copyright (c) 2007-2026 H.Merijn Brand. All rights reserved.
4 # Copyright (c) 1998-2001 Jochen Wiedmann. All rights reserved.
5 # Copyright (c) 1997 Alan Citterman. All rights reserved.
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9  
10 # HISTORY
11 #
12 # 0.24 - H.Merijn Brand <perl5@tux.freedom.nl>
13 # 0.10 - 0.23 Jochen Wiedmann <joe@ispsoft.de>
14 # Based on (the original) Text::CSV by Alan Citterman <alan@mfgrtl.com>
15  
16 36 require 5.008001;
17  
18 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 36 require Exporter;
22 36 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 36 ▶use vars qw( $VERSION @ISA @EXPORT_OK %EXPORT_TAGS );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 $VERSION = "1.65";
27 36 @ISA = qw( Exporter );
28 36 XSLoader::load ("Text::CSV_XS", $VERSION);
29  
30 4 ▶sub PV { 0 } sub CSV_TYPE_PV { PV }
Subroutine CSV_TYPE_PV: called CC=1 SCAR=0.0
Subroutine PV: called CC=1 SCAR=0.0
Pod documented
Pod documented
31 4 ▶sub IV { 1 } sub CSV_TYPE_IV { IV }
Subroutine CSV_TYPE_IV: called CC=1 SCAR=0.0
Subroutine IV: called CC=1 SCAR=0.0
Pod documented
Pod documented
32 4 ▶sub NV { 2 } sub CSV_TYPE_NV { NV }
Subroutine CSV_TYPE_NV: called CC=1 SCAR=0.0
Subroutine NV: called CC=1 SCAR=0.0
Pod documented
Pod documented
33  
34 11 ▶sub CSV_FLAGS_IS_QUOTED { 0x0001 }
Subroutine CSV_FLAGS_IS_QUOTED: called CC=1 SCAR=0.0
Pod documented
35 12 ▶sub CSV_FLAGS_IS_BINARY { 0x0002 }
Subroutine CSV_FLAGS_IS_BINARY: called CC=1 SCAR=0.0
Pod documented
36 4 ▶sub CSV_FLAGS_ERROR_IN_FIELD { 0x0004 }
Subroutine CSV_FLAGS_ERROR_IN_FIELD: called CC=1 SCAR=0.0
Pod documented
37 20 ▶sub CSV_FLAGS_IS_MISSING { 0x0010 }
Subroutine CSV_FLAGS_IS_MISSING: called CC=1 SCAR=0.0
Pod documented
38  
39 36 %EXPORT_TAGS = (
40 CONSTANTS => [qw(
41 CSV_FLAGS_IS_QUOTED
42 CSV_FLAGS_IS_BINARY
43 CSV_FLAGS_ERROR_IN_FIELD
44 CSV_FLAGS_IS_MISSING
45  
46 CSV_TYPE_PV
47 CSV_TYPE_IV
48 CSV_TYPE_NV
49 )],
50 );
51 36 @EXPORT_OK = (qw( csv PV IV NV ), @{$EXPORT_TAGS{'CONSTANTS'}});
52  
53 36 ▶if ($] < 5.008002) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.008002") 0 36 36
54 36 ▶ no warnings "redefine";
Subroutine BEGIN: called CC=1 SCAR=0.0
55 0 ▶ *utf8::decode = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 }
57  
58 # version
59 #
60 # class/object method expecting no arguments and returning the version
61 # number of Text::CSV. there are no side-effects.
62  
63 2 ▶sub version {
Subroutine version: called CC=1 SCAR=1.2
Pod documented
64 0 ▶ return $VERSION;
Subroutine version: not called CC=1 SCAR=1.2
Pod documented
65 } # version
66  
67 # new
68 #
69 # class/object method expecting no arguments and returning a reference to
70 # a newly created Text::CSV object.
71  
72 36 my %def_attr = (
73 'eol' => '',
74 'sep_char' => ',',
75 'quote_char' => '"',
76 'escape_char' => '"',
77 'binary' => 0,
78 'decode_utf8' => 1,
79 'auto_diag' => 0,
80 'diag_verbose' => 0,
81 'strict' => 0,
82 'strict_eol' => 0,
83 'blank_is_undef' => 0,
84 'empty_is_undef' => 0,
85 'allow_whitespace' => 0,
86 'allow_loose_quotes' => 0,
87 'allow_loose_escapes' => 0,
88 'allow_unquoted_escape' => 0,
89 'always_quote' => 0,
90 'quote_empty' => 0,
91 'quote_space' => 1,
92 'quote_binary' => 1,
93 'escape_null' => 1,
94 'keep_meta_info' => 0,
95 'verbatim' => 0,
96 'formula' => 0,
97 'skip_empty_rows' => 0,
98 'undef_str' => undef,
99 'comment_str' => undef,
100 'types' => undef,
101 'callbacks' => undef,
102  
103 '_EOF' => "",
104 '_RECNO' => 0,
105 '_STATUS' => undef,
106 '_FIELDS' => undef,
107 '_FFLAGS' => undef,
108 '_STRING' => undef,
109 '_ERROR_INPUT' => undef,
110 '_COLUMN_NAMES' => undef,
111 '_BOUND_COLUMNS' => undef,
112 '_AHEAD' => undef,
113 '_FORMULA_CB' => undef,
114 '_EMPTROW_CB' => undef,
115  
116 'ENCODING' => undef,
117 );
118 36 my %attr_alias = (
119 'quote_always' => "always_quote",
120 'verbose_diag' => "diag_verbose",
121 'quote_null' => "escape_null",
122 'escape' => "escape_char",
123 'comment' => "comment_str",
124 );
125 36 my $last_err = Text::CSV_XS->SetDiag (0);
126 36 my $ebcdic = ord ("A") == 0xC1; # Faster than $Config{'ebcdic'}
127 36 my @internal_kh;
128  
129 # NOT a method: is also used before bless
130 15772 ▶sub _unhealthy_whitespace {
Subroutine _unhealthy_whitespace: called CC=8 SCAR=27.7
131 0 ▶ my ($self, $aw) = @_;
Subroutine _unhealthy_whitespace: not called CC=8 SCAR=27.7
132 0 ▶ $aw or return 0; # no checks needed without allow_whitespace
Branch: 2 branches
BranchTrueFalseTotal
$aw or return 0 3571 12201 15772
$aw or return 0 0 0 0
133  
134 0 my $quo = $self->{'quote'};
135 0 ▶ defined $quo && length ($quo) or $quo = $self->{'quote_char'};
Branch: 2 branches
BranchTrueFalseTotal
defined $quo and length $quo or $quo = $self->{"quote_char"} 2 3569 3571
defined $quo and length $quo or $quo = $self->{"quote_char"} 0 0 0
Condition50%3/6
defined $quo and length $quo
!ll&&!rl&&r
356632
defined $quo and length $quo
!ll&&!rl&&r
000
MC/DC100%2/2
defined $quo and length $quo
defined $quo length $quo
MC/DC0%0/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
Truth table0%0/3
A and B
A= defined $quoB= length $quo
ABresult
0X0
100
111
136 0 my $esc = $self->{'escape_char'};
137  
138 0 ▶ defined $quo && $quo =~ m/^[ \t]/ and return 1002;
Branch: 2 branches
BranchTrueFalseTotal
defined $quo and $quo =~ /^[ \t]/ and return 1002 242 3329 3571
defined $quo and $quo =~ /^[ \t]/ and return 1002 0 0 0
Condition50%3/6
defined $quo and $quo =~ /^[ \t]/
!ll&&!rl&&r
23327242
defined $quo and $quo =~ /^[ \t]/
!ll&&!rl&&r
000
MC/DC100%2/2
defined $quo and $quo =~ /^[ \t]/
defined $quo $quo =~ /^[ \t]/
MC/DC0%0/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
Truth table0%0/3
A and B
A= defined $quoB= $quo =~ /^[ \t]/
ABresult
0X0
100
111
139 0 ▶ defined $esc && $esc =~ m/^[ \t]/ and return 1002;
Branch: 2 branches
BranchTrueFalseTotal
defined $esc and $esc =~ /^[ \t]/ and return 1002 290 3039 3329
defined $esc and $esc =~ /^[ \t]/ and return 1002 0 0 0
Condition50%3/6
defined $esc and $esc =~ /^[ \t]/
!ll&&!rl&&r
43035290
defined $esc and $esc =~ /^[ \t]/
!ll&&!rl&&r
000
MC/DC100%2/2
defined $esc and $esc =~ /^[ \t]/
defined $esc $esc =~ /^[ \t]/
MC/DC0%0/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
Truth table0%0/3
A and B
A= defined $escB= $esc =~ /^[ \t]/
ABresult
0X0
100
111
140  
141 0 return 0;
142 } # _unhealty_whitespace
143  
144 12466 ▶sub _check_sanity {
Subroutine _check_sanity: called CC=17 SCAR=39.7
145 0 ▶ my $self = shift;
Subroutine _check_sanity: not called CC=17 SCAR=39.7
146  
147 0 my $eol = $self->{'eol'};
148 0 my $sep = $self->{'sep'};
149 0 ▶ defined $sep && length ($sep) or $sep = $self->{'sep_char'};
Branch: 2 branches
BranchTrueFalseTotal
defined $sep and length $sep or $sep = $self->{"sep_char"} 35 12431 12466
defined $sep and length $sep or $sep = $self->{"sep_char"} 0 0 0
Condition50%3/6
defined $sep and length $sep
!ll&&!rl&&r
1201241935
defined $sep and length $sep
!ll&&!rl&&r
000
MC/DC100%2/2
defined $sep and length $sep
defined $sep length $sep
MC/DC0%0/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
Truth table0%0/3
A and B
A= defined $sepB= length $sep
ABresult
0X0
100
111
150 0 my $quo = $self->{'quote'};
151 0 ▶ defined $quo && length ($quo) or $quo = $self->{'quote_char'};
Branch: 2 branches
BranchTrueFalseTotal
defined $quo and length $quo or $quo = $self->{"quote_char"} 18 12448 12466
defined $quo and length $quo or $quo = $self->{"quote_char"} 0 0 0
Condition50%3/6
defined $quo and length $quo
!ll&&!rl&&r
124341418
defined $quo and length $quo
!ll&&!rl&&r
000
MC/DC100%2/2
defined $quo and length $quo
defined $quo length $quo
MC/DC0%0/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
Truth table0%0/3
A and B
A= defined $quoB= length $quo
ABresult
0X0
100
111
152 0 my $esc = $self->{'escape_char'};
153  
154 # use DP;::diag ("SEP: '", DPeek ($sep),
155 # "', QUO: '", DPeek ($quo),
156 # "', ESC: '", DPeek ($esc),"'");
157  
158 # sep_char should not be undefined
159 0 ▶ $sep ne "" or return 1008;
Branch: 2 branches
BranchTrueFalseTotal
$sep ne "" or return 1008 12464 2 12466
$sep ne "" or return 1008 0 0 0
160 0 ▶ length ($sep) > 16 and return 1006;
Branch: 2 branches
BranchTrueFalseTotal
length $sep > 16 and return 1006 1 12463 12464
length $sep > 16 and return 1006 0 0 0
161 0 ▶ $sep =~ m/[\r\n]/ and return 1003;
Branch: 2 branches
BranchTrueFalseTotal
$sep =~ /[\r\n]/ and return 1003 6 12457 12463
$sep =~ /[\r\n]/ and return 1003 0 0 0
162  
163 0 ▶ if (defined $quo) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $quo) 12447 10 12457
if (defined $quo) 0 0 0
164 0 ▶ $quo eq $sep and return 1001;
Branch: 2 branches
BranchTrueFalseTotal
$quo eq $sep and return 1001 228 12219 12447
$quo eq $sep and return 1001 0 0 0
165 0 ▶ length ($quo) > 16 and return 1007;
Branch: 2 branches
BranchTrueFalseTotal
length $quo > 16 and return 1007 1 12218 12219
length $quo > 16 and return 1007 0 0 0
166 0 ▶ $quo =~ m/[\r\n]/ and return 1003;
Branch: 2 branches
BranchTrueFalseTotal
$quo =~ /[\r\n]/ and return 1003 6 12212 12218
$quo =~ /[\r\n]/ and return 1003 0 0 0
167 }
168 0 ▶ if (defined $esc) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $esc) 12206 16 12222
if (defined $esc) 0 0 0
169 0 ▶ $esc eq $sep and return 1001;
Branch: 2 branches
BranchTrueFalseTotal
$esc eq $sep and return 1001 168 12038 12206
$esc eq $sep and return 1001 0 0 0
170 0 ▶ $esc =~ m/[\r\n]/ and return 1003;
Branch: 2 branches
BranchTrueFalseTotal
$esc =~ /[\r\n]/ and return 1003 6 12032 12038
$esc =~ /[\r\n]/ and return 1003 0 0 0
171 }
172 0 ▶ if (defined $eol) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $eol) 12043 5 12048
if (defined $eol) 0 0 0
173 0 ▶ length ($eol) > 16 and return 1005;
Branch: 2 branches
BranchTrueFalseTotal
length $eol > 16 and return 1005 1 12042 12043
length $eol > 16 and return 1005 0 0 0
174 }
175  
176 0 return _unhealthy_whitespace ($self, $self->{'allow_whitespace'});
177 } # _check_sanity
178  
179 3 ▶sub known_attributes {
Subroutine known_attributes: called CC=1 SCAR=1.2
Pod documented
180 0 ▶ sort grep !m/^_/ => "sep", "quote", keys %def_attr;
Subroutine known_attributes: not called CC=1 SCAR=1.2
Pod documented
181 } # known_attributes
182  
183 1040 ▶sub new {
Subroutine new: called CC=31 SCAR=50.6
Pod documented
184 0 ▶ $last_err = Text::CSV_XS->SetDiag (1000,
Subroutine new: not called CC=31 SCAR=50.6
Pod documented
185 "usage: my \$csv = Text::CSV_XS->new ([{ option => value, ... }]);");
186  
187 0 my $proto = shift;
188 0 ▶ my $class = ref $proto || $proto or return;
Branch: 2 branches
BranchTrueFalseTotal
my $class = ref $proto || $proto or return 1039 1 1040
my $class = ref $proto || $proto or return 0 0 0
Condition50%3/6
ref $proto || $proto
l!l&&r!l&&!r
210371
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC100%2/2
ref $proto || $proto
ref $proto $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table100%3/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
189 0 ▶ @_ > 0 && ref $_[0] ne "HASH" and return;
Branch: 2 branches
BranchTrueFalseTotal
@_ > 0 and ref $_[0] ne "HASH" and return 8 1031 1039
@_ > 0 and ref $_[0] ne "HASH" and return 0 0 0
Condition50%3/6
@_ > 0 and ref $_[0] ne "HASH"
!ll&&!rl&&r
1019308
@_ > 0 and ref $_[0] ne "HASH"
!ll&&!rl&&r
000
MC/DC100%2/2
@_ > 0 and ref $_[0] ne "HASH"
@_ > 0 ref $_[0] ne "HASH"
MC/DC0%0/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
Truth table0%0/3
A and B
A= @_ > 0B= ref $_[0] ne "HASH"
ABresult
0X0
100
111
190 0 ▶ my $attr = shift || +{};
Condition50%2/4
shift() || {}
l!l
930101
shift() || {}
l!l
00
MC/DC100%1/1
shift() || {}
shift()
MC/DC0%0/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
Truth table0%0/2
A
A= shift()
Aresult
11
00
191 my %attr = map {
192 0 ▶ my $k = m/^[a-zA-Z]\w+$/ ? lc $_ : $_;
Branch: 2 branches
BranchTrueFalseTotal
/^[a-zA-Z]\w+$/ ? : 2797 1 2798
/^[a-zA-Z]\w+$/ ? : 0 0 0
193 0 ▶ exists $attr_alias{$k} and $k = $attr_alias{$k};
Branch: 2 branches
BranchTrueFalseTotal
exists $attr_alias{$k} and $k = $attr_alias{$k} 21 2777 2798
exists $attr_alias{$k} and $k = $attr_alias{$k} 0 0 0
194 0 ($k => $attr->{$_});
195 0 } keys %{$attr};
196  
197 0 my $sep_aliased = 0;
198 0 ▶ if (exists $attr{'sep'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $attr{"sep"}) 10 1021 1031
if (exists $attr{"sep"}) 0 0 0
199 0 $attr{'sep_char'} = delete $attr{'sep'};
200 0 $sep_aliased = 1;
201 }
202 0 my $quote_aliased = 0;
203 0 ▶ if (exists $attr{'quote'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $attr{"quote"}) 25 1006 1031
if (exists $attr{"quote"}) 0 0 0
204 0 $attr{'quote_char'} = delete $attr{'quote'};
205 0 $quote_aliased = 1;
206 }
207 exists $attr{'formula_handling'} and
208 0 ▶ $attr{'formula'} = delete $attr{'formula_handling'};
Branch: 2 branches
BranchTrueFalseTotal
exists $attr{"formula_handling"} and $attr{"formula"} = delete $attr{"formula_handling"} 12 1019 1031
exists $attr{"formula_handling"} and $attr{"formula"} = delete $attr{"formula_handling"} 0 0 0
209 0 my $attr_formula = delete $attr{'formula'};
210  
211 0 for (keys %attr) {
212 0 ▶ if (m/^[a-z]/ && exists $def_attr{$_}) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^[a-z]/ and exists $def_attr{$_}) 2753 7 2760
if (/^[a-z]/ and exists $def_attr{$_}) 0 0 0
Condition50%3/6
/^[a-z]/ and exists $def_attr{$_}
!ll&&!rl&&r
162753
/^[a-z]/ and exists $def_attr{$_}
!ll&&!rl&&r
000
MC/DC100%2/2
/^[a-z]/ and exists $def_attr{$_}
/^[a-z]/ exists $def_attr{$_}
MC/DC0%0/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
Truth table0%0/3
A and B
A= /^[a-z]/B= exists $def_attr{$_}
ABresult
0X0
100
111
213 # uncoverable condition false
214 0 ▶ defined $attr{$_} && m/_char$/ and utf8::decode ($attr{$_});
Branch: 2 branches
BranchTrueFalseTotal
defined $attr{$_} and /_char$/ and utf8::decode($attr{$_}) 202 2551 2753
defined $attr{$_} and /_char$/ and utf8::decode($attr{$_}) 0 0 0
Condition33%3/6
defined $attr{$_} and /_char$/
!ll&&!rl&&r
212530202
defined $attr{$_} and /_char$/
!ll&&!rl&&r
000
MC/DC100%2/2
defined $attr{$_} and /_char$/
defined $attr{$_} /_char$/
MC/DC0%0/2
defined $attr{$_} and /_char$/
defined $attr{$_} /_char$/
Truth table66%3/3
A and B
A= defined $attr{$_}B= /_char$/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $attr{$_}B= /_char$/
ABresult
0X0
100
111
215 0 next;
216 }
217 # croak?
218 0 $last_err = Text::CSV_XS->SetDiag (1000, "INI - Unknown attribute '$_'");
219 0 ▶ $attr{'auto_diag'} and error_diag ();
Branch: 2 branches
BranchTrueFalseTotal
$attr{"auto_diag"} and error_diag() 1 6 7
$attr{"auto_diag"} and error_diag() 0 0 0
220 0 return;
221 }
222 0 ▶ if ($sep_aliased) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sep_aliased) 10 1014 1024
if ($sep_aliased) 0 0 0
223 0 my @b = unpack "U0C*", $attr{'sep_char'};
224 0 ▶ if (@b > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@b > 1) { } 6 4 10
if (@b > 1) { } 0 0 0
225 0 $attr{'sep'} = $attr{'sep_char'};
226 0 $attr{'sep_char'} = "\0";
227 }
228 else {
229 0 $attr{'sep'} = undef;
230 }
231 }
232 0 ▶ if ($quote_aliased and defined $attr{'quote_char'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($quote_aliased and defined $attr{"quote_char"}) 21 1003 1024
if ($quote_aliased and defined $attr{"quote_char"}) 0 0 0
Condition50%3/6
$quote_aliased and defined $attr{"quote_char"}
!ll&&!rl&&r
999421
$quote_aliased and defined $attr{"quote_char"}
!ll&&!rl&&r
000
MC/DC100%2/2
$quote_aliased and defined $attr{"quote_char"}
$quote_aliased defined $attr{"quote_char"}
MC/DC0%0/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
Truth table0%0/3
A and B
A= $quote_aliasedB= defined $attr{"quote_char"}
ABresult
0X0
100
111
233 0 my @b = unpack "U0C*", $attr{'quote_char'};
234 0 ▶ if (@b > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@b > 1) { } 7 14 21
if (@b > 1) { } 0 0 0
235 0 $attr{'quote'} = $attr{'quote_char'};
236 0 $attr{'quote_char'} = "\0";
237 }
238 else {
239 0 $attr{'quote'} = undef;
240 }
241 }
242  
243 0 my $self = { %def_attr, %attr };
244 0 ▶ if (my $ec = _check_sanity ($self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $ec = _check_sanity($self)) 35 989 1024
if (my $ec = _check_sanity($self)) 0 0 0
245 0 $last_err = Text::CSV_XS->SetDiag ($ec);
246 0 ▶ $attr{'auto_diag'} and error_diag ();
Branch: 2 branches
BranchTrueFalseTotal
$attr{"auto_diag"} and error_diag() 1 34 35
$attr{"auto_diag"} and error_diag() 0 0 0
247 0 return;
248 }
249 0 ▶ if (defined $self->{'callbacks'} && ref $self->{'callbacks'} ne "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{"callbacks"} and ref $self->{"callbacks"} ne "HASH") 6 983 989
if (defined $self->{"callbacks"} and ref $self->{"callbacks"} ne "HASH") 0 0 0
Condition50%3/6
defined $self->{"callbacks"} and ref $self->{"callbacks"} ne "HASH"
!ll&&!rl&&r
6583256
defined $self->{"callbacks"} and ref $self->{"callbacks"} ne "HASH"
!ll&&!rl&&r
000
MC/DC100%2/2
defined $self->{"callbacks"} and ref $self->{"callbacks"} ne "HASH"
defined $self->{"callbacks"} ref $self->{"callbacks"} ne "HASH"
MC/DC0%0/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
Truth table0%0/3
A and B
A= defined $self->{"callbacks"}B= ref $self->{"callbacks"} ne "HASH"
ABresult
0X0
100
111
250 0 carp ("The 'callbacks' attribute is set but is not a hash: ignored\n");
251 0 $self->{'callbacks'} = undef;
252 }
253  
254 0 $last_err = Text::CSV_XS->SetDiag (0);
255 0 ▶ defined $\ && !exists $attr{'eol'} and $self->{'eol'} = $\;
Branch: 2 branches
BranchTrueFalseTotal
defined $\ and not exists $attr{"eol"} and $self->{"eol"} = $\ 8 981 989
defined $\ and not exists $attr{"eol"} and $self->{"eol"} = $\ 0 0 0
Condition50%3/6
defined $\ and not exists $attr{"eol"}
!ll&&!rl&&r
97928
defined $\ and not exists $attr{"eol"}
!ll&&!rl&&r
000
MC/DC100%2/2
defined $\ and not exists $attr{"eol"}
defined $\ not exists $attr{"eol"}
MC/DC0%0/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
Truth table0%0/3
A and not(B)
A= defined $\B= not exists $attr{"eol"}
ABresult
0X0
100
111
256 0 bless $self, $class;
257 0 ▶ defined $self->{'types'} and $self->types ($self->{'types'});
Branch: 2 branches
BranchTrueFalseTotal
defined $self->{"types"} and $self->types($self->{"types"}) 1 988 989
defined $self->{"types"} and $self->types($self->{"types"}) 0 0 0
258 0 ▶ defined $self->{'skip_empty_rows'} and $self->{'skip_empty_rows'} = _supported_skip_empty_rows ($self, $self->{'skip_empty_rows'});
Branch: 2 branches
BranchTrueFalseTotal
defined $self->{"skip_empty_rows"} and $self->{"skip_empty_rows"} = _supported_skip_empty_rows($self, $self->{"skip_empty_rows"}) 989 0 989
defined $self->{"skip_empty_rows"} and $self->{"skip_empty_rows"} = _supported_skip_empty_rows($self, $self->{"skip_empty_rows"}) 0 0 0
259 0 ▶ defined $attr_formula and $self->{'formula'} = _supported_formula ($self, $attr_formula);
Branch: 2 branches
BranchTrueFalseTotal
defined $attr_formula and $self->{"formula"} = _supported_formula($self, $attr_formula) 36 953 989
defined $attr_formula and $self->{"formula"} = _supported_formula($self, $attr_formula) 0 0 0
260 0 $self;
261 } # new
262  
263 # Keep in sync with XS!
264 36 my %_cache_id = ( # Only expose what is accessed from within PM
265 'quote_char' => 0,
266 'escape_char' => 1,
267 'sep_char' => 2,
268 'always_quote' => 4,
269 'quote_empty' => 5,
270 'quote_space' => 6,
271 'quote_binary' => 7,
272 'allow_loose_quotes' => 8,
273 'allow_loose_escapes' => 9,
274 'allow_unquoted_escape' => 10,
275 'allow_whitespace' => 11,
276 'blank_is_undef' => 12,
277 'empty_is_undef' => 13,
278 'auto_diag' => 14,
279 'diag_verbose' => 15,
280 'escape_null' => 16,
281 'formula' => 18,
282 'decode_utf8' => 21,
283 'verbatim' => 23,
284 'strict_eol' => 24,
285 'strict' => 28,
286 'skip_empty_rows' => 29,
287 'binary' => 30,
288 'keep_meta_info' => 31,
289 '_has_hooks' => 32,
290 '_has_ahead' => 33,
291 '_is_bound' => 44,
292 'eol' => 100,
293 'sep' => 116,
294 'quote' => 132,
295 'undef_str' => 148,
296 'comment_str' => 156,
297 'types' => 92,
298 );
299  
300 # A `character'
301 11109 ▶sub _set_attr_C {
Subroutine _set_attr_C: called CC=3 SCAR=14.2
302 0 ▶ my ($self, $name, $val, $ec) = @_;
Subroutine _set_attr_C: not called CC=3 SCAR=14.2
303 0 ▶ defined $val and utf8::decode ($val);
Branch: 2 branches
BranchTrueFalseTotal
defined $val and utf8::decode($val) 11101 8 11109
defined $val and utf8::decode($val) 0 0 0
304 0 $self->{$name} = $val;
305 0 ▶ $ec = _check_sanity ($self) and croak ($self->SetDiag ($ec));
Branch: 2 branches
BranchTrueFalseTotal
$ec = _check_sanity($self) and croak($self->SetDiag($ec)) 910 10199 11109
$ec = _check_sanity($self) and croak($self->SetDiag($ec)) 0 0 0
306 0 $self->_cache_set ($_cache_id{$name}, $val);
307 } # _set_attr_C
308  
309 # A flag
310 5644 ▶sub _set_attr_X {
Subroutine _set_attr_X: called CC=2 SCAR=9.2
311 0 ▶ my ($self, $name, $val) = @_;
Subroutine _set_attr_X: not called CC=2 SCAR=9.2
312 0 ▶ defined $val or $val = 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $val or $val = 0 5643 1 5644
defined $val or $val = 0 0 0 0
313 0 $self->{$name} = $val;
314 0 $self->_cache_set ($_cache_id{$name}, 0 + $val);
315 } # _set_attr_X
316  
317 # A number
318 72 ▶sub _set_attr_N {
Subroutine _set_attr_N: called CC=1 SCAR=1.2
319 0 ▶ my ($self, $name, $val) = @_;
Subroutine _set_attr_N: not called CC=1 SCAR=1.2
320 0 $self->{$name} = $val;
321 0 $self->_cache_set ($_cache_id{$name}, 0 + $val);
322 } # _set_attr_N
323  
324 # Accessor methods.
325 # It is unwise to change them halfway through a single file!
326 4836 ▶sub quote_char {
Subroutine quote_char: called CC=2 SCAR=9.2
Pod documented
327 0 ▶ my $self = shift;
Subroutine quote_char: not called CC=2 SCAR=9.2
Pod documented
328 0 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 3601 1235 4836
if (@_) 0 0 0
329 0 $self->_set_attr_C ("quote_char", shift);
330 0 $self->_cache_set ($_cache_id{'quote'}, "");
331 }
332 0 $self->{'quote_char'};
333 } # quote_char
334  
335 20 ▶sub quote {
Subroutine quote: called CC=8 SCAR=27.7
Pod documented
336 0 ▶ my $self = shift;
Subroutine quote: not called CC=8 SCAR=27.7
Pod documented
337 0 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 11 9 20
if (@_) 0 0 0
338 0 my $quote = shift;
339 0 ▶ defined $quote or $quote = "";
Branch: 2 branches
BranchTrueFalseTotal
defined $quote or $quote = "" 10 1 11
defined $quote or $quote = "" 0 0 0
340 0 utf8::decode ($quote);
341 0 my @b = unpack "U0C*", $quote;
342 0 ▶ if (@b > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@b > 1) { } 5 6 11
if (@b > 1) { } 0 0 0
343 0 ▶ @b > 16 and croak ($self->SetDiag (1007));
Branch: 2 branches
BranchTrueFalseTotal
@b > 16 and croak($self->SetDiag(1007)) 1 4 5
@b > 16 and croak($self->SetDiag(1007)) 0 0 0
344 0 $self->quote_char ("\0");
345 }
346 else {
347 0 $self->quote_char ($quote);
348 0 $quote = "";
349 }
350 0 $self->{'quote'} = $quote;
351  
352 0 my $ec = _check_sanity ($self);
353 0 ▶ $ec and croak ($self->SetDiag ($ec));
Branch: 2 branches
BranchTrueFalseTotal
$ec and croak($self->SetDiag($ec)) 1 9 10
$ec and croak($self->SetDiag($ec)) 0 0 0
354  
355 0 $self->_cache_set ($_cache_id{'quote'}, $quote);
356 }
357 0 my $quote = $self->{'quote'};
358 0 ▶ defined $quote && length ($quote) ? $quote : $self->{'quote_char'};
Branch: 2 branches
BranchTrueFalseTotal
defined $quote && length $quote ? : 6 12 18
defined $quote && length $quote ? : 0 0 0
Condition50%3/6
defined $quote and length $quote
!ll&&!rl&&r
666
defined $quote and length $quote
!ll&&!rl&&r
000
MC/DC100%2/2
defined $quote and length $quote
defined $quote length $quote
MC/DC0%0/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
Truth table0%0/3
A and B
A= defined $quoteB= length $quote
ABresult
0X0
100
111
359 } # quote
360  
361 4826 ▶sub escape_char {
Subroutine escape_char: called CC=3 SCAR=14.2
Pod documented
362 0 ▶ my $self = shift;
Subroutine escape_char: not called CC=3 SCAR=14.2
Pod documented
363 0 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 3595 1231 4826
if (@_) 0 0 0
364 0 my $ec = shift;
365 0 $self->_set_attr_C ("escape_char", $ec);
366 0 ▶ $ec or $self->_set_attr_X ("escape_null", 0);
Branch: 2 branches
BranchTrueFalseTotal
$ec or $self->_set_attr_X("escape_null", 0) 3474 6 3480
$ec or $self->_set_attr_X("escape_null", 0) 0 0 0
367 }
368 0 $self->{'escape_char'};
369 } # escape_char
370  
371 5156 ▶sub sep_char {
Subroutine sep_char: called CC=2 SCAR=9.2
Pod documented
372 0 ▶ my $self = shift;
Subroutine sep_char: not called CC=2 SCAR=9.2
Pod documented
373 0 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 3913 1243 5156
if (@_) 0 0 0
374 0 $self->_set_attr_C ("sep_char", shift);
375 0 $self->_cache_set ($_cache_id{'sep'}, "");
376 }
377 0 $self->{'sep_char'};
378 } # sep_char
379  
380 360 ▶sub sep {
Subroutine sep: called CC=8 SCAR=27.7
Pod documented
381 0 ▶ my $self = shift;
Subroutine sep: not called CC=8 SCAR=27.7
Pod documented
382 0 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 327 33 360
if (@_) 0 0 0
383 0 my $sep = shift;
384 0 ▶ defined $sep or $sep = "";
Branch: 2 branches
BranchTrueFalseTotal
defined $sep or $sep = "" 326 1 327
defined $sep or $sep = "" 0 0 0
385 0 utf8::decode ($sep);
386 0 my @b = unpack "U0C*", $sep;
387 0 ▶ if (@b > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@b > 1) { } 13 314 327
if (@b > 1) { } 0 0 0
388 0 ▶ @b > 16 and croak ($self->SetDiag (1006));
Branch: 2 branches
BranchTrueFalseTotal
@b > 16 and croak($self->SetDiag(1006)) 1 12 13
@b > 16 and croak($self->SetDiag(1006)) 0 0 0
389 0 $self->sep_char ("\0");
390 }
391 else {
392 0 $self->sep_char ($sep);
393 0 $sep = "";
394 }
395 0 $self->{'sep'} = $sep;
396  
397 0 my $ec = _check_sanity ($self);
398 0 ▶ $ec and croak ($self->SetDiag ($ec));
Branch: 2 branches
BranchTrueFalseTotal
$ec and croak($self->SetDiag($ec)) 1 322 323
$ec and croak($self->SetDiag($ec)) 0 0 0
399  
400 0 $self->_cache_set ($_cache_id{'sep'}, $sep);
401 }
402 0 my $sep = $self->{'sep'};
403 0 ▶ defined $sep && length ($sep) ? $sep : $self->{'sep_char'};
Branch: 2 branches
BranchTrueFalseTotal
defined $sep && length $sep ? : 21 334 355
defined $sep && length $sep ? : 0 0 0
Condition50%3/6
defined $sep and length $sep
!ll&&!rl&&r
532921
defined $sep and length $sep
!ll&&!rl&&r
000
MC/DC100%2/2
defined $sep and length $sep
defined $sep length $sep
MC/DC0%0/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
Truth table0%0/3
A and B
A= defined $sepB= length $sep
ABresult
0X0
100
111
404 } # sep
405  
406 281 ▶sub eol {
Subroutine eol: called CC=4 SCAR=17.9
Pod documented
407 0 ▶ my $self = shift;
Subroutine eol: not called CC=4 SCAR=17.9
Pod documented
408 0 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 228 53 281
if (@_) 0 0 0
409 0 my $eol = shift;
410 0 ▶ defined $eol or $eol = ""; # Also reset strict_eol?
Branch: 2 branches
BranchTrueFalseTotal
defined $eol or $eol = "" 99 129 228
defined $eol or $eol = "" 0 0 0
411 0 ▶ length ($eol) > 16 and croak ($self->SetDiag (1005));
Branch: 2 branches
BranchTrueFalseTotal
length $eol > 16 and croak($self->SetDiag(1005)) 1 227 228
length $eol > 16 and croak($self->SetDiag(1005)) 0 0 0
412 0 $self->{'eol'} = $eol;
413 0 $self->_cache_set ($_cache_id{'eol'}, $eol);
414 }
415 0 $self->{'eol'};
416 } # eol
417  
418 32 ▶sub eol_type {
Subroutine eol_type: called CC=1 SCAR=1.2
Pod documented
419 0 ▶ my $self = shift;
Subroutine eol_type: not called CC=1 SCAR=1.2
Pod documented
420 0 $self->_cache_get_eolt;
421 } # eol_type
422  
423 3032 ▶sub always_quote {
Subroutine always_quote: called CC=2 SCAR=9.2
Pod documented
424 0 ▶ my $self = shift;
Subroutine always_quote: not called CC=2 SCAR=9.2
Pod documented
425 0 ▶ @_ and $self->_set_attr_X ("always_quote", shift);
Branch: 2 branches
BranchTrueFalseTotal
@_ and $self->_set_attr_X("always_quote", shift()) 1799 1233 3032
@_ and $self->_set_attr_X("always_quote", shift()) 0 0 0
426 0 $self->{'always_quote'};
427 } # always_quote
428  
429 10 ▶sub quote_space {
Subroutine quote_space: called CC=2 SCAR=9.2
Pod documented
430 0 ▶ my $self = shift;
Subroutine quote_space: not called CC=2 SCAR=9.2
Pod documented
431 0 ▶ @_ and $self->_set_attr_X ("quote_space", shift);
Branch: 2 branches
BranchTrueFalseTotal
@_ and $self->_set_attr_X("quote_space", shift()) 6 4 10
@_ and $self->_set_attr_X("quote_space", shift()) 0 0 0
432 0 $self->{'quote_space'};
433 } # quote_space
434  
435 5 ▶sub quote_empty {
Subroutine quote_empty: called CC=2 SCAR=9.2
Pod documented
436 0 ▶ my $self = shift;
Subroutine quote_empty: not called CC=2 SCAR=9.2
Pod documented
437 0 ▶ @_ and $self->_set_attr_X ("quote_empty", shift);
Branch: 2 branches
BranchTrueFalseTotal
@_ and $self->_set_attr_X("quote_empty", shift()) 3 2 5
@_ and $self->_set_attr_X("quote_empty", shift()) 0 0 0
438 0 $self->{'quote_empty'};
439 } # quote_empty
440  
441 6 ▶sub escape_null {
Subroutine escape_null: called CC=2 SCAR=9.2
Pod documented
442 0 ▶ my $self = shift;
Subroutine escape_null: not called CC=2 SCAR=9.2
Pod documented
443 0 ▶ @_ and $self->_set_attr_X ("escape_null", shift);
Branch: 2 branches
BranchTrueFalseTotal
@_ and $self->_set_attr_X("escape_null", shift()) 4 2 6
@_ and $self->_set_attr_X("escape_null", shift()) 0 0 0
444 0 $self->{'escape_null'};
445 } # escape_null
446 3 ▶sub quote_null { goto &escape_null; }
Subroutine quote_null: called CC=1 SCAR=0.0
Pod documented
447  
448 7 ▶sub quote_binary {
Subroutine quote_binary: called CC=2 SCAR=6.9
Pod documented
449 7 my $self = shift;
450 7 ▶ @_ and $self->_set_attr_X ("quote_binary", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("quote_binary", shift()) 6 1 7
451 7 $self->{'quote_binary'};
452 } # quote_binary
453  
454 21 ▶sub binary {
Subroutine binary: called CC=2 SCAR=6.9
Pod documented
455 21 my $self = shift;
456 21 ▶ @_ and $self->_set_attr_X ("binary", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("binary", shift()) 12 9 21
457 21 $self->{'binary'};
458 } # binary
459  
460 2 ▶sub strict {
Subroutine strict: called CC=2 SCAR=6.9
Pod documented
461 2 my $self = shift;
462 2 ▶ @_ and $self->_set_attr_X ("strict", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("strict", shift()) 1 1 2
463 2 $self->{'strict'};
464 } # strict
465  
466 2 ▶sub strict_eol {
Subroutine strict_eol: called CC=2 SCAR=6.9
Pod documented
467 2 my $self = shift;
468 2 ▶ @_ and $self->_set_attr_X ("strict_eol", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("strict_eol", shift()) 1 1 2
469 2 $self->{'strict_eol'};
470 } # strict_eol
471  
472 1011 ▶sub _supported_skip_empty_rows {
Subroutine _supported_skip_empty_rows: called CC=14 SCAR=26.6
473 1011 my ($self, $f) = @_;
474 1011 ▶ defined $f or return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $f or return 0 1010 1 1011
475 1010 ▶ 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 1005 1010
Condition77%7/9
$self and $f and ref $f and ref $f eq "CODE"
!ll&&!rl&&r
100505
$self and $f and ref $f
!ll&&!rl&&r
945605
$self and $f
!ll&&!rl&&r
094565
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
476 5 $self->{'_EMPTROW_CB'} = $f;
477 5 return 6;
478 }
479 $f =~ m/^(?: 0 | undef )$/xi ? 0 :
480 $f =~ m/^(?: 1 | skip )$/xi ? 1 :
481 $f =~ m/^(?: 2 | eof | stop )$/xi ? 2 :
482 $f =~ m/^(?: 3 | die )$/xi ? 3 :
483 $f =~ m/^(?: 4 | croak )$/xi ? 4 :
484 $f =~ m/^(?: 5 | error )$/xi ? 5 :
485 1005 ▶ $f =~ m/^(?: 6 | cb )$/xi ? 6 : do {
Branch: 7 branches
BranchTrueFalseTotal
$f =~ /^(?: 0 | undef )$/xi ? : 945 60 1005
$f =~ /^(?: 1 | skip )$/xi ? : 34 26 60
$f =~ /^(?: 2 | eof | stop )$/xi ? : 8 18 26
$f =~ /^(?: 3 | die )$/xi ? : 6 12 18
$f =~ /^(?: 4 | croak )$/xi ? : 6 6 12
$f =~ /^(?: 5 | error )$/xi ? : 5 1 6
$f =~ /^(?: 6 | cb )$/xi ? : 0 1 1
486 1 ▶ $self ||= "Text::CSV_XS";
Condition50%1/2
$self ||= "Text::CSV_XS"
l!l
10
MC/DC0%0/1
$self ||= "Text::CSV_XS"
$self
Truth table50%1/2
A
A= $self
Aresult
11
00
487 1 croak ($self->_SetDiagInfo (1500, "skip_empty_rows '$f' is not supported"));
488 };
489 } # _supported_skip_empty_rows
490  
491 24 ▶sub skip_empty_rows {
Subroutine skip_empty_rows: called CC=8 SCAR=20.8
Pod documented
492 24 my $self = shift;
493 24 ▶ @_ 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())) 22 2 24
494 23 my $ser = $self->{'skip_empty_rows'};
495 23 ▶ $ser == 6 or $self->{'_EMPTROW_CB'} = undef;
Branch: 1 branch
BranchTrueFalseTotal
$ser == 6 or $self->{"_EMPTROW_CB"} = undef 1 22 23
496 $ser <= 1 ? $ser : $ser == 2 ? "eof" : $ser == 3 ? "die" :
497 $ser == 4 ? "croak" : $ser == 5 ? "error" :
498 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
499 } # skip_empty_rows
500  
501 18 ▶sub _SetDiagInfo {
Subroutine _SetDiagInfo: called CC=3 SCAR=11.2
502 18 my ($self, $err, $msg) = @_;
503 18 $self->SetDiag ($err);
504 18 my $em = $self->error_diag ();
505 18 ▶ $em =~ s/^\d+$// and $msg =~ s/^/# /;
Branch: 1 branch
BranchTrueFalseTotal
$em =~ s/^\d+$// and $msg =~ s/^/# / 0 18 18
506 18 ▶ my $sep = $em =~ m/[;\n]$/ ? "\n\t" : ": ";
Branch: 1 branch
BranchTrueFalseTotal
$em =~ /[;\n]$/ ? : 0 18 18
507 18 join $sep => grep m/\S\S\S/ => $em, $msg;
508 } # _SetDiagInfo
509  
510 103 ▶sub _supported_formula {
Subroutine _supported_formula: called CC=14 SCAR=26.4
511 103 my ($self, $f) = @_;
512 103 ▶ defined $f or return 5;
Branch: 1 branch
BranchTrueFalseTotal
defined $f or return 5 102 1 103
513 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
514 6 $self->{'_FORMULA_CB'} = $f;
515 6 return 6;
516 }
517 $f =~ m/^(?: 0 | none )$/xi ? 0 :
518 $f =~ m/^(?: 1 | die )$/xi ? 1 :
519 $f =~ m/^(?: 2 | croak )$/xi ? 2 :
520 $f =~ m/^(?: 3 | diag )$/xi ? 3 :
521 $f =~ m/^(?: 4 | empty | )$/xi ? 4 :
522 $f =~ m/^(?: 5 | undef )$/xi ? 5 :
523 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
524 7 ▶ $self ||= "Text::CSV_XS";
Condition50%1/2
$self ||= "Text::CSV_XS"
l!l
70
MC/DC0%0/1
$self ||= "Text::CSV_XS"
$self
Truth table50%1/2
A
A= $self
Aresult
11
00
525 7 croak ($self->_SetDiagInfo (1500, "formula-handling '$f' is not supported"));
526 };
527 } # _supported_formula
528  
529 44 ▶sub formula {
Subroutine formula: called CC=3 SCAR=11.0
Pod documented
530 44 my $self = shift;
531 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
532 38 ▶ $self->{'formula'} == 6 or $self->{'_FORMULA_CB'} = undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"formula"} == 6 or $self->{"_FORMULA_CB"} = undef 2 36 38
533 38 [qw( none die croak diag empty undef cb )]->[_supported_formula ($self, $self->{'formula'})];
534 } # formula
535  
536 7 ▶sub formula_handling {
Subroutine formula_handling: called CC=1 SCAR=0.0
Pod documented
537 7 my $self = shift;
538 7 $self->formula (@_);
539 } # formula_handling
540  
541 2 ▶sub decode_utf8 {
Subroutine decode_utf8: called CC=2 SCAR=6.9
Pod documented
542 2 my $self = shift;
543 2 ▶ @_ and $self->_set_attr_X ("decode_utf8", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("decode_utf8", shift()) 1 1 2
544 2 $self->{'decode_utf8'};
545 } # decode_utf8
546  
547 12 ▶sub keep_meta_info {
Subroutine keep_meta_info: called CC=6 SCAR=17.9
Pod documented
548 12 my $self = shift;
549 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 1 12
550 11 my $v = shift;
551 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
552 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
553 11 $self->_set_attr_X ("keep_meta_info", $v);
554 }
555 12 $self->{'keep_meta_info'};
556 } # keep_meta_info
557  
558 12 ▶sub allow_loose_quotes {
Subroutine allow_loose_quotes: called CC=2 SCAR=6.9
Pod documented
559 12 my $self = shift;
560 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
561 12 $self->{'allow_loose_quotes'};
562 } # allow_loose_quotes
563  
564 12 ▶sub allow_loose_escapes {
Subroutine allow_loose_escapes: called CC=2 SCAR=6.9
Pod documented
565 12 my $self = shift;
566 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
567 12 $self->{'allow_loose_escapes'};
568 } # allow_loose_escapes
569  
570 4954 ▶sub allow_whitespace {
Subroutine allow_whitespace: called CC=3 SCAR=11.0
Pod documented
571 4954 my $self = shift;
572 4954 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3725 1229 4954
573 3725 my $aw = shift;
574 3725 ▶ _unhealthy_whitespace ($self, $aw) and
Branch: 1 branch
BranchTrueFalseTotal
_unhealthy_whitespace($self, $aw) and croak($self->SetDiag(1002)) 4 3721 3725
575 croak ($self->SetDiag (1002));
576 3721 $self->_set_attr_X ("allow_whitespace", $aw);
577 }
578 4950 $self->{'allow_whitespace'};
579 } # allow_whitespace
580  
581 3 ▶sub allow_unquoted_escape {
Subroutine allow_unquoted_escape: called CC=2 SCAR=6.9
Pod documented
582 3 my $self = shift;
583 3 ▶ @_ and $self->_set_attr_X ("allow_unquoted_escape", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("allow_unquoted_escape", shift()) 2 1 3
584 3 $self->{'allow_unquoted_escape'};
585 } # allow_unquoted_escape
586  
587 2 ▶sub blank_is_undef {
Subroutine blank_is_undef: called CC=2 SCAR=6.9
Pod documented
588 2 my $self = shift;
589 2 ▶ @_ and $self->_set_attr_X ("blank_is_undef", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("blank_is_undef", shift()) 1 1 2
590 2 $self->{'blank_is_undef'};
591 } # blank_is_undef
592  
593 2 ▶sub empty_is_undef {
Subroutine empty_is_undef: called CC=2 SCAR=6.9
Pod documented
594 2 my $self = shift;
595 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
596 2 $self->{'empty_is_undef'};
597 } # empty_is_undef
598  
599 9 ▶sub verbatim {
Subroutine verbatim: called CC=2 SCAR=6.9
Pod documented
600 9 my $self = shift;
601 9 ▶ @_ and $self->_set_attr_X ("verbatim", shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->_set_attr_X("verbatim", shift()) 7 2 9
602 9 $self->{'verbatim'};
603 } # verbatim
604  
605 13 ▶sub undef_str {
Subroutine undef_str: called CC=3 SCAR=11.0
Pod documented
606 13 my $self = shift;
607 13 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 12 1 13
608 12 my $v = shift;
609 12 ▶ $self->{'undef_str'} = defined $v ? "$v" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 10 2 12
610 12 $self->_cache_set ($_cache_id{'undef_str'}, $self->{'undef_str'});
611 }
612 13 $self->{'undef_str'};
613 } # undef_str
614  
615 15 ▶sub comment_str {
Subroutine comment_str: called CC=3 SCAR=11.0
Pod documented
616 15 my $self = shift;
617 15 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 1 15
618 14 my $v = shift;
619 14 ▶ $self->{'comment_str'} = defined $v ? "$v" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 13 1 14
620 14 $self->_cache_set ($_cache_id{'comment_str'}, $self->{'comment_str'});
621 }
622 15 $self->{'comment_str'};
623 } # comment_str
624  
625 12 ▶sub auto_diag {
Subroutine auto_diag: called CC=6 SCAR=17.9
Pod documented
626 12 my $self = shift;
627 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 9 3 12
628 9 my $v = shift;
629 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
630 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
631 9 $self->_set_attr_X ("auto_diag", $v);
632 }
633 12 $self->{'auto_diag'};
634 } # auto_diag
635  
636 10 ▶sub diag_verbose {
Subroutine diag_verbose: called CC=6 SCAR=17.9
Pod documented
637 10 my $self = shift;
638 10 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 2 10
639 8 my $v = shift;
640 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
641 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
642 8 $self->_set_attr_X ("diag_verbose", $v);
643 }
644 10 $self->{'diag_verbose'};
645 } # diag_verbose
646  
647 # status
648 #
649 # object method returning the success or failure of the most recent
650 # combine () or parse (). there are no side-effects.
651  
652 5 ▶sub status {
Subroutine status: called CC=1 SCAR=0.0
Pod documented
653 5 my $self = shift;
654 5 return $self->{'_STATUS'};
655 } # status
656  
657 34 ▶sub eof {
Subroutine eof: called CC=1 SCAR=0.0
Pod documented
658 34 my $self = shift;
659 34 return $self->{'_EOF'};
660 } # eof
661  
662 7 ▶sub types {
Subroutine types: called CC=3 SCAR=11.0
Pod documented
663 7 my $self = shift;
664 7 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 5 7
665 2 ▶ if (my $types = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $types = shift()) { } 1 1 2
666 1 $self->{'_types'} = join "", map { chr } @{$types};
667 1 $self->{'types'} = $types;
668 1 $self->_cache_set ($_cache_id{'types'}, $self->{'_types'});
669 }
670 else {
671 1 delete $self->{'types'};
672 1 delete $self->{'_types'};
673 1 $self->_cache_set ($_cache_id{'types'}, undef);
674 1 undef;
675 }
676 }
677 else {
678 5 $self->{'types'};
679 }
680 } # types
681  
682 75 ▶sub callbacks {
Subroutine callbacks: called CC=14 SCAR=26.4
Pod documented
683 75 my $self = shift;
684 75 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 45 30 75
685 45 my $cb;
686 45 my $hf = 0x00;
687 45 ▶ if (defined $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[0]) { } 43 2 45
elsif (@_ > 1) { } 1 1 2
688 43 ▶ grep { !defined } @_ and croak ($self->SetDiag (1004));
Branch: 1 branch
BranchTrueFalseTotal
grep {not defined $_;} @_ and croak($self->SetDiag(1004)) 2 41 43
689 41 ▶ $cb = @_ == 1 && ref $_[0] eq "HASH" ? shift
Branch: 2 branches
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'HASH' ? : 8 33 41
@_ % 2 == 0 ? : 28 5 33
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
2948
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
690 : @_ % 2 == 0 ? { @_ }
691 : croak ($self->SetDiag (1004));
692 36 foreach my $cbk (keys %{$cb}) {
693 # A key cannot be a ref. That would be stored as the *string
694 # 'SCALAR(0x1f3e710)' or 'ARRAY(0x1a5ae18)'
695 38 ▶ $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)) 24 14 38
Condition100%3/3
$cbk =~ /^[\w.]+$/ and ref $cb->{$cbk} eq "CODE"
!ll&&!rl&&r
41024
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
696 croak ($self->SetDiag (1004));
697 }
698 22 ▶ exists $cb->{'error'} and $hf |= 0x01;
Branch: 1 branch
BranchTrueFalseTotal
exists $cb->{"error"} and $hf |= 1 3 19 22
699 22 ▶ exists $cb->{'after_parse'} and $hf |= 0x02;
Branch: 1 branch
BranchTrueFalseTotal
exists $cb->{"after_parse"} and $hf |= 2 19 3 22
700 22 ▶ exists $cb->{'before_print'} and $hf |= 0x04;
Branch: 1 branch
BranchTrueFalseTotal
exists $cb->{"before_print"} and $hf |= 4 1 21 22
701 }
702 elsif (@_ > 1) {
703 # (undef, whatever)
704 1 croak ($self->SetDiag (1004));
705 }
706 23 $self->_set_attr_X ("_has_hooks", $hf);
707 23 $self->{'callbacks'} = $cb;
708 }
709 53 $self->{'callbacks'};
710 } # callbacks
711  
712 # error_diag
713 #
714 # If (and only if) an error occurred, this function returns a code that
715 # indicates the reason of failure
716  
717 1829 ▶sub error_diag {
Subroutine error_diag: called CC=31 SCAR=36.1
Pod documented
718 1829 my $self = shift;
719 1829 my @diag = (0 + $last_err, $last_err, 0, 0, 0, 0);
720  
721 # Docs state to NEVER use UNIVERSAL::isa, because it will *never* call an
722 # overridden isa method in any class. Well, that is exacly what I want here
723 1829 ▶ 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"})) 1650 179 1829
Condition100%9/9
$self and ref $self and (UNIVERSAL::isa($self, __PACKAGE__) and exists $self->{"_ERROR_DIAG"})
!ll&&!rl&&r
701091650
$self and ref $self
!ll&&!rl&&r
6641759
UNIVERSAL::isa($self, __PACKAGE__) and exists $self->{"_ERROR_DIAG"}
!ll&&!rl&&r
11081650
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
724 UNIVERSAL::isa ($self, __PACKAGE__) && exists $self->{'_ERROR_DIAG'}) {
725 1650 $diag[0] = 0 + $self->{'_ERROR_DIAG'};
726 1650 $diag[1] = $self->{'_ERROR_DIAG'};
727 1650 ▶ $diag[2] = 1 + $self->{'_ERROR_POS'} if exists $self->{'_ERROR_POS'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_ERROR_POS"} 306 1344 1650
728 1650 $diag[3] = $self->{'_RECNO'};
729 1650 ▶ $diag[4] = $self->{'_ERROR_FLD'} if exists $self->{'_ERROR_FLD'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_ERROR_FLD"} 306 1344 1650
730 1650 ▶ $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"} 64 1586 1650
Condition66%2/3
exists $self->{"_ERROR_SRC"} and $self->{"diag_verbose"}
!ll&&!rl&&r
0158664
MC/DC50%1/2
exists $self->{"_ERROR_SRC"} and $self->{"diag_verbose"}
exists $self->{"_ERROR_SRC"} $self->{"diag_verbose"}
Truth table66%2/3
A and B
A= exists $self->{"_ERROR_SRC"}B= $self->{"diag_verbose"}
ABresult
0X0
100
111
731  
732 $diag[0] && $self->{'callbacks'} && $self->{'callbacks'}{'error'} and
733 1650 ▶ 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 1640 1650
Condition100%6/6
$diag[0] and $self->{"callbacks"} and $self->{"callbacks"}{"error"}
!ll&&!rl&&r
136028010
$diag[0] and $self->{"callbacks"}
!ll&&!rl&&r
71353290
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
734 }
735  
736 1819 my $context = wantarray;
737 1819 ▶ unless (defined $context) { # Void context, auto-diag
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $context) 344 1475 1819
738 344 ▶ if ($diag[0] && $diag[0] != 2012) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diag[0] and $diag[0] != 2012) 36 308 344
Condition100%3/3
$diag[0] and $diag[0] != 2012
!ll&&!rl&&r
1029836
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
739 36 my $msg = "# CSV_XS ERROR: $diag[0] - $diag[1] \@ rec $diag[3] pos $diag[2]\n";
740 36 ▶ $diag[4] and $msg =~ s/$/ field $diag[4]/;
Branch: 1 branch
BranchTrueFalseTotal
$diag[4] and $msg =~ s/$/ field $diag[4]/ 25 11 36
741 36 ▶ $diag[5] and $msg =~ s/$/ (XS#$diag[5])/;
Branch: 1 branch
BranchTrueFalseTotal
$diag[5] and $msg =~ s/$/ (XS#$diag[5])/ 16 20 36
742  
743 36 ▶ unless ($self && ref $self) { # auto_diag
Branch: 1 branch
BranchTrueFalseTotal
unless ($self and ref $self) 4 32 36
Condition100%3/3
$self and ref $self
!ll&&!rl&&r
3132
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
744 # called without args in void context
745 4 warn $msg;
746 4 return;
747 }
748  
749 $self->{'diag_verbose'} && $self->{'_ERROR_INPUT'} and
750 32 ▶ $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 16 32
Condition66%2/3
$self->{"diag_verbose"} and $self->{"_ERROR_INPUT"}
!ll&&!rl&&r
16016
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
751 (" " x ($diag[2] - 1))."^\n";
752  
753 32 my $lvl = $self->{'auto_diag'};
754 32 ▶ if ($lvl < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lvl < 2) 29 3 32
755 29 my @c = caller (2);
756 29 ▶ 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 29 29
Condition50%3/6
@c >= 11 and $c[10] and ref $c[10] eq "HASH"
!ll&&!rl&&r
2900
@c >= 11 and $c[10]
!ll&&!rl&&r
18110
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
757 0 my $hints = $c[10];
758 (exists $hints->{'autodie'} && $hints->{'autodie'} or
759 exists $hints->{'guard Fatal'} &&
760 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
761 $lvl++;
762 # Future releases of autodie will probably set $^H{autodie}
763 # to "autodie @args", like "autodie :all" or "autodie open"
764 # so we can/should check for "open" or "new"
765 }
766 }
767 32 ▶ $lvl > 1 ? die $msg : warn $msg;
Branch: 1 branch
BranchTrueFalseTotal
$lvl > 1 ? : 3 29 32
768 }
769 337 return;
770 }
771 1475 ▶ return $context ? @diag : $diag[1];
Branch: 1 branch
BranchTrueFalseTotal
$context ? : 275 1200 1475
772 } # error_diag
773  
774 14 ▶sub record_number {
Subroutine record_number: called CC=1 SCAR=0.0
Pod documented
775 14 my $self = shift;
776 14 return $self->{'_RECNO'};
777 } # record_number
778  
779 # string
780 #
781 # object method returning the result of the most recent combine () or the
782 # input to the most recent parse (), whichever is more recent. there are
783 # no side-effects.
784  
785 1404 ▶sub string {
Subroutine string: called CC=2 SCAR=6.9
Pod documented
786 1404 my $self = shift;
787 1404 ▶ return ref $self->{'_STRING'} ? ${$self->{'_STRING'}} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_STRING'} ? : 1403 1 1404
788 } # string
789  
790 # fields
791 #
792 # object method returning the result of the most recent parse () or the
793 # input to the most recent combine (), whichever is more recent. there
794 # are no side-effects.
795  
796 1607 ▶sub fields {
Subroutine fields: called CC=2 SCAR=6.9
Pod documented
797 1607 my $self = shift;
798 1607 ▶ return ref $self->{'_FIELDS'} ? @{$self->{'_FIELDS'}} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_FIELDS'} ? : 1606 1 1607
799 } # fields
800  
801 # meta_info
802 #
803 # object method returning the result of the most recent parse () or the
804 # input to the most recent combine (), whichever is more recent. there
805 # are no side-effects. meta_info () returns (if available) some of the
806 # field's properties
807  
808 21 ▶sub meta_info {
Subroutine meta_info: called CC=2 SCAR=6.9
Pod documented
809 21 my $self = shift;
810 21 ▶ return ref $self->{'_FFLAGS'} ? @{$self->{'_FFLAGS'}} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_FFLAGS'} ? : 16 5 21
811 } # meta_info
812  
813 12 ▶sub is_quoted {
Subroutine is_quoted: called CC=5 SCAR=16.1
Pod documented
814 12 my ($self, $idx) = @_;
815 ref $self->{'_FFLAGS'} &&
816 12 ▶ $idx >= 0 && $idx < @{$self->{'_FFLAGS'}} or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"_FFLAGS"} and $idx >= 0 and $idx < @{$self->{"_FFLAGS"};} or return 7 5 12
Condition100%6/6
ref $self->{"_FFLAGS"} and $idx >= 0 and $idx < @{$self->{"_FFLAGS"};}
!ll&&!rl&&r
417
ref $self->{"_FFLAGS"} and $idx >= 0
!ll&&!rl&&r
318
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
817 7 ▶ $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_QUOTED () ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_QUOTED() ? : 3 4 7
818 } # is_quoted
819  
820 11 ▶sub is_binary {
Subroutine is_binary: called CC=5 SCAR=16.1
Pod documented
821 11 my ($self, $idx) = @_;
822 ref $self->{'_FFLAGS'} &&
823 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
824 8 ▶ $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_BINARY () ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_BINARY() ? : 4 4 8
825 } # is_binary
826  
827 19 ▶sub is_missing {
Subroutine is_missing: called CC=5 SCAR=16.1
Pod documented
828 19 my ($self, $idx) = @_;
829 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
830 11 ▶ $idx >= @{$self->{'_FFLAGS'}} and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$idx >= @{$self->{"_FFLAGS"};} and return 1 1 10 11
831 10 ▶ $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_MISSING () ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_MISSING() ? : 4 6 10
832 } # is_missing
833  
834 # combine
835 #
836 # Object method returning success or failure. The given arguments are
837 # combined into a single comma-separated value. Failure can be the
838 # result of no arguments or an argument containing an invalid character.
839 # side-effects include:
840 # setting status ()
841 # setting fields ()
842 # setting string ()
843 # setting error_input ()
844  
845 1403 ▶sub combine {
Subroutine combine: called CC=2 SCAR=6.9
Pod documented
846 1403 my $self = shift;
847 1403 my $str = "";
848 1403 $self->{'_FIELDS'} = \@_;
849 1403 ▶ $self->{'_STATUS'} = (@_ > 0) && $self->Combine (\$str, \@_, 0);
Condition100%3/3
@_ > 0 && $self->Combine(\$str, \@_, 0)
!ll&&!rl&&r
111401
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
850 1399 $self->{'_STRING'} = \$str;
851 1399 $self->{'_STATUS'};
852 } # combine
853  
854 # parse
855 #
856 # Object method returning success or failure. The given argument is
857 # expected to be a valid comma-separated value. Failure can be the
858 # result of no arguments or an argument containing an invalid sequence
859 # of characters. Side-effects include:
860 # setting status ()
861 # setting fields ()
862 # setting meta_info ()
863 # setting string ()
864 # setting error_input ()
865  
866 1956 ▶sub parse {
Subroutine parse: called CC=4 SCAR=13.9
Pod documented
867 1956 my ($self, $str) = @_;
868  
869 1956 ▶ ref $str and croak ($self->SetDiag (1500));
Branch: 1 branch
BranchTrueFalseTotal
ref $str and croak($self->SetDiag(1500)) 4 1952 1956
870  
871 1952 my $fields = [];
872 1952 my $fflags = [];
873 1952 $self->{'_STRING'} = \$str;
874 1952 ▶ if (defined $str && $self->Parse ($str, $fields, $fflags)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and $self->Parse($str, $fields, $fflags)) { } 1733 216 1949
Condition100%3/3
defined $str and $self->Parse($str, $fields, $fflags)
!ll&&!rl&&r
62101736
MC/DC100%2/2
defined $str and $self->Parse($str, $fields, $fflags)
defined $str $self->Parse($str, $fields, $fflags)
Truth table100%3/3
A and B
A= defined $strB= $self->Parse($str, $fields, $fflags)
ABresult
0X0
100
111
875 1733 $self->{'_FIELDS'} = $fields;
876 1733 $self->{'_FFLAGS'} = $fflags;
877 1733 $self->{'_STATUS'} = 1;
878 }
879 else {
880 216 $self->{'_FIELDS'} = undef;
881 216 $self->{'_FFLAGS'} = undef;
882 216 $self->{'_STATUS'} = 0;
883 }
884 1949 $self->{'_STATUS'};
885 } # parse
886  
887 1034 ▶sub column_names {
Subroutine column_names: called CC=12 SCAR=24.8
Pod documented
888 1034 my ($self, @keys) = @_;
889 @keys or
890 1034 ▶ return defined $self->{'_COLUMN_NAMES'} ? @{$self->{'_COLUMN_NAMES'}} : ();
Branch: 2 branches
BranchTrueFalseTotal
@keys or return defined $self->{"_COLUMN_NAMES"} ? @{$self->{"_COLUMN_NAMES"};} : () 690 344 1034
defined $self->{'_COLUMN_NAMES'} ? : 293 51 344
891  
892 @keys == 1 && ! defined $keys[0] and
893 690 ▶ return $self->{'_COLUMN_NAMES'} = undef;
Branch: 1 branch
BranchTrueFalseTotal
@keys == 1 and not defined $keys[0] and return $self->{"_COLUMN_NAMES"} = undef 138 552 690
Condition100%3/3
@keys == 1 and not defined $keys[0]
!ll&&!rl&&r
316236138
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
894  
895 552 ▶ if (@keys == 1 && ref $keys[0] eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (@keys == 1 and ref $keys[0] eq 'ARRAY') { } 227 325 552
elsif (join '', map({defined $_ ? ref $_ : '';} @keys)) { } 5 320 325
Condition100%3/3
@keys == 1 and ref $keys[0] eq "ARRAY"
!ll&&!rl&&r
3169227
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
896 227 @keys = @{$keys[0]};
897 }
898 714 ▶ elsif (join "", map { defined $_ ? ref $_ : "" } @keys) {
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 713 1 714
899 5 croak ($self->SetDiag (3001));
900 }
901  
902 547 ▶ $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 546 547
Condition100%3/3
$self->{"_BOUND_COLUMNS"} and @keys != @{$self->{"_BOUND_COLUMNS"};}
!ll&&!rl&&r
54511
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
903 croak ($self->SetDiag (3003));
904  
905 546 ▶ $self->{'_COLUMN_NAMES'} = [ map { defined $_ ? $_ : "\cAUNDEF\cA" } @keys ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1263 1 1264
906 546 @{$self->{'_COLUMN_NAMES'}};
907 } # column_names
908  
909 334 ▶sub header {
Subroutine header: called CC=63 SCAR=41.5
Pod documented
910 334 my ($self, $fh, @args) = @_;
911  
912 334 ▶ $fh or croak ($self->SetDiag (1014));
Branch: 1 branch
BranchTrueFalseTotal
$fh or croak($self->SetDiag(1014)) 333 1 334
913  
914 333 my (@seps, %args);
915 333 for (@args) {
916 225 ▶ if (ref $_ eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "ARRAY") 18 207 225
917 18 push @seps, @{$_};
918 18 next;
919 }
920 207 ▶ if (ref $_ eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq "HASH") 206 1 207
921 206 %args = %{$_};
922 206 next;
923 }
924 1 croak ('usage: $csv->header ($fh, [ seps ], { options })');
925 }
926  
927 defined $args{'munge'} && !defined $args{'munge_column_names'} and
928 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
929 332 ▶ defined $args{'detect_bom'} or $args{'detect_bom'} = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{"detect_bom"} or $args{"detect_bom"} = 1 162 170 332
930 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
931 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
932  
933 # Reset any previous leftovers
934 332 $self->{'_RECNO'} = 0;
935 332 $self->{'_AHEAD'} = undef;
936 332 ▶ $self->{'_COLUMN_NAMES'} = undef if $args{'set_column_names'};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"set_column_names"} 324 8 332
937 332 ▶ $self->{'_BOUND_COLUMNS'} = undef if $args{'set_column_names'};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"set_column_names"} 324 8 332
938  
939 332 ▶ if (defined $args{'sep_set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"sep_set"}) 27 305 332
940 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
941 croak ($self->_SetDiagInfo (1500, "sep_set should be an array ref"));
942 22 @seps = @{$args{'sep_set'}};
943 }
944  
945 327 ▶ $^O eq "MSWin32" and binmode $fh;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq "MSWin32" and binmode $fh 0 327 327
946 327 my $hdr = <$fh>;
947 # check if $hdr can be empty here, I don't think so
948 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
949  
950 325 my %sep;
951 325 ▶ @seps or @seps = (",", ";");
Branch: 1 branch
BranchTrueFalseTotal
@seps or @seps = (",", ";") 40 285 325
952 325 foreach my $sep (@seps) {
953 734 ▶ index ($hdr, $sep) >= 0 and $sep{$sep}++;
Branch: 1 branch
BranchTrueFalseTotal
index($hdr, $sep) != -1 and ++$sep{$sep} 322 412 734
954 }
955  
956 325 ▶ keys %sep >= 2 and croak ($self->SetDiag (1011));
Branch: 1 branch
BranchTrueFalseTotal
keys %sep >= 2 and croak($self->SetDiag(1011)) 4 321 325
957  
958 321 $self->sep (keys %sep);
959 321 my $enc = "";
960 321 ▶ if ($args{'detect_bom'}) { # UTF-7 is not supported
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"detect_bom"}) 320 1 321
961 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
962 24 elsif ($hdr =~ s/^\xff\xfe\x00\x00//) { $enc = "utf-32le" }
963 25 elsif ($hdr =~ s/^\xfe\xff//) { $enc = "utf-16be" }
964 24 elsif ($hdr =~ s/^\xff\xfe//) { $enc = "utf-16le" }
965 48 elsif ($hdr =~ s/^\xef\xbb\xbf//) { $enc = "utf-8" }
966 1 elsif ($hdr =~ s/^\xf7\x64\x4c//) { $enc = "utf-1" }
967 1 elsif ($hdr =~ s/^\xdd\x73\x66\x73//) { $enc = "utf-ebcdic" }
968 1 elsif ($hdr =~ s/^\x0e\xfe\xff//) { $enc = "scsu" }
969 1 elsif ($hdr =~ s/^\xfb\xee\x28//) { $enc = "bocu-1" }
970 1 elsif ($hdr =~ s/^\x84\x31\x95\x33//) { $enc = "gb-18030" }
971 36 elsif ($hdr =~ s/^\x{feff}//) { $enc = "" }
972  
973 320 ▶ $self->{'ENCODING'} = $enc ? uc $enc : undef;
Branch: 1 branch
BranchTrueFalseTotal
$enc ? : 150 170 320
974  
975 320 ▶ $hdr eq "" and croak ($self->SetDiag (1010));
Branch: 1 branch
BranchTrueFalseTotal
$hdr eq "" and croak($self->SetDiag(1010)) 6 314 320
976  
977 314 ▶ if ($enc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) 144 170 314
978 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
979 144 ▶ if ($enc =~ m/([13]).le$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc =~ /([13]).le$/) 48 96 144
980 48 my $l = 0 + $1;
981 48 my $x;
982 48 $hdr .= "\0" x $l;
983 48 read $fh, $x, $l;
984 }
985 144 ▶ if ($enc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) 144 0 144
986 144 ▶ if ($enc ne "utf-8") {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc ne "utf-8") 96 48 144
987 96 require Encode;
988 96 $hdr = Encode::decode ($enc, $hdr);
989 }
990 144 binmode $fh, ":encoding($enc)";
991 }
992 }
993 }
994  
995 315 my ($ahead, $eol);
996 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
997 1 $self->sep ($1);
998 1 ▶ length $hdr or $hdr = <$fh>;
Branch: 1 branch
BranchTrueFalseTotal
length $hdr or $hdr = readline $fh 0 1 1
999 }
1000 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) 143 172 315
1001 143 $eol = $2;
1002 143 $ahead = $3;
1003 }
1004  
1005 315 my $hr = \$hdr;
1006 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
1007  
1008 315 ▶ my $row = $self->getline ($h) or croak ();
Branch: 1 branch
BranchTrueFalseTotal
my $row = $self->getline($h) or croak() 313 2 315
1009 313 close $h;
1010  
1011 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
1012 294 $_ = lc for @{$row};
1013 }
1014 elsif ($args{'munge_column_names'} eq "uc") {
1015 7 $_ = uc for @{$row};
1016 }
1017 elsif ($args{'munge_column_names'} eq "db") {
1018 3 for (@{$row}) {
1019 7 s/\W+/_/g;
1020 7 s/^_+//;
1021 7 $_ = lc;
1022 }
1023 }
1024  
1025 313 ▶ if ($ahead) { # Must be after getline, which creates the cache
Branch: 1 branch
BranchTrueFalseTotal
if ($ahead) 143 170 313
1026 143 $self->_cache_set ($_cache_id{'_has_ahead'}, 1);
1027 143 $self->{'_AHEAD'} = $ahead;
1028 143 ▶ $eol =~ m/^\r([^\n]|\z)/ and $self->eol ($eol);
Branch: 1 branch
BranchTrueFalseTotal
$eol =~ /^\r([^\n]|\z)/ and $self->eol($eol) 73 70 143
1029 }
1030  
1031 313 my @hdr = @{$row};
1032 ref $args{'munge_column_names'} eq "CODE" and
1033 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
1034 ref $args{'munge_column_names'} eq "HASH" and
1035 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
1036 313 my %hdr; $hdr{$_}++ for @hdr;
1037 313 ▶ exists $hdr{''} and croak ($self->SetDiag (1012));
Branch: 1 branch
BranchTrueFalseTotal
exists $hdr{""} and croak($self->SetDiag(1012)) 2 311 313
1038 311 ▶ unless (keys %hdr == @hdr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %hdr == @hdr) 1 310 311
1039 croak ($self->_SetDiagInfo (1013, join ", " =>
1040 1 map { "$_ ($hdr{$_})" } grep { $hdr{$_} > 1 } keys %hdr));
1041 }
1042 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
1043 310 ▶ wantarray ? @hdr : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 195 115 310
1044 } # header
1045  
1046 40 ▶sub bind_columns {
Subroutine bind_columns: called CC=9 SCAR=22.0
Pod documented
1047 40 my ($self, @refs) = @_;
1048 @refs or
1049 40 ▶ return defined $self->{'_BOUND_COLUMNS'} ? @{$self->{'_BOUND_COLUMNS'}} : undef;
Branch: 2 branches
BranchTrueFalseTotal
@refs or return defined $self->{"_BOUND_COLUMNS"} ? @{$self->{"_BOUND_COLUMNS"};} : undef 36 4 40
defined $self->{'_BOUND_COLUMNS'} ? : 2 2 4
1050  
1051 36 ▶ if (@refs == 1 && ! defined $refs[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@refs == 1 and not defined $refs[0]) 5 31 36
Condition100%3/3
@refs == 1 and not defined $refs[0]
!ll&&!rl&&r
2475
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
1052 5 $self->{'_COLUMN_NAMES'} = undef;
1053 5 return $self->{'_BOUND_COLUMNS'} = undef;
1054 }
1055  
1056 31 ▶ $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 30 31
Condition100%3/3
$self->{"_COLUMN_NAMES"} and @refs != @{$self->{"_COLUMN_NAMES"};}
!ll&&!rl&&r
2821
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
1057 croak ($self->SetDiag (3003));
1058  
1059 30 ▶ join "", map { ref $_ eq "SCALAR" ? "" : "*" } @refs and
Branch: 2 branches
BranchTrueFalseTotal
join "", map({ref $_ eq "SCALAR" ? "" : "*";} @refs) and croak($self->SetDiag(3004)) 2 28 30
ref $_ eq 'SCALAR' ? : 74635 5 74640
1060 croak ($self->SetDiag (3004));
1061  
1062 28 $self->_set_attr_N ("_is_bound", scalar @refs);
1063 28 $self->{'_BOUND_COLUMNS'} = [ @refs ];
1064 28 @refs;
1065 } # bind_columns
1066  
1067 131 ▶sub getline_hr {
Subroutine getline_hr: called CC=10 SCAR=23.2
Pod documented
1068 131 my ($self, @args, %hr) = @_;
1069 131 ▶ $self->{'_COLUMN_NAMES'} or croak ($self->SetDiag (3002));
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_COLUMN_NAMES"} or croak($self->SetDiag(3002)) 130 1 131
1070 130 ▶ my $fr = $self->getline (@args) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fr = $self->getline(@args) or return 127 3 130
1071 127 ▶ if (ref $self->{'_FFLAGS'}) { # missing
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"_FFLAGS"}) 5 122 127
1072 $self->{'_FFLAGS'}[$_] = CSV_FLAGS_IS_MISSING ()
1073 5 ▶ for (@{$fr} ? $#{$fr} + 1 : 0) .. $#{$self->{'_COLUMN_NAMES'}};
Branch: 1 branch
BranchTrueFalseTotal
@{$fr;} ? : 5 0 5
1074 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
1075 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
1076 }
1077 127 @hr{@{$self->{'_COLUMN_NAMES'}}} = @{$fr};
1078 127 \%hr;
1079 } # getline_hr
1080  
1081 251 ▶sub getline_hr_all {
Subroutine getline_hr_all: called CC=2 SCAR=6.9
Pod documented
1082 251 my ($self, @args) = @_;
1083 251 ▶ $self->{'_COLUMN_NAMES'} or croak ($self->SetDiag (3002));
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_COLUMN_NAMES"} or croak($self->SetDiag(3002)) 249 2 251
1084 249 my @cn = @{$self->{'_COLUMN_NAMES'}};
1085 249 [ map { my %h; @h{@cn} = @{$_}; \%h } @{$self->getline_all (@args)} ];
1086 } # getline_hr_all
1087  
1088 34 ▶sub say {
Subroutine say: called CC=6 SCAR=18.1
Pod documented
1089 34 my ($self, $io, @f) = @_;
1090 34 my $eol = $self->eol ();
1091 # say ($fh, undef) does not propage actual undef to print ()
1092 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
1093 34 ▶ unless (length $eol) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $eol) 32 2 34
1094 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
1095 32 print $io $eol;
1096 }
1097 34 return $state;
1098 } # say
1099  
1100 3 ▶sub print_hr {
Subroutine print_hr: called CC=3 SCAR=11.0
Pod documented
1101 3 my ($self, $io, $hr) = @_;
1102 3 ▶ $self->{'_COLUMN_NAMES'} or croak ($self->SetDiag (3009));
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_COLUMN_NAMES"} or croak($self->SetDiag(3009)) 2 1 3
1103 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
1104 1 $self->print ($io, [ map { $hr->{$_} } $self->column_names () ]);
1105 } # print_hr
1106  
1107 66 ▶sub fragment {
Subroutine fragment: called CC=48 SCAR=38.7
Pod documented
1108 66 my ($self, $io, $spec) = @_;
1109  
1110 66 my $qd = qr{\s* [0-9]+ \s* }x; # digit
1111 66 my $qs = qr{\s* (?: [0-9]+ | \* ) \s*}x; # digit or star
1112 66 my $qr = qr{$qd (?: - $qs )?}x; # range
1113 66 my $qc = qr{$qr (?: ; $qr )*}x; # list
1114 66 ▶ 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)) 46 20 66
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
11946
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
1115 \x23 ? \s* # optional leading #
1116 ( row | col | cell ) \s* =
1117 ( $qc # for row and col
1118 | $qd , $qd (?: - $qs , $qs)? # for cell (ranges)
1119 (?: ; $qd , $qd (?: - $qs , $qs)? )* # and cell (range) lists
1120 ) \s* $}xi or croak ($self->SetDiag (2013));
1121 46 my ($type, $range) = (lc $1, $2);
1122  
1123 46 my @h = $self->column_names ();
1124  
1125 46 my @c;
1126 46 ▶ if ($type eq "cell") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "cell") 23 23 46
1127 23 my @spec;
1128 my $min_row;
1129 23 my $max_row = 0;
1130 23 for (split m/\s*;\s*/ => $range) {
1131 39 ▶ 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)) 38 1 39
1132 ^ \s* ([0-9]+ ) \s* , \s* ([0-9]+ ) \s*
1133 (?: - \s* ([0-9]+ | \*) \s* , \s* ([0-9]+ | \*) \s* )?
1134 $}x) or croak ($self->SetDiag (2013));
1135 38 ▶ defined $brr or ($brr, $brc) = ($tlr, $tlc);
Branch: 1 branch
BranchTrueFalseTotal
defined $brr or () = 18 20 38
1136 38 ▶ $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 30 38
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
6230
$tlr == 0 or $tlc == 0 or $brr ne "*" and $brr == 0 || $brr < $tlr
l!l&&r!l&&!r
4232
$tlr == 0 or $tlc == 0
l!l&&r!l&&!r
2234
$brr ne "*" and $brr == 0 || $brr < $tlr
!ll&&!rl&&r
3292
$brr == 0 or $brr < $tlr
l!l&&r!l&&!r
0229
$brc ne "*" and $brc == 0 || $brc < $tlc
!ll&&!rl&&r
2282
$brc == 0 or $brc < $tlc
l!l&&r!l&&!r
0228
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
1137 ($brr ne "*" && ($brr == 0 || $brr < $tlr)) ||
1138 ($brc ne "*" && ($brc == 0 || $brc < $tlc))
1139 and croak ($self->SetDiag (2013));
1140 30 $tlc--;
1141 30 ▶ $brc-- unless $brc eq "*";
Branch: 1 branch
BranchTrueFalseTotal
unless $brc eq "*" 28 2 30
1142 30 ▶ defined $min_row or $min_row = $tlr;
Branch: 1 branch
BranchTrueFalseTotal
defined $min_row or $min_row = $tlr 14 16 30
1143 30 ▶ $tlr < $min_row and $min_row = $tlr;
Branch: 1 branch
BranchTrueFalseTotal
$tlr < $min_row and $min_row = $tlr 1 29 30
1144 30 ▶ $brr eq "*" || $brr > $max_row and
Branch: 1 branch
BranchTrueFalseTotal
$brr eq "*" || $brr > $max_row and $max_row = $brr 21 9 30
Condition100%3/3
$brr eq "*" or $brr > $max_row
l!l&&r!l&&!r
2199
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
1145 $max_row = $brr;
1146 30 push @spec, [ $tlr, $tlc, $brr, $brc ];
1147 }
1148 14 my $r = 0;
1149 14 ▶ while (my $row = $self->getline ($io)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $self->getline($io)) 80 2 82
1150 80 ▶ ++$r < $min_row and next;
Branch: 1 branch
BranchTrueFalseTotal
++$r < $min_row and next 44 36 80
1151 36 my %row;
1152 my $lc;
1153 36 foreach my $s (@spec) {
1154 80 my ($tlr, $tlc, $brr, $brc) = @{$s};
1155 80 ▶ $r < $tlr || ($brr ne "*" && $r > $brr) and next;
Branch: 1 branch
BranchTrueFalseTotal
$r < $tlr || $brr ne "*" && $r > $brr and next 32 48 80
Condition100%6/6
$r < $tlr or $brr ne "*" and $r > $brr
l!l&&r!l&&!r
171548
$brr ne "*" and $r > $brr
!ll&&!rl&&r
64215
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
1156 48 ▶ !defined $lc || $tlc < $lc and $lc = $tlc;
Branch: 1 branch
BranchTrueFalseTotal
!defined($lc) || $tlc < $lc and $lc = $tlc 39 9 48
Condition100%3/3
not defined $lc or $tlc < $lc
l!l&&r!l&&!r
3639
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
1157 # Do not pad past the data: an explicit column beyond the
1158 # row would otherwise allocate one slot per selector integer
1159 48 ▶ my $lr = $#{$row} > $tlc ? $#{$row} : $tlc;
Branch: 1 branch
BranchTrueFalseTotal
$#{$row;} > $tlc ? : 47 1 48
1160 48 ▶ my $rr = $brc eq "*" ? $#{$row} : $brc > $lr ? $lr : $brc;
Branch: 2 branches
BranchTrueFalseTotal
$brc eq '*' ? : 5 43 48
$brc > $lr ? : 2 41 43
1161 48 $row{$_} = $row->[$_] for $tlc .. $rr;
1162 }
1163 36 push @c, [ @row{sort { $a <=> $b } keys %row } ];
1164 36 ▶ if (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 2 34 36
1165 2 my %h; @h{@h} = @{$c[-1]};
1166 2 $c[-1] = \%h;
1167 }
1168 36 ▶ $max_row ne "*" && $r == $max_row and last;
Branch: 1 branch
BranchTrueFalseTotal
$max_row ne "*" and $r == $max_row and last 12 24 36
Condition100%3/3
$max_row ne "*" and $r == $max_row
!ll&&!rl&&r
61812
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
1169 }
1170 14 return \@c;
1171 }
1172  
1173 # row or col
1174 # Keep the ranges as pairs and test membership per row or column:
1175 # materialising every index in an array cost memory proportional
1176 # to the integers in the selector, not to the data
1177 23 my @r;
1178 23 my $max = 0;
1179 23 my $eod = 0;
1180 23 for (split m/\s*;\s*/ => $range) {
1181 33 ▶ 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)) 33 0 33
1182 or croak ($self->SetDiag (2013));
1183 33 ▶ $to ||= $from;
Condition100%3/3
$to ||= $from
l!l&&r!l&&!r
15162
MC/DC100%2/2
$to ||= $from
$to $from
Truth table100%3/3
A ||= B
A= $toB= $from
ABresult
1X1
011
000
1184 33 ▶ $to eq "*" and ($to, $eod) = ($from, 1);
Branch: 1 branch
BranchTrueFalseTotal
$to eq "*" and ($to, $eod) = ($from, 1) 5 28 33
1185 # $to cannot be <= 0 due to regex and ||=
1186 33 ▶ $from <= 0 || $to < $from and croak ($self->SetDiag (2013));
Branch: 1 branch
BranchTrueFalseTotal
$from <= 0 || $to < $from and croak($self->SetDiag(2013)) 3 30 33
Condition100%3/3
$from <= 0 or $to < $from
l!l&&r!l&&!r
2130
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
1187 30 push @r => [ $from, $to ];
1188 30 ▶ $to > $max and $max = $to;
Branch: 1 branch
BranchTrueFalseTotal
$to > $max and $max = $to 29 1 30
1189 }
1190 505 ▶ my $in = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
1191 505 my $i = shift;
1192 505 ▶ $i > $max and return $eod;
Branch: 1 branch
BranchTrueFalseTotal
$i > $max and return $eod 283 222 505
1193 222 ▶ $i >= $_->[0] && $i <= $_->[1] and return 1 for @r;
Branch: 1 branch
BranchTrueFalseTotal
$i >= $_->[0] and $i <= $_->[1] and return 1 133 257 390
Condition100%3/3
$i >= $_->[0] and $i <= $_->[1]
!ll&&!rl&&r
130127133
MC/DC100%2/2
$i >= $_->[0] and $i <= $_->[1]
$i >= $_->[0] $i <= $_->[1]
Truth table100%3/3
A and B
A= $i >= $_->[0]B= $i <= $_->[1]
ABresult
0X0
100
111
1194 89 return 0;
1195 20 };
1196  
1197 20 my $r = 0;
1198 20 ▶ while (my $row = $self->getline ($io)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $self->getline($io)) 127 20 147
1199 127 $r++;
1200 127 ▶ if ($type eq "row") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "row") 73 54 127
1201 73 ▶ if ($in->($r)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$in($r)) 26 47 73
1202 26 push @c, $row;
1203 26 ▶ if (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 3 23 26
1204 3 my %h; @h{@h} = @{$c[-1]};
1205 3 $c[-1] = \%h;
1206 }
1207 }
1208 73 next;
1209 }
1210 54 ▶ push @c, [ map { $in->($_ + 1) ? $row->[$_] : () } 0..$#{$row} ];
Branch: 1 branch
BranchTrueFalseTotal
&$in($_ + 1) ? : 138 294 432
1211 54 ▶ if (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 9 45 54
1212 9 my %h; @h{@h} = @{$c[-1]};
1213 9 $c[-1] = \%h;
1214 }
1215 }
1216  
1217 20 return \@c;
1218 } # fragment
1219  
1220 36 my $csv_usage = q{usage: my $aoa = csv (in => $file);};
1221  
1222 345 ▶sub _csv_attr {
Subroutine _csv_attr: called CC=89 SCAR=45.5
1223 345 my %attr;
1224 345 ▶ if (@_ == 1 && ref $_[0] eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 4 341 345
elsif (scalar @_ % 2) { } 1 340 341
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
34014
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
1225 4 %attr = %{$_[0]};
1226 }
1227 elsif (scalar @_ % 2) {
1228 1 croak (Text::CSV_XS->SetDiag (1502));
1229 }
1230 else {
1231 340 %attr = @_;
1232 }
1233  
1234 344 $attr{'binary'} = 1;
1235 344 $attr{'strict_eol'} = 1;
1236  
1237 344 ▶ my $enc = delete $attr{'enc'} || delete $attr{'encoding'} || "";
Condition100%5/5
delete $attr{'enc'} || delete $attr{'encoding'} || ''
l!l
45299
delete $attr{"enc"} or delete $attr{"encoding"}
l!l&&r!l&&!r
144299
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
1238 344 ▶ $enc eq "auto" and ($attr{'detect_bom'}, $enc) = (1, "");
Branch: 1 branch
BranchTrueFalseTotal
$enc eq "auto" and ($attr{"detect_bom"}, $enc) = (1, "") 42 302 344
1239 344 ▶ my $stack = $enc =~ s/(:\w.*)// ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
$enc =~ s/(:\w.*)// ? : 0 344 344
1240 344 ▶ $enc =~ m/^[-\w.]+$/ and $enc = ":encoding($enc)";
Branch: 1 branch
BranchTrueFalseTotal
$enc =~ /^[-\w.]+$/ and $enc = ":encoding($enc)" 3 341 344
1241 344 $enc .= $stack;
1242  
1243 344 my $hdrs = delete $attr{'headers'};
1244 344 my $frag = delete $attr{'fragment'};
1245 344 my $key = delete $attr{'key'};
1246 344 my $val = delete $attr{'value'};
1247 my $kh = delete $attr{'keep_headers'} ||
1248 delete $attr{'keep_column_names'} ||
1249 344 ▶ delete $attr{'kh'};
Condition100%6/6
delete $attr{'keep_headers'} || delete $attr{'keep_column_names'} || delete $attr{'kh'}
l!l&&r!l&&!r
415325
delete $attr{"keep_headers"} or delete $attr{"keep_column_names"}
l!l&&r!l&&!r
22340
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
1250  
1251 my $cbai = delete $attr{'callbacks'}{'after_in'} ||
1252 delete $attr{'after_in'} ||
1253 delete $attr{'callbacks'}{'after_parse'} ||
1254 344 ▶ 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
112331
delete $attr{"callbacks"}{"after_in"} or delete $attr{"after_in"} or delete $attr{"callbacks"}{"after_parse"}
l!l&&r!l&&!r
92333
delete $attr{"callbacks"}{"after_in"} or delete $attr{"after_in"}
l!l&&r!l&&!r
27335
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
1255 my $cbbo = delete $attr{'callbacks'}{'before_out'} ||
1256 344 ▶ delete $attr{'before_out'};
Condition100%3/3
delete $attr{'callbacks'}{'before_out'} || delete $attr{'before_out'}
l!l&&r!l&&!r
22340
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
1257 my $cboi = delete $attr{'callbacks'}{'on_in'} ||
1258 344 ▶ delete $attr{'on_in'};
Condition100%3/3
delete $attr{'callbacks'}{'on_in'} || delete $attr{'on_in'}
l!l&&r!l&&!r
412328
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
1259 my $cboe = delete $attr{'callbacks'}{'on_error'} ||
1260 344 ▶ delete $attr{'on_error'};
Condition66%2/3
delete $attr{'callbacks'}{'on_error'} || delete $attr{'on_error'}
l!l&&r!l&&!r
01343
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
1261  
1262 my $hd_s = delete $attr{'sep_set'} ||
1263 344 ▶ delete $attr{'seps'};
Condition100%3/3
delete $attr{'sep_set'} || delete $attr{'seps'}
l!l&&r!l&&!r
46334
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
1264 my $hd_b = delete $attr{'detect_bom'} ||
1265 344 ▶ delete $attr{'bom'};
Condition100%3/3
delete $attr{'detect_bom'} || delete $attr{'bom'}
l!l&&r!l&&!r
42119183
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
1266 my $hd_m = delete $attr{'munge'} ||
1267 344 ▶ delete $attr{'munge_column_names'};
Condition100%3/3
delete $attr{'munge'} || delete $attr{'munge_column_names'}
l!l&&r!l&&!r
71336
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
1268 344 my $hd_c = delete $attr{'set_column_names'};
1269  
1270 344 my $fh;
1271 344 my $sink = 0;
1272 344 my $cls = 0; # If I open a file, I have to close it
1273 344 ▶ 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) 341 3 344
Condition100%3/3
delete $attr{'in'} || delete $attr{'file'}
l!l&&r!l&&!r
33833
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
1274 my $out = exists $attr{'out'} && !$attr{'out'} ? \"skip"
1275 341 ▶ : delete $attr{'out'} || delete $attr{'file'};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr{'out'} && !$attr{'out'} ? : 1 340 341
Condition100%6/6
exists $attr{"out"} and not $attr{"out"}
!ll&&!rl&&r
304361
delete $attr{"out"} or delete $attr{"file"}
l!l&&r!l&&!r
361303
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
1276  
1277 341 ▶ 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 316 341
Condition100%5/5
ref $in eq "CODE" or ref $in eq "ARRAY"
l!l&&r!l&&!r
322316
$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
1278  
1279 341 my ($fho, $fho_cls);
1280 341 ▶ 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 334 341
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
32957
$in and $out and !ref($in) || ref $in eq "GLOB" || ref \$in eq "GLOB"
!ll&&!rl&&r
3012812
$in and $out
!ll&&!rl&&r
030140
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
1281 and (!ref $out || ref $out eq "GLOB" || ref \$out eq "GLOB")) {
1282 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
1283 2 $fho = $out;
1284 }
1285 else {
1286 5 ▶ open $fho, ">", $out or croak "$out: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $fho, ">", $out or croak("${out}: $!\n") 5 0 5
1287 5 ▶ if (my $e = $attr{'encoding'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $attr{"encoding"}) 0 5 5
1288 0 binmode $fho, ":encoding($e)";
1289 0 ▶ $hd_b and print $fho "\x{feff}";
Branch: 1 branch
BranchTrueFalseTotal
$hd_b and print $fho "\x{feff}" 0 0 0
1290 }
1291 5 $fho_cls = 1;
1292 }
1293 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
1294 1 $cbai = $cboi;
1295 1 $cboi = undef;
1296 }
1297 7 ▶ if ($cbai) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cbai) { } 2 5 7
1298 2 my $cb = $cbai;
1299 2 ▶ $cbai = sub { $cb->(@_); $_[0]->say ($fho, $_[1]); 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
1300 }
1301 else {
1302 5 ▶ $cbai = sub { $_[0]->say ($fho, $_[1]); 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
1303 }
1304  
1305 # Put all callbacks back in place for streaming behavior
1306 7 $attr{'callbacks'}{'after_parse'} = $cbai; $cbai = undef;
1307 7 $attr{'callbacks'}{'before_out'} = $cbbo; $cbbo = undef;
1308 7 $attr{'callbacks'}{'on_in'} = $cboi; $cboi = undef;
1309 7 $attr{'callbacks'}{'on_error'} = $cboe; $cboe = undef;
1310 7 $out = undef;
1311 7 $sink = 1;
1312 }
1313  
1314 341 ▶ if ($out) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out) 33 308 341
1315 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
1316 5 delete $attr{'out'};
1317 5 $sink = 1;
1318 }
1319 ▶ 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
1320 14 $fh = $out;
1321 }
1322 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
1323 2 delete $attr{'out'};
1324 2 $sink = 1;
1325 }
1326 else {
1327 12 ▶ open $fh, ">", $out or croak ("$out: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $out or croak("${out}: $!") 11 1 12
1328 11 $cls = 1;
1329 }
1330 32 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 25 7 32
1331 25 ▶ if ($enc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) 1 24 25
1332 1 binmode $fh, $enc;
1333 1 my $fn = fileno $fh; # This is a workaround for a bug in PerlIO::via::gzip
1334 }
1335 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
1336 18 my @layers = eval { PerlIO::get_layers ($fh) };
1337 18 ▶ $attr{'eol'} = (grep m/crlf/ => @layers) ? "\n" : "\r\n";
Branch: 1 branch
BranchTrueFalseTotal
grep(/crlf/, @layers) ? : 1 17 18
1338 }
1339 }
1340 }
1341  
1342 340 ▶ 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 316 340
elsif (ref $in eq 'SCALAR') { } 30 286 316
elsif (ref $in or 'GLOB' eq ref \$in) { } 18 268 286
Condition100%3/3
ref $in eq "CODE" or ref $in eq "ARRAY"
l!l&&r!l&&!r
321316
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
1343 # All done
1344 }
1345 elsif (ref $in eq "SCALAR") {
1346 # Strings with code points over 0xFF may not be mapped into in-memory file handles
1347 # "<$enc" does not change that :(
1348 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
1349 30 $cls = 1;
1350 }
1351 ▶ elsif (ref $in or "GLOB" eq ref \$in) {
Condition100%3/3
ref $in or "GLOB" eq ref \$in
l!l&&r!l&&!r
162268
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
1352 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
1353 0 $fh = \*{$in}; # uncoverable statement ancient perl version required
1354 }
1355 else {
1356 18 $fh = $in;
1357 }
1358 }
1359 else {
1360 268 ▶ open $fh, "<$enc", $in or croak ("$in: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<$enc", $in or croak("${in}: $!") 266 1 267
1361 266 $cls = 1;
1362 }
1363 338 ▶ $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") 338 0 338
Condition33%1/3
$fh or $sink
l!l&&r!l&&!r
33800
MC/DC0%0/2
$fh or $sink
$fh $sink
Truth table33%1/3
A or B
A= $fhB= $sink
ABresult
1X1
011
000
1364  
1365 338 for ([ 'quo' => "quote" ],
1366 [ 'esc' => "escape" ],
1367 [ 'escape' => "escape_char" ],
1368 ) {
1369 1014 my ($f, $t) = @{$_};
1370 1014 ▶ 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 1008 1014
Condition100%3/3
exists $attr{$f} and not exists $attr{$t}
!ll&&!rl&&r
100716
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
1371 }
1372  
1373 338 my $fltr = delete $attr{'filter'};
1374 my %fltr = (
1375 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
1376 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
1377 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
1378 338 );
1379 defined $fltr && !ref $fltr && exists $fltr{$fltr} and
1380 338 ▶ $fltr = { '0' => $fltr{$fltr} };
Branch: 1 branch
BranchTrueFalseTotal
defined $fltr and not ref $fltr and exists $fltr{$fltr} and $fltr = {0, $fltr{$fltr}} 3 335 338
Condition83%5/6
defined $fltr and not ref $fltr and exists $fltr{$fltr}
!ll&&!rl&&r
33503
defined $fltr and not ref $fltr
!ll&&!rl&&r
321143
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
1381 338 ▶ ref $fltr eq "CODE" and $fltr = { 0 => $fltr };
Branch: 1 branch
BranchTrueFalseTotal
ref $fltr eq "CODE" and $fltr = {0, $fltr} 2 336 338
1382 338 ▶ ref $fltr eq "HASH" or $fltr = undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $fltr eq "HASH" or $fltr = undef 17 321 338
1383  
1384 338 my $form = delete $attr{'formula'};
1385  
1386 338 ▶ defined $attr{'auto_diag'} or $attr{'auto_diag'} = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $attr{"auto_diag"} or $attr{"auto_diag"} = 1 31 307 338
1387 338 ▶ defined $attr{'escape_null'} or $attr{'escape_null'} = 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $attr{"escape_null"} or $attr{"escape_null"} = 0 1 337 338
1388 338 ▶ my $csv = delete $attr{'csv'} || Text::CSV_XS->new (\%attr)
Branch: 1 branch
BranchTrueFalseTotal
my $csv = delete $attr{"csv"} || "Text::CSV_XS"->new(\%attr) or croak($last_err) 338 0 338
Condition66%2/3
delete $attr{'csv'} || 'Text::CSV_XS'->new(\%attr)
l!l&&r!l&&!r
153230
MC/DC0%0/2
delete $attr{'csv'} || 'Text::CSV_XS'->new(\%attr)
delete $attr{'csv'} 'Text::CSV_XS'->new(\%attr)
Truth table66%2/3
A || B
A= delete $attr{'csv'}B= 'Text::CSV_XS'->new(\%attr)
ABresult
1X1
011
000
1389 or croak ($last_err);
1390 338 ▶ defined $form and $csv->formula ($form);
Branch: 1 branch
BranchTrueFalseTotal
defined $form and $csv->formula($form) 1 337 338
1391 338 ▶ defined $cboe and $csv->callbacks (error => $cboe);
Branch: 1 branch
BranchTrueFalseTotal
defined $cboe and $csv->callbacks("error", $cboe) 1 337 338
1392  
1393 338 ▶ $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 330 338
Condition100%6/6
$kh and not ref $kh and $kh =~ /^(?:1|yes|true|internal|auto)$/i
!ll&&!rl&&r
32738
$kh and not ref $kh
!ll&&!rl&&r
319811
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
1394 $kh = \@internal_kh;
1395  
1396 return {
1397 338 'csv' => $csv,
1398 'attr' => { %attr },
1399 'fh' => $fh,
1400 'cls' => $cls,
1401 'in' => $in,
1402 'sink' => $sink,
1403 'out' => $out,
1404 'enc' => $enc,
1405 'fho' => $fho,
1406 'fhoc' => $fho_cls,
1407 'hdrs' => $hdrs,
1408 'key' => $key,
1409 'val' => $val,
1410 'kh' => $kh,
1411 'frag' => $frag,
1412 'fltr' => $fltr,
1413 'cbai' => $cbai,
1414 'cbbo' => $cbbo,
1415 'cboi' => $cboi,
1416 'hd_s' => $hd_s,
1417 'hd_b' => $hd_b,
1418 'hd_m' => $hd_m,
1419 'hd_c' => $hd_c,
1420 };
1421 } # _csv_attr
1422  
1423 346 ▶sub csv {
Subroutine csv: called CC=128 SCAR=49.6
Pod documented
1424 346 ▶ @_ && ref $_[0] eq __PACKAGE__ and splice @_, 0, 0, "csv";
Branch: 1 branch
BranchTrueFalseTotal
@_ and ref $_[0] eq __PACKAGE__ and splice @_, 0, 0, "csv" 13 333 346
Condition100%3/3
@_ and ref $_[0] eq __PACKAGE__
!ll&&!rl&&r
133213
MC/DC100%2/2
@_ and ref $_[0] eq __PACKAGE__
@_ ref $_[0] eq __PACKAGE__
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq __PACKAGE__
ABresult
0X0
100
111
1425 346 ▶ @_ or croak ($csv_usage);
Branch: 1 branch
BranchTrueFalseTotal
@_ or croak($csv_usage) 345 1 346
1426  
1427 345 my $c = _csv_attr (@_);
1428  
1429 338 my ($csv, $in, $fh, $hdrs) = @{$c}{qw( csv in fh hdrs )};
1430 338 my %hdr;
1431 338 ▶ if (ref $hdrs eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hdrs eq "HASH") 2 336 338
1432 2 %hdr = %{$hdrs};
1433 2 $hdrs = "auto";
1434 }
1435  
1436 338 ▶ if ($c->{'out'} && !$c->{'sink'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"out"} and not $c->{"sink"}) 24 314 338
Condition100%3/3
$c->{"out"} and not $c->{"sink"}
!ll&&!rl&&r
307724
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
1437 !$hdrs && ref $c->{'kh'} && $c->{'kh'} == \@internal_kh and
1438 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
1439  
1440 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
1441 3 my $hdr = 1;
1442 3 ▶ while (my $row = $in->($csv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$in($csv)) 7 3 10
1443 7 ▶ if (ref $row eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $row eq "ARRAY") 3 4 7
1444 3 $csv->print ($fh, $row);
1445 3 next;
1446 }
1447 4 ▶ if (ref $row eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $row eq "HASH") 4 0 4
1448 4 ▶ if ($hdr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr) 2 2 4
1449 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
1450 2 $csv->print ($fh, $hdrs);
1451 2 $hdr = 0;
1452 }
1453 4 $csv->print ($fh, [ @{$row}{@{$hdrs}} ]);
1454 }
1455 }
1456 }
1457 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
1458 10 ▶ ref $hdrs and $csv->print ($fh, $hdrs);
Branch: 1 branch
BranchTrueFalseTotal
ref $hdrs and $csv->print($fh, $hdrs) 0 10 10
1459 10 for (@{$in}) {
1460 12 ▶ $c->{'cboi'} and $c->{'cboi'}->($csv, $_);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cboi"} and $c->{"cboi"}->($csv, $_) 2 10 12
1461 12 ▶ $c->{'cbbo'} and $c->{'cbbo'}->($csv, $_);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cbbo"} and $c->{"cbbo"}->($csv, $_) 0 12 12
1462 12 $csv->print ($fh, $_);
1463 }
1464 }
1465 else { # aoh
1466 11 ▶ my @hdrs = ref $hdrs ? @{$hdrs} : keys %{$in->[0]};
Branch: 1 branch
BranchTrueFalseTotal
ref $hdrs ? : 5 6 11
1467 11 ▶ defined $hdrs or $hdrs = "auto";
Branch: 1 branch
BranchTrueFalseTotal
defined $hdrs or $hdrs = "auto" 9 2 11
1468 ref $hdrs || $hdrs eq "auto" and @hdrs and
1469 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
1470 11 for (@{$in}) {
1471 17 local %_;
1472 17 *_ = $_;
1473 17 ▶ $c->{'cboi'} and $c->{'cboi'}->($csv, $_);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cboi"} and $c->{"cboi"}->($csv, $_) 0 17 17
1474 17 ▶ $c->{'cbbo'} and $c->{'cbbo'}->($csv, $_);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cbbo"} and $c->{"cbbo"}->($csv, $_) 0 17 17
1475 17 $csv->print ($fh, [ @{$_}{@hdrs} ]);
1476 }
1477 }
1478  
1479 24 ▶ $c->{'cls'} and close $fh;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cls"} and close $fh 11 13 24
1480 24 ▶ $c->{'fho_cls'} and close $c->{'fho'};
Branch: 1 branch
BranchTrueFalseTotal
$c->{"fho_cls"} and close $c->{"fho"} 0 24 24
1481 24 return 1;
1482 }
1483  
1484 314 my @row1;
1485 314 ▶ 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"}) 173 141 314
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
1712141
defined $c->{"hd_s"} or defined $c->{"hd_b"} or defined $c->{"hd_m"}
l!l&&r!l&&!r
1656143
defined $c->{"hd_s"} or defined $c->{"hd_b"}
l!l&&r!l&&!r
10155149
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
1486 173 my %harg;
1487 !defined $c->{'hd_s'} && $c->{'attr'}{'sep_char'} and
1488 173 ▶ $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 170 173
Condition100%3/3
not defined $c->{"hd_s"} and $c->{"attr"}{"sep_char"}
!ll&&!rl&&r
101603
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
1489 !defined $c->{'hd_s'} && $c->{'attr'}{'sep'} and
1490 173 ▶ $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 170 173
Condition100%3/3
not defined $c->{"hd_s"} and $c->{"attr"}{"sep"}
!ll&&!rl&&r
131573
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
1491 173 ▶ 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 157 173
1492 173 ▶ 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"} 161 12 173
1493 173 ▶ 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 165 173
$hdrs ? : 0 8 8
1494 173 ▶ 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 169 173
$hdrs ? : 0 4 4
1495 173 @row1 = $csv->header ($fh, \%harg);
1496 170 my @hdr = $csv->column_names ();
1497 170 ▶ @hdr and $hdrs ||= \@hdr;
Branch: 1 branch
BranchTrueFalseTotal
@hdr and $hdrs ||= \@hdr 166 4 170
Condition100%2/2
$hdrs ||= \@hdr
l!l
1165
MC/DC100%1/1
$hdrs ||= \@hdr
$hdrs
Truth table100%2/2
A
A= $hdrs
Aresult
11
00
1498 }
1499  
1500 311 ▶ if ($c->{'kh'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"kh"}) 15 296 311
1501 15 @internal_kh = ();
1502 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
1503 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
1504 }
1505  
1506 306 my $key = $c->{'key'};
1507 306 ▶ if ($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) 27 279 306
1508 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
1509 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
1510 }
1511 299 my $val = $c->{'val'};
1512 299 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 9 290 299
1513 9 ▶ $key or croak ($csv->SetDiag (1502));
Branch: 1 branch
BranchTrueFalseTotal
$key or croak($csv->SetDiag(1502)) 8 1 9
1514 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
1515 }
1516  
1517 295 ▶ $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" 6 289 295
Condition100%5/5
$c->{"fltr"} and grep /\D/, keys %{$$c{"fltr"};}
!ll&&!rl&&r
278116
$hdrs ||= "auto"
l!l
24
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
1518 295 ▶ if (defined $hdrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hdrs) 224 71 295
1519 224 ▶ if (!ref $hdrs or ref $hdrs eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $hdrs or ref $hdrs eq "CODE") 53 171 224
Condition100%3/3
not ref $hdrs or ref $hdrs eq "CODE"
l!l&&r!l&&!r
521171
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
1520 53 ▶ my $h = $c->{'hd_b'}
Branch: 1 branch
BranchTrueFalseTotal
$c->{'hd_b'} ? : 1 52 53
1521 ? [ $csv->column_names () ]
1522 : $csv->getline ($fh);
1523 53 ▶ my $has_h = $h && @$h;
Condition33%1/3
$h && @$h
!ll&&!rl&&r
0053
MC/DC0%0/2
$h && @$h
$h @$h
Truth table33%1/3
A && B
A= $hB= @$h
ABresult
0X0
100
111
1524  
1525 53 ▶ if (ref $hdrs) {
Branch: 5 branches
BranchTrueFalseTotal
if (ref $hdrs) { } 1 52 53
elsif ($hdrs eq 'skip') { } 1 51 52
elsif ($hdrs eq 'auto') { } 49 2 51
elsif ($hdrs eq 'lc') { } 1 1 2
elsif ($hdrs eq 'uc') { } 1 0 1
1526 1 ▶ $has_h or return;
Branch: 1 branch
BranchTrueFalseTotal
$has_h or return 1 0 1
1527 1 my $cr = $hdrs;
1528 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
1529 }
1530 elsif ($hdrs eq "skip") {
1531 # discard;
1532 }
1533 elsif ($hdrs eq "auto") {
1534 49 ▶ $has_h or return;
Branch: 1 branch
BranchTrueFalseTotal
$has_h or return 49 0 49
1535 49 ▶ $hdrs = [ map { $hdr{$_} || $_ } @{$h} ];
Condition66%2/3
$hdr{$_} || $_
l!l&&r!l&&!r
11380
MC/DC0%0/2
$hdr{$_} || $_
$hdr{$_} $_
Truth table66%2/3
A || B
A= $hdr{$_}B= $_
ABresult
1X1
011
000
1536 }
1537 elsif ($hdrs eq "lc") {
1538 1 ▶ $has_h or return;
Branch: 1 branch
BranchTrueFalseTotal
$has_h or return 1 0 1
1539 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
1540 }
1541 elsif ($hdrs eq "uc") {
1542 1 ▶ $has_h or return;
Branch: 1 branch
BranchTrueFalseTotal
$has_h or return 1 0 1
1543 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
1544 }
1545 }
1546 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
1547 }
1548  
1549 295 ▶ if ($c->{'fltr'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"fltr"}) 17 278 295
1550 17 my %f = %{$c->{'fltr'}};
1551 # convert headers to index
1552 17 my @hdr;
1553 17 ▶ if (ref $hdrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hdrs) 8 9 17
1554 8 @hdr = @{$hdrs};
1555 8 for (0 .. $#hdr) {
1556 24 ▶ exists $f{$hdr[$_]} and $f{$_ + 1} = delete $f{$hdr[$_]};
Branch: 1 branch
BranchTrueFalseTotal
exists $f{$hdr[$_]} and $f{$_ + 1} = delete $f{$hdr[$_]} 6 18 24
1557 }
1558 }
1559 116 ▶ $csv->callbacks ('after_parse' => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1560 116 my ($CSV, $ROW) = @_; # lexical sub-variables in caps
1561 116 foreach my $FLD (sort keys %f) {
1562 117 local $_ = $ROW->[$FLD - 1];
1563 117 local %_;
1564 117 ▶ @hdr and @_{@hdr} = @{$ROW};
Branch: 1 branch
BranchTrueFalseTotal
@hdr and @_{@hdr} = @{$ROW;} 53 64 117
1565 117 ▶ $f{$FLD}->($CSV, $ROW) or return \"skip";
Branch: 1 branch
BranchTrueFalseTotal
$f{$FLD}->($CSV, $ROW) or return \"skip" 53 64 117
1566 53 $ROW->[$FLD - 1] = $_;
1567 }
1568 17 });
1569 }
1570  
1571 295 my $frag = $c->{'frag'};
1572 my $ref = ref $hdrs
1573 ? # aoh
1574 295 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
ref $hdrs ? : 223 72 295
1575 223 my @h = $csv->column_names ($hdrs);
1576 223 my %h; $h{$_}++ for @h;
1577 223 ▶ exists $h{''} and croak ($csv->SetDiag (1012));
Branch: 1 branch
BranchTrueFalseTotal
exists $h{""} and croak($csv->SetDiag(1012)) 0 223 223
1578 223 ▶ unless (keys %h == @h) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %h == @h) 0 223 223
1579 croak ($csv->_SetDiagInfo (1013, join ", " =>
1580 0 map { "$_ ($h{$_})" } grep { $h{$_} > 1 } keys %h));
1581 }
1582 $frag ? $csv->fragment ($fh, $frag) :
1583 223 ▶ $key ? do {
Branch: 2 branches
BranchTrueFalseTotal
$frag ? : 2 221 223
$key ? : 17 204 221
1584 17 ▶ my ($k, $j, @f) = ref $key ? (undef, @{$key}) : ($key);
Branch: 1 branch
BranchTrueFalseTotal
ref $key ? : 5 12 17
1585 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
1586 2 croak ($csv->_SetDiagInfo (4001, join ", " => @mk));
1587 }
1588 +{ map {
1589 26 my $r = $_;
1590 26 ▶ my $K = defined $k ? $r->{$k} : join $j => @{$r}{@f};
Branch: 1 branch
BranchTrueFalseTotal
defined $k ? : 22 4 26
1591 ( $K => (
1592 $val
1593 ? ref $val
1594 4 ? { map { $_ => $r->{$_} } @{$val} }
1595 26 ▶ : $r->{$val}
Branch: 2 branches
BranchTrueFalseTotal
$val ? : 5 21 26
ref $val ? : 2 3 5
1596 : $r ));
1597 15 ▶ } @{$csv->getline_hr_all ($fh)} }
Branch: 1 branch
BranchTrueFalseTotal
$frag ? : 2 70 72
1598 }
1599 : $csv->getline_hr_all ($fh);
1600 }
1601 : # aoa
1602 $frag ? $csv->fragment ($fh, $frag)
1603 : $csv->getline_all ($fh);
1604 287 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 287 0 287
1605 287 ▶ @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 283 287
Condition83%5/6
@row1 and not $c->{"hd_c"} and not ref $hdrs
!ll&&!rl&&r
1191644
@row1 and not $c->{"hd_c"}
!ll&&!rl&&r
1190168
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
1606 }
1607 else {
1608 0 Text::CSV_XS->auto_diag ();
1609 }
1610 287 ▶ $c->{'cls'} and close $fh;
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cls"} and close $fh 269 18 287
1611 287 ▶ $c->{'fho_cls'} and close $c->{'fho'};
Branch: 1 branch
BranchTrueFalseTotal
$c->{"fho_cls"} and close $c->{"fho"} 0 287 287
1612 287 ▶ if ($ref and $c->{'cbai'} || $c->{'cboi'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and $c->{"cbai"} || $c->{"cboi"}) 23 264 287
Condition83%5/6
$ref and $c->{"cbai"} || $c->{"cboi"}
!ll&&!rl&&r
026423
$c->{"cbai"} or $c->{"cboi"}
l!l&&r!l&&!r
1211264
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
1613 # Default is ARRAYref, but with key =>, you'll get a hashref
1614 23 ▶ foreach my $r (ref $ref eq "ARRAY" ? @{$ref} : values %{$ref}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 22 1 23
1615 74 local %_;
1616 74 ▶ ref $r eq "HASH" and *_ = $r;
Branch: 1 branch
BranchTrueFalseTotal
ref $r eq "HASH" and *_ = $r 34 40 74
1617 74 ▶ $c->{'cbai'} and $c->{'cbai'}->($csv, $r);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cbai"} and $c->{"cbai"}->($csv, $r) 33 41 74
1618 74 ▶ $c->{'cboi'} and $c->{'cboi'}->($csv, $r);
Branch: 1 branch
BranchTrueFalseTotal
$c->{"cboi"} and $c->{"cboi"}->($csv, $r) 46 28 74
1619 }
1620 }
1621  
1622 287 ▶ if ($c->{'sink'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"sink"}) 14 273 287
1623 14 ▶ my $ro = ref $c->{'out'} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ro = ref $c->{"out"} or return 7 7 14
1624  
1625 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
1626 return;
1627  
1628 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
1629 croak ($csv->_SetDiagInfo (5001, "Output type mismatch"));
1630  
1631 5 ▶ if ($ro eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ro eq "ARRAY") 4 1 5
1632 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
1633 2 push @{$c->{'out'}} => @$ref;
1634 2 return $c->{'out'};
1635 }
1636 2 croak ($csv->_SetDiagInfo (5001, "Output type mismatch"));
1637 }
1638  
1639 1 ▶ if ($ro eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ro eq "HASH") 1 0 1
1640 1 @{$c->{'out'}}{keys %{$ref}} = values %{$ref};
1641 1 return $c->{'out'};
1642 }
1643  
1644 0 croak ($csv->_SetDiagInfo (5002, "Unsupported output type"));
1645 }
1646  
1647 defined wantarray or
1648 return csv (
1649 'in' => $ref,
1650 'headers' => $hdrs,
1651 273 ▶ %{$c->{'attr'}},
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray or return csv("in", $ref, "headers", $hdrs, %{$$c{"attr"};}) 272 1 273
1652 );
1653  
1654 272 ▶ $last_err ||= $csv->{'_ERROR_DIAG'};
Condition100%3/3
$last_err ||= $csv->{"_ERROR_DIAG"}
l!l&&r!l&&!r
22664
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
1655 272 return $ref;
1656 } # csv
1657  
1658 36 1;
1659  
1660 __END__
↑ Summary CSV_XS.xs »