Branch Coverage

blib/lib/Text/CSV_XS.pm
Criterion Covered Total %
branch 718 764 93.9


line true false branch
131 12100 3564 unless $aw
134 3562 2 unless defined $quo and length $quo
137 242 3322 if defined $quo and $quo =~ /^[ \t]/
138 290 3032 if defined $esc and $esc =~ /^[ \t]/
148 12323 35 unless defined $sep and length $sep
150 12340 18 unless defined $quo and length $quo
158 2 12356 unless $sep ne ""
159 1 12355 if length $sep > 16
160 6 12349 if $sep =~ /[\r\n]/
162 12339 10 if (defined $quo)
163 228 12111 if $quo eq $sep
164 1 12110 if length $quo > 16
165 6 12104 if $quo =~ /[\r\n]/
167 12098 16 if (defined $esc)
168 168 11930 if $esc eq $sep
169 6 11924 if $esc =~ /[\r\n]/
171 11936 4 if (defined $eol)
172 1 11935 if length $eol > 16
187 1 933 unless my $class = ref $proto || $proto
188 8 925 if @_ > 0 and ref $_[0] ne "HASH"
191 2163 1 /^[a-zA-Z]\w+$/ ? :
192 21 2143 if exists $attr_alias{$k}
197 10 915 if (exists $attr{'sep'})
202 25 900 if (exists $attr{'quote'})
207 12 913 if exists $attr{'formula_handling'}
211 2119 6 if (/^[a-z]/ and exists $def_attr{$_})
213 188 1931 if defined $attr{$_} and /_char$/
218 1 6 if $attr{'auto_diag'}
221 10 908 if ($sep_aliased)
223 6 4 if (@b > 1) { }
231 21 897 if ($quote_aliased and defined $attr{'quote_char'})
233 7 14 if (@b > 1) { }
243 35 883 if (my $ec = _check_sanity($self))
245 1 34 if $attr{'auto_diag'}
248 6 877 if (defined $self->{'callbacks'} and ref $self->{'callbacks'} ne "HASH")
254 8 875 if defined $\ and not exists $attr{'eol'}
256 1 882 if defined $self->{'types'}
257 883 0 if defined $self->{'skip_empty_rows'}
258 36 847 if defined $attr_formula
301 11100 8 if defined $val
303 910 10198 if $ec = _check_sanity($self)
310 1 5640 unless defined $val
326 3601 1235 if (@_)
335 11 9 if (@_)
337 1 10 unless defined $quote
340 5 6 if (@b > 1) { }
341 1 4 if @b > 16
351 1 9 if $ec
356 6 12 defined $quote && length $quote ? :
361 3595 1231 if (@_)
364 6 3474 unless $ec
371 3912 1243 if (@_)
380 326 33 if (@_)
382 1 325 unless defined $sep
385 13 313 if (@b > 1) { }
386 1 12 if @b > 16
396 1 321 if $ec
401 21 333 defined $sep && length $sep ? :
406 125 32 if (@_)
408 3 122 unless defined $eol
409 1 124 if length $eol > 16
418 1799 1233 if @_
424 6 4 if @_
430 3 2 if @_
436 4 2 if @_
443 6 1 if @_
449 12 9 if @_
455 1 1 if @_
461 1 903 unless defined $f
462 5 42 if ($self and $f and ref $f and ref $f eq "CODE")
472 0 0 $f =~ /^(?: 6 | cb )$/xi ? :
5 0 $f =~ /^(?: 5 | error )$/xi ? :
6 5 $f =~ /^(?: 4 | croak )$/xi ? :
6 11 $f =~ /^(?: 3 | die )$/xi ? :
7 17 $f =~ /^(?: 2 | eof | stop )$/xi ? :
18 24 $f =~ /^(?: 1 | skip )$/xi ? :
856 42 $f =~ /^(?: 0 | undef )$/xi ? :
480 21 2 if @_
482 22 1 unless $ser == 6
485 3 1 $ser == 5 ? :
3 4 $ser == 4 ? :
3 7 $ser == 3 ? :
5 10 $ser == 2 ? :
8 15 $ser <= 1 ? :
492 0 17 if $em =~ s/^\d+$//
493 0 17 $em =~ /[;\n]$/ ? :
499 1 102 unless defined $f
500 6 83 if ($self and $f and ref $f and ref $f eq "CODE")
510 2 7 $f =~ /^(?: 6 | cb )$/xi ? :
14 9 $f =~ /^(?: 5 | undef )$/xi ? :
15 23 $f =~ /^(?: 4 | empty | )$/xi ? :
16 38 $f =~ /^(?: 3 | diag )$/xi ? :
13 54 $f =~ /^(?: 2 | croak )$/xi ? :
13 67 $f =~ /^(?: 1 | die )$/xi ? :
16 80 $f =~ /^(?: 0 | none )$/xi ? :
518 29 15 if @_
519 36 2 unless $self->{'formula'} == 6
530 1 1 if @_
536 11 1 if (@_)
538 2 9 if not defined $v or $v eq ""
539 1 1 lc $v eq 'false' ? :
2 9 unless $v =~ /^[0-9]/
547 11 1 if @_
553 11 1 if @_
559 3725 1229 if (@_)
561 4 3721 if _unhealthy_whitespace($self, $aw)
570 2 1 if @_
576 1 1 if @_
582 1 1 if @_
588 7 2 if @_
594 11 1 if (@_)
596 9 2 defined $v ? :
604 14 1 if (@_)
606 13 1 defined $v ? :
614 9 3 if (@_)
616 2 7 if not defined $v or $v eq ""
617 1 1 lc $v eq 'false' ? :
2 7 unless $v =~ /^[0-9]/
625 8 2 if (@_)
627 2 6 if not defined $v or $v eq ""
628 1 1 lc $v eq 'false' ? :
2 6 unless $v =~ /^[0-9]/
651 2 5 if (@_) { }
652 1 1 if (my $types = shift()) { }
671 43 30 if (@_)
674 41 2 if (defined $_[0]) { }
1 1 elsif (@_ > 1) { }
675 2 39 if grep {not defined $_;} @_
676 26 5 @_ % 2 == 0 ? :
8 31 @_ == 1 && ref $_[0] eq 'HASH' ? :
682 14 22 unless $cbk =~ /^[\w.]+$/ and ref $cb->{$cbk} eq "CODE"
685 2 18 if exists $cb->{'error'}
686 18 2 if exists $cb->{'after_parse'}
687 1 19 if exists $cb->{'before_print'}
710 1543 105 if ($self and ref $self and (UNIVERSAL::isa($self, "Text::CSV_XS") and exists $self->{'_ERROR_DIAG'}))
714 251 1292 if exists $self->{'_ERROR_POS'}
716 251 1292 if exists $self->{'_ERROR_FLD'}
719 9 257 if $diag[0] and $self->{'callbacks'} and $self->{'callbacks'}{'error'}
723 285 1424 unless (defined $context)
724 19 266 if ($diag[0] and $diag[0] != 2012)
726 8 11 if $diag[4]
728 4 15 unless ($self and ref $self)
735 2 0 if $self->{'diag_verbose'} and $self->{'_ERROR_INPUT'}
739 12 3 if ($lvl < 2)
741 0 9 if (@c >= 11 and $c[10] and ref $c[10] eq "HASH")
745 0 0 if exists $hints->{'autodie'} and $hints->{'autodie'} or exists $hints->{'guard Fatal'} and not exists $hints->{'no Fatal'}
752 3 12 $lvl > 1 ? :
756 230 1194 $context ? :
772 1397 1 ref $self->{'_STRING'} ? :
783 1599 1 ref $self->{'_FIELDS'} ? :
795 16 5 ref $self->{'_FFLAGS'} ? :
801 2 7 unless ref $self->{'_FFLAGS'} and $idx >= 0 and $idx < @{$self->{'_FFLAGS'};}
802 3 4 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_QUOTED() ? :
808 2 8 unless ref $self->{'_FFLAGS'} and $idx >= 0 and $idx < @{$self->{'_FFLAGS'};}
809 4 4 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_BINARY() ? :
814 8 11 if $idx < 0 or not ref $self->{'_FFLAGS'}
815 1 10 if $idx >= @{$self->{'_FFLAGS'};}
816 4 6 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_MISSING() ? :
854 4 1934 if ref $str
859 1724 207 if (defined $str and $self->Parse($str, $fields, $fflags)) { }
875 293 43 defined $self->{'_COLUMN_NAMES'} ? :
336 681 unless @keys
878 138 543 if @keys == 1 and not defined $keys[0]
880 222 321 if (@keys == 1 and ref $keys[0] eq 'ARRAY') { }
5 316 elsif (join '', map({defined $_ ? ref $_ : '';} @keys)) { }
883 701 1 defined $_ ? :
887 1 537 if $self->{'_BOUND_COLUMNS'} and @keys != @{$self->{'_BOUND_COLUMNS'};}
890 1240 1 defined $_ ? :
897 1 332 unless $fh
901 18 207 if (ref $_ eq "ARRAY")
905 206 1 if (ref $_ eq "HASH")
913 1 330 if defined $args{'munge'} and not defined $args{'munge_column_names'}
914 169 162 unless defined $args{'detect_bom'}
915 323 8 unless defined $args{'set_column_names'}
916 310 21 unless defined $args{'munge_column_names'}
921 323 8 if $args{'set_column_names'}
922 323 8 if $args{'set_column_names'}
924 27 304 if (defined $args{'sep_set'})
925 5 22 unless ref $args{'sep_set'} eq "ARRAY"
930 0 326 if $^O eq "MSWin32"
933 2 324 unless defined $hdr and $hdr ne ""
936 284 40 unless @seps
938 321 411 if index($hdr, $sep) >= 0
941 4 320 if keys %sep >= 2
945 319 1 if ($args{'detect_bom'})
946 24 295 if ($hdr =~ s/^\x00\x00\xfe\xff//) { }
24 271 elsif ($hdr =~ s/^\xff\xfe\x00\x00//) { }
25 246 elsif ($hdr =~ s/^\xfe\xff//) { }
24 222 elsif ($hdr =~ s/^\xff\xfe//) { }
48 174 elsif ($hdr =~ s/^\xef\xbb\xbf//) { }
1 173 elsif ($hdr =~ s/^\xf7\x64\x4c//) { }
1 172 elsif ($hdr =~ s/^\xdd\x73\x66\x73//) { }
1 171 elsif ($hdr =~ s/^\x0e\xfe\xff//) { }
1 170 elsif ($hdr =~ s/^\xfb\xee\x28//) { }
1 169 elsif ($hdr =~ s/^\x84\x31\x95\x33//) { }
36 133 elsif ($hdr =~ s/^\x{feff}//) { }
958 150 169 $enc ? :
960 6 313 if $hdr eq ""
962 144 169 if ($enc)
963 0 144 if $ebcdic and $enc eq "utf-ebcdic"
964 48 96 if ($enc =~ /([13]).le$/)
970 144 0 if ($enc)
971 96 48 if ($enc ne "utf-8")
981 1 313 if ($hdr and $hdr =~ s/\Asep=(\S)([\r\n]+)//i)
983 1 0 unless length $hdr
985 142 172 if ($hdr =~ s/^([^\r\n]+)([\r\n]+)([^\r\n].+)\z/$1/s)
991 0 314 unless open my $h, "<", $hr
993 2 312 unless my $row = $self->getline($h)
996 293 19 if ($args{'munge_column_names'} eq 'lc') { }
7 12 elsif ($args{'munge_column_names'} eq 'uc') { }
3 9 elsif ($args{'munge_column_names'} eq 'db') { }
1010 142 170 if ($ahead)
1013 72 70 if $eol =~ /^\r([^\n]|\z)/
1018 2 310 if ref $args{'munge_column_names'} eq "CODE"
1020 2 1 unless $args{'munge_column_names'}{$_}
1 311 if ref $args{'munge_column_names'} eq "HASH"
1022 2 310 if exists $hdr{''}
1023 1 309 unless (keys %hdr == @hdr)
1027 301 8 if $args{'set_column_names'}
1028 194 115 wantarray ? :
1034 2 2 defined $self->{'_BOUND_COLUMNS'} ? :
4 23 unless @refs
1036 5 18 if (@refs == 1 and not defined $refs[0])
1041 1 17 if $self->{'_COLUMN_NAMES'} and @refs != @{$self->{'_COLUMN_NAMES'};}
1044 74601 5 ref $_ eq 'SCALAR' ? :
2 15 if join "", map({ref $_ eq "SCALAR" ? "" : "*";} @refs)
1054 1 124 unless $self->{'_COLUMN_NAMES'}
1055 2 122 unless my $fr = $self->getline(@args)
1056 5 117 if (ref $self->{'_FFLAGS'})
1058 5 0 @{$fr;} ? :
1060 2 1 if @{$fr;} == 1 and !defined($fr->[0]) || $fr->[0] eq ''
1068 2 244 unless $self->{'_COLUMN_NAMES'}
1076 11 2 if $eol eq ""
1078 1 12 @f == 1 && !defined($f[0]) ? :
1085 1 2 unless $self->{'_COLUMN_NAMES'}
1086 1 1 unless ref $hr eq "HASH"
1097 20 38 unless 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
1109 21 17 if ($type eq "cell")
1114 1 36 unless my($tlr, $tlc, $brr, $brc) = / ^ \s* ([0-9]+ ) \s* , \s* ([0-9]+ ) \s* (?: - \s* ([0-9]+ | \*) \s* , \s* ([0-9]+ | \*) \s* )? $/x
1118 19 17 unless defined $brr
1119 4 26 if $tlr == 0 or $tlc == 0 or $brr ne "*" and $brr == 0 || $brr < $tlr or $brc ne "*" and $brc == 0 || $brc < $tlc
1124 26 2 unless $brc eq "*"
1125 14 14 unless defined $min_row
1126 1 27 if $tlr < $min_row
1127 19 9 if $brr eq "*" or $brr > $max_row
1133 44 33 if ++$r < $min_row
1138 32 45 if $r < $tlr or $brr ne "*" and $r > $brr
1139 36 9 if not defined $lc or $tlc < $lc
1140 5 40 $brc eq '*' ? :
1144 2 31 if (@h)
1148 10 23 if $max_row ne "*" and $r == $max_row
1157 0 25 unless my($from, $to) = /^\s* ([0-9]+) (?: \s* - \s* ([0-9]+ | \* ))? \s* $/x
1160 2 23 if $to eq "*"
1162 3 22 if $from <= 0 or $to < $from
1167 5 9 if $type eq "col"
1171 64 45 if ($type eq "row")
1172 20 44 if ($r > $#r and $eod or $r[$r])
1174 3 17 if (@h)
1181 126 279 $_ > $#r && $eod || $r[$_] ? :
1182 9 36 if (@h)
1194 4 318 @_ == 1 && ref $_[0] eq 'HASH' ? :
0 322 unless my(%attr) = @_ == 1 && ref $_[0] eq 'HASH' ? %{$_[0];} : @_
1199 42 280 if $enc eq "auto"
1200 0 322 $enc =~ s/(:\w.*)// ? :
1201 3 319 if $enc =~ /^[-\w.]+$/
1207 3 319 unless my $in = delete $attr{'in'} || delete $attr{'file'}
1209 0 319 exists $attr{'out'} && !$attr{'out'} ? :
1211 25 294 if ref $in eq "CODE" or ref $in eq "ARRAY"
1213 1 32 if $in and $out and not ref $in and not ref $out
1217 32 286 if ($out)
1218 5 27 if (ref $out and 'ARRAY' eq ref $out || 'HASH' eq ref $out) { }
14 13 elsif (ref $out and 'SCALAR' ne ref $out or 'GLOB' eq ref \$out) { }
1 12 elsif (ref $out and 'SCALAR' eq ref $out and defined ${$out;} and ${$out;} eq 'skip') { }
1230 1 11 unless open $fh, ">", $out
1233 25 6 if ($fh)
1234 1 24 if ($enc)
1238 18 7 unless (defined $attr{'eol'})
1240 1 17 grep(/crlf/, @layers) ? :
1245 24 293 if (ref $in eq 'CODE' or ref $in eq 'ARRAY') { }
25 268 elsif (ref $in eq 'SCALAR') { }
16 252 elsif (ref $in or 'GLOB' eq ref \$in) { }
1251 0 25 unless open $fh, "<", $in
1255 0 16 if (not ref $in and $] < 5.008005) { }
1263 1 250 unless open $fh, "<$enc", $in
1266 0 315 unless $fh or $sink
1298 6 939 if exists $attr{$f} and not exists $attr{$t}
1303 2 8 unless @{$_[1];} > 1
1304 26 0 if defined $_
1305 26 0 if defined $_
1308 3 0 if defined $fltr and not ref $fltr and exists $fltr{$fltr}
1309 2 313 if ref $fltr eq "CODE"
1310 299 16 unless ref $fltr eq "HASH"
1314 286 29 unless defined $attr{'auto_diag'}
1315 314 1 unless defined $attr{'escape_null'}
1316 0 315 unless my $csv = delete $attr{'csv'} || 'Text::CSV_XS'->new(\%attr)
1318 1 314 if defined $form
1320 8 11 if $kh and not ref $kh and $kh =~ /^(?:1|yes|true|internal|auto)$/i
1349 13 310 if @_ and ref $_[0] eq "Text::CSV_XS"
1350 1 322 unless @_
1356 2 313 if (ref $hdrs eq "HASH")
1361 24 291 if ($c->{'out'} and not $c->{'sink'})
1363 4 14 if not $hdrs and ref $c->{'kh'} and $c->{'kh'} == \@internal_kh
1365 3 21 if (ref $in eq 'CODE') { }
10 11 elsif (@{$in;} == 0 or ref $in->[0] eq 'ARRAY') { }
1368 3 4 if (ref $row eq "ARRAY")
1372 4 0 if (ref $row eq "HASH")
1373 2 2 if ($hdr)
1374 3 0 unless $hdr{$_}
1383 0 10 if ref $hdrs
1385 2 10 if $c->{'cboi'}
1386 0 12 if $c->{'cbbo'}
1391 5 6 ref $hdrs ? :
1392 2 9 unless defined $hdrs
1394 19 1 unless $hdr{$_}
10 1 if ref $hdrs || $hdrs eq 'auto' and @hdrs
1398 0 17 if $c->{'cboi'}
1399 0 17 if $c->{'cbbo'}
1404 11 13 if $c->{'cls'}
1409 8 118 if (defined $c->{'hd_s'} or defined $c->{'hd_b'} or defined $c->{'hd_m'} or defined $c->{'hd_c'})
1412 3 160 if not defined $c->{'hd_s'} and $c->{'attr'}{'sep_char'}
1414 3 157 if not defined $c->{'hd_s'} and $c->{'attr'}{'sep'}
1415 16 157 if defined $c->{'hd_s'}
1416 161 12 if defined $c->{'hd_b'}
1417 0 8 $hdrs ? :
8 165 if defined $c->{'hd_m'}
1418 0 4 $hdrs ? :
4 169 if defined $c->{'hd_c'}
1421 166 4 if @hdr
1424 15 273 if ($c->{'kh'})
1426 5 10 unless ref $c->{'kh'} eq "ARRAY"
1431 27 256 if ($key)
1432 7 5 unless not ref $key or ref $key eq "ARRAY" and @{$key;} > 1
1436 9 267 if ($val)
1437 1 8 unless $key
1438 3 2 unless not ref $val or ref $val eq "ARRAY" and @{$val;} > 0
1441 5 267 if $c->{'fltr'} and grep /\D/, keys %{$$c{"fltr"};}
1442 219 53 if (defined $hdrs)
1443 48 171 if (not ref $hdrs or ref $hdrs eq "CODE")
1444 1 47 $c->{'hd_b'} ? :
1449 1 47 if (ref $hdrs) { }
1 46 elsif ($hdrs eq 'skip') { }
44 2 elsif ($hdrs eq 'auto') { }
1 1 elsif ($hdrs eq 'lc') { }
1 0 elsif ($hdrs eq 'uc') { }
1450 0 1 unless $has_h
1458 0 44 unless $has_h
1459 127 1 unless $hdr{$_}
1462 0 1 unless $has_h
1466 0 1 unless $has_h
1470 10 209 if $c->{'kh'} and $hdrs
1473 16 256 if ($c->{'fltr'})
1477 7 9 if (ref $hdrs)
1480 5 16 if exists $f{$hdr[$_]}
1488 51 64 if @hdr
1489 63 52 unless $f{$FLD}->($CSV, $ROW)
1498 2 52 $frag ? :
218 54 ref $hdrs ? :
1501 0 218 if exists $h{''}
1502 0 218 unless (keys %h == @h)
1507 17 199 $key ? :
2 216 $frag ? :
1508 5 12 ref $key ? :
1509 2 15 if (my(@mk) = grep({not exists $h{$_};} grep({defined $_;} $k, @f)))
1514 22 4 defined $k ? :
1519 2 3 ref $val ? :
5 21 $val ? :
1528 264 0 if ($ref) { }
1529 4 164 if @row1 and not $c->{'hd_c'} and not ref $hdrs
1534 248 16 if $c->{'cls'}
1535 22 242 if ($ref and $c->{'cbai'} || $c->{'cboi'})
1537 21 1 ref $ref eq 'ARRAY' ? :
1539 34 37 if ref $r eq "HASH"
1540 30 41 if $c->{'cbai'}
1541 46 25 if $c->{'cboi'}
1545 6 258 if ($c->{'sink'})
1546 0 6 unless my $ro = ref $c->{'out'}
1548 1 5 if $ro eq "SCALAR" and ${$c->{'out'};} eq "skip"
1551 0 5 unless $ro eq ref $ref
1554 4 1 if ($ro eq "ARRAY")
1555 2 2 if (@{$c->{'out'};} and @$ref and ref $c->{'out'}[0] eq ref $ref->[0])
1562 1 0 if ($ro eq "HASH")
1574 1 257 unless defined wantarray