Branch Coverage

blib/lib/Text/CSV_XS.pm
Criterion Covered Total %
branch 740 790 93.6


line true false branch
132 12165 3569 unless $aw
135 3567 2 unless defined $quo and length $quo
138 242 3327 if defined $quo and $quo =~ /^[ \t]/
139 290 3037 if defined $esc and $esc =~ /^[ \t]/
149 12393 35 unless defined $sep and length $sep
151 12410 18 unless defined $quo and length $quo
159 2 12426 unless $sep ne ""
160 1 12425 if length $sep > 16
161 6 12419 if $sep =~ /[\r\n]/
163 12409 10 if (defined $quo)
164 228 12181 if $quo eq $sep
165 1 12180 if length $quo > 16
166 6 12174 if $quo =~ /[\r\n]/
168 12168 16 if (defined $esc)
169 168 12000 if $esc eq $sep
170 6 11994 if $esc =~ /[\r\n]/
172 12005 5 if (defined $eol)
173 1 12004 if length $eol > 16
188 1 1003 unless my $class = ref $proto || $proto
189 8 995 if @_ > 0 and ref $_[0] ne "HASH"
192 2755 1 /^[a-zA-Z]\w+$/ ? :
193 21 2735 if exists $attr_alias{$k}
198 10 985 if (exists $attr{'sep'})
203 25 970 if (exists $attr{'quote'})
208 12 983 if exists $attr{'formula_handling'}
212 2713 6 if (/^[a-z]/ and exists $def_attr{$_})
214 201 2512 if defined $attr{$_} and /_char$/
219 1 6 if $attr{'auto_diag'}
222 10 978 if ($sep_aliased)
224 6 4 if (@b > 1) { }
232 21 967 if ($quote_aliased and defined $attr{'quote_char'})
234 7 14 if (@b > 1) { }
244 35 953 if (my $ec = _check_sanity($self))
246 1 34 if $attr{'auto_diag'}
249 6 947 if (defined $self->{'callbacks'} and ref $self->{'callbacks'} ne "HASH")
255 8 945 if defined $\ and not exists $attr{'eol'}
257 1 952 if defined $self->{'types'}
258 953 0 if defined $self->{'skip_empty_rows'}
259 36 917 if defined $attr_formula
303 11100 8 if defined $val
305 910 10198 if $ec = _check_sanity($self)
312 1 5642 unless defined $val
328 3601 1235 if (@_)
337 11 9 if (@_)
339 1 10 unless defined $quote
342 5 6 if (@b > 1) { }
343 1 4 if @b > 16
353 1 9 if $ec
358 6 12 if (defined $quote and length $quote) { }
363 3595 1231 if (@_)
366 6 3474 unless $ec
373 3912 1243 if (@_)
382 326 33 if (@_)
384 1 325 unless defined $sep
387 13 313 if (@b > 1) { }
388 1 12 if @b > 16
398 1 321 if $ec
403 21 333 if (defined $sep and length $sep) { }
408 227 53 if (@_)
410 129 98 unless defined $eol
411 1 226 if length $eol > 16
425 1799 1233 if @_
431 6 4 if @_
437 3 2 if @_
443 4 2 if @_
450 6 1 if @_
456 12 9 if @_
462 1 1 if @_
468 1 1 if @_
474 1 973 unless defined $f
475 5 56 if ($self and $f and ref $f and ref $f eq "CODE")
485 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 ? :
32 24 $f =~ /^(?: 1 | skip )$/xi ? :
912 56 if ($f =~ /^(?: 0 | undef )$/xi) { }
493 21 2 if @_
495 22 1 unless $ser == 6
498 3 1 $ser == 5 ? :
3 4 $ser == 4 ? :
3 7 $ser == 3 ? :
5 10 $ser == 2 ? :
8 15 if ($ser <= 1) { }
505 0 17 if $em =~ s/^\d+$//
506 0 17 $em =~ /[;\n]$/ ? :
512 1 102 unless defined $f
513 6 83 if ($self and $f and ref $f and ref $f eq "CODE")
523 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 if ($f =~ /^(?: 0 | none )$/xi) { }
531 29 15 if @_
532 36 2 unless $self->{'formula'} == 6
543 1 1 if @_
549 11 1 if (@_)
551 2 9 if not defined $v or $v eq ""
552 1 1 lc $v eq 'false' ? :
2 9 unless $v =~ /^[0-9]/
560 11 1 if @_
566 11 1 if @_
572 3725 1229 if (@_)
574 4 3721 if _unhealthy_whitespace($self, $aw)
583 2 1 if @_
589 1 1 if @_
595 1 1 if @_
601 7 2 if @_
607 11 1 if (@_)
609 9 2 defined $v ? :
617 14 1 if (@_)
619 13 1 defined $v ? :
627 9 3 if (@_)
629 2 7 if not defined $v or $v eq ""
630 1 1 lc $v eq 'false' ? :
2 7 unless $v =~ /^[0-9]/
638 8 2 if (@_)
640 2 6 if not defined $v or $v eq ""
641 1 1 lc $v eq 'false' ? :
2 6 unless $v =~ /^[0-9]/
664 2 5 if (@_) { }
665 1 1 if (my $types = shift()) { }
684 44 30 if (@_)
687 42 2 if (defined $_[0]) { }
1 1 elsif (@_ > 1) { }
688 2 40 if grep {not defined $_;} @_
689 27 5 @_ % 2 == 0 ? :
8 32 @_ == 1 && ref $_[0] eq 'HASH' ? :
695 14 23 unless $cbk =~ /^[\w.]+$/ and ref $cb->{$cbk} eq "CODE"
698 3 18 if exists $cb->{'error'}
699 18 3 if exists $cb->{'after_parse'}
700 1 20 if exists $cb->{'before_print'}
723 1641 108 if ($self and ref $self and (UNIVERSAL::isa($self, __PACKAGE__) and exists $self->{'_ERROR_DIAG'}))
727 300 1341 if exists $self->{'_ERROR_POS'}
729 300 1341 if exists $self->{'_ERROR_FLD'}
730 64 1577 if exists $self->{'_ERROR_SRC'} and $self->{'diag_verbose'}
733 10 279 if $diag[0] and $self->{'callbacks'} and $self->{'callbacks'}{'error'}
737 343 1467 unless (defined $context)
738 36 307 if ($diag[0] and $diag[0] != 2012)
740 25 11 if $diag[4]
741 16 20 if $diag[5]
743 4 32 unless ($self and ref $self)
750 16 0 if $self->{'diag_verbose'} and $self->{'_ERROR_INPUT'}
754 29 3 if ($lvl < 2)
756 0 11 if (@c >= 11 and $c[10] and ref $c[10] eq "HASH")
760 0 0 if exists $hints->{'autodie'} and $hints->{'autodie'} or exists $hints->{'guard Fatal'} and not exists $hints->{'no Fatal'}
767 3 29 $lvl > 1 ? :
771 268 1199 $context ? :
787 1397 1 ref $self->{'_STRING'} ? :
798 1602 1 ref $self->{'_FIELDS'} ? :
810 16 5 ref $self->{'_FFLAGS'} ? :
816 2 7 unless ref $self->{'_FFLAGS'} and $idx >= 0 and $idx < @{$self->{'_FFLAGS'};}
817 3 4 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_QUOTED() ? :
823 2 8 unless ref $self->{'_FFLAGS'} and $idx >= 0 and $idx < @{$self->{'_FFLAGS'};}
824 4 4 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_BINARY() ? :
829 8 11 if $idx < 0 or not ref $self->{'_FFLAGS'}
830 1 10 if $idx >= @{$self->{'_FFLAGS'};}
831 4 6 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_MISSING() ? :
869 4 1943 if ref $str
874 1729 211 if (defined $str and $self->Parse($str, $fields, $fflags)) { }
890 293 43 defined $self->{'_COLUMN_NAMES'} ? :
336 688 unless @keys
893 138 550 if @keys == 1 and not defined $keys[0]
895 226 324 if (@keys == 1 and ref $keys[0] eq 'ARRAY') { }
5 319 elsif (join '', map({defined $_ ? ref $_ : '';} @keys)) { }
898 711 1 defined $_ ? :
902 1 544 if $self->{'_BOUND_COLUMNS'} and @keys != @{$self->{'_BOUND_COLUMNS'};}
905 1258 1 defined $_ ? :
912 1 332 unless $fh
916 18 207 if (ref $_ eq "ARRAY")
920 206 1 if (ref $_ eq "HASH")
928 1 330 if defined $args{'munge'} and not defined $args{'munge_column_names'}
929 169 162 unless defined $args{'detect_bom'}
930 323 8 unless defined $args{'set_column_names'}
931 310 21 unless defined $args{'munge_column_names'}
936 323 8 if $args{'set_column_names'}
937 323 8 if $args{'set_column_names'}
939 27 304 if (defined $args{'sep_set'})
940 5 22 unless ref $args{'sep_set'} eq "ARRAY"
945 0 326 if $^O eq "MSWin32"
948 2 324 unless defined $hdr and $hdr ne ""
951 284 40 unless @seps
953 321 411 if index($hdr, $sep) != -1
956 4 320 if keys %sep >= 2
960 319 1 if ($args{'detect_bom'})
961 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}//) { }
973 150 169 $enc ? :
975 6 313 if $hdr eq ""
977 144 169 if ($enc)
978 0 144 if $ebcdic and $enc eq "utf-ebcdic"
979 48 96 if ($enc =~ /([13]).le$/)
985 144 0 if ($enc)
986 96 48 if ($enc ne "utf-8")
996 1 313 if ($hdr and $hdr =~ s/\Asep=(\S)([\r\n]+)//i)
998 1 0 unless length $hdr
1000 142 172 if ($hdr =~ s/^([^\r\n]+)([\r\n]+)([^\r\n].+)\z/$1/s)
1006 0 314 unless open my $h, "<", $hr
1008 2 312 unless my $row = $self->getline($h)
1011 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') { }
1025 142 170 if ($ahead)
1028 72 70 if $eol =~ /^\r([^\n]|\z)/
1033 2 310 if ref $args{'munge_column_names'} eq "CODE"
1035 2 1 unless $args{'munge_column_names'}{$_}
1 311 if ref $args{'munge_column_names'} eq "HASH"
1037 2 310 if exists $hdr{''}
1038 1 309 unless (keys %hdr == @hdr)
1042 301 8 if $args{'set_column_names'}
1043 194 115 wantarray ? :
1049 2 2 defined $self->{'_BOUND_COLUMNS'} ? :
4 32 unless @refs
1051 5 27 if (@refs == 1 and not defined $refs[0])
1056 1 26 if $self->{'_COLUMN_NAMES'} and @refs != @{$self->{'_COLUMN_NAMES'};}
1059 74627 5 ref $_ eq 'SCALAR' ? :
2 24 if join "", map({ref $_ eq "SCALAR" ? "" : "*";} @refs)
1069 1 130 unless $self->{'_COLUMN_NAMES'}
1070 3 127 unless my $fr = $self->getline(@args)
1071 5 122 if (ref $self->{'_FFLAGS'})
1073 5 0 @{$fr;} ? :
1075 2 1 if @{$fr;} == 1 and !defined($fr->[0]) || $fr->[0] eq ''
1083 2 248 unless $self->{'_COLUMN_NAMES'}
1092 1 33 @f == 1 && !defined($f[0]) ? :
1093 32 2 unless (length $eol)
1102 1 2 unless $self->{'_COLUMN_NAMES'}
1103 1 1 unless ref $hr eq "HASH"
1114 20 38 unless defined $spec and $spec =~ /^ \s*
1126 21 17 if ($type eq "cell")
1131 1 36 unless my($tlr, $tlc, $brr, $brc) = /
1135 19 17 unless defined $brr
1136 4 26 if $tlr == 0 or $tlc == 0 or $brr ne "*" and $brr == 0 || $brr < $tlr or $brc ne "*" and $brc == 0 || $brc < $tlc
1141 26 2 unless $brc eq "*"
1142 14 14 unless defined $min_row
1143 1 27 if $tlr < $min_row
1144 19 9 if $brr eq "*" or $brr > $max_row
1150 44 33 if ++$r < $min_row
1155 32 45 if $r < $tlr or $brr ne "*" and $r > $brr
1156 36 9 if not defined $lc or $tlc < $lc
1157 5 40 $brc eq '*' ? :
1161 2 31 if (@h)
1165 10 23 if $max_row ne "*" and $r == $max_row
1174 0 25 unless my($from, $to) = /^\s* ([0-9]+) (?: \s* - \s* ([0-9]+ | \* ))? \s* $/x
1177 2 23 if $to eq "*"
1179 3 22 if $from <= 0 or $to < $from
1184 5 9 if $type eq "col"
1188 64 45 if ($type eq "row")
1189 20 44 if ($r > $#r and $eod or $r[$r])
1191 3 17 if (@h)
1198 126 279 $_ > $#r && $eod || $r[$_] ? :
1199 9 36 if (@h)
1211 4 339 @_ == 1 && ref $_[0] eq 'HASH' ? :
0 343 unless my(%attr) = @_ == 1 && ref $_[0] eq 'HASH' ? %{$_[0];} : @_
1217 42 301 if $enc eq "auto"
1218 0 343 $enc =~ s/(:\w.*)// ? :
1219 3 340 if $enc =~ /^[-\w.]+$/
1252 3 340 unless my $in = delete $attr{'in'} || delete $attr{'file'}
1254 1 339 exists $attr{'out'} && !$attr{'out'} ? :
1256 25 315 if ref $in eq "CODE" or ref $in eq "ARRAY"
1259 2 5 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')
1261 2 5 if (ref $out or 'GLOB' eq ref \$out) { }
1265 0 5 unless open $fho, ">", $out
1266 0 5 if (my $e = $attr{'encoding'})
1268 0 0 if $hd_b
1272 1 6 if ($cboi and not $cbai)
1276 2 5 if ($cbai) { }
1293 33 307 if ($out)
1294 5 28 if (ref $out and 'ARRAY' eq ref $out || 'HASH' eq ref $out) { }
14 14 elsif (ref $out and 'SCALAR' ne ref $out or 'GLOB' eq ref \$out) { }
2 12 elsif (ref $out and 'SCALAR' eq ref $out and defined ${$out;} and ${$out;} eq 'skip') { }
1306 1 11 unless open $fh, ">", $out
1309 25 7 if ($fh)
1310 1 24 if ($enc)
1314 18 7 unless (defined $attr{'eol'} or defined $fho)
1316 1 17 grep(/crlf/, @layers) ? :
1321 24 315 if (ref $in eq 'CODE' or ref $in eq 'ARRAY') { }
30 285 elsif (ref $in eq 'SCALAR') { }
18 267 elsif (ref $in or 'GLOB' eq ref \$in) { }
1327 0 30 unless open $fh, "<", $in
1331 0 18 if (not ref $in and $] < 5.008005) { }
1339 1 265 unless open $fh, "<$enc", $in
1342 0 337 unless $fh or $sink
1349 6 1005 if exists $attr{$f} and not exists $attr{$t}
1354 2 8 unless @{$_[1];} > 1
1355 26 0 if defined $_
1356 26 0 if defined $_
1359 3 0 if defined $fltr and not ref $fltr and exists $fltr{$fltr}
1360 2 335 if ref $fltr eq "CODE"
1361 321 16 unless ref $fltr eq "HASH"
1365 306 31 unless defined $attr{'auto_diag'}
1366 336 1 unless defined $attr{'escape_null'}
1367 0 337 unless my $csv = delete $attr{'csv'} || 'Text::CSV_XS'->new(\%attr)
1369 1 336 if defined $form
1370 1 336 if defined $cboe
1372 8 11 if $kh and not ref $kh and $kh =~ /^(?:1|yes|true|internal|auto)$/i
1403 13 331 if @_ and ref $_[0] eq __PACKAGE__
1404 1 343 unless @_
1410 2 335 if (ref $hdrs eq "HASH")
1415 24 313 if ($c->{'out'} and not $c->{'sink'})
1417 4 14 if not $hdrs and ref $c->{'kh'} and $c->{'kh'} == \@internal_kh
1419 3 21 if (ref $in eq 'CODE') { }
10 11 elsif (@{$in;} == 0 or ref $in->[0] eq 'ARRAY') { }
1422 3 4 if (ref $row eq "ARRAY")
1426 4 0 if (ref $row eq "HASH")
1427 2 2 if ($hdr)
1428 3 0 unless $hdr{$_}
1437 0 10 if ref $hdrs
1439 2 10 if $c->{'cboi'}
1440 0 12 if $c->{'cbbo'}
1445 5 6 ref $hdrs ? :
1446 2 9 unless defined $hdrs
1448 19 1 unless $hdr{$_}
10 1 if ref $hdrs || $hdrs eq 'auto' and @hdrs
1452 0 17 if $c->{'cboi'}
1453 0 17 if $c->{'cbbo'}
1458 11 13 if $c->{'cls'}
1459 0 24 if $c->{'fho_cls'}
1464 8 140 if (defined $c->{'hd_s'} or defined $c->{'hd_b'} or defined $c->{'hd_m'} or defined $c->{'hd_c'})
1467 3 160 if not defined $c->{'hd_s'} and $c->{'attr'}{'sep_char'}
1469 3 157 if not defined $c->{'hd_s'} and $c->{'attr'}{'sep'}
1470 16 157 if defined $c->{'hd_s'}
1471 161 12 if defined $c->{'hd_b'}
1472 0 8 $hdrs ? :
8 165 if defined $c->{'hd_m'}
1473 0 4 $hdrs ? :
4 169 if defined $c->{'hd_c'}
1476 166 4 if @hdr
1479 15 295 if ($c->{'kh'})
1481 5 10 unless ref $c->{'kh'} eq "ARRAY"
1486 27 278 if ($key)
1487 7 5 unless not ref $key or ref $key eq "ARRAY" and @{$key;} > 1
1491 9 289 if ($val)
1492 1 8 unless $key
1493 3 2 unless not ref $val or ref $val eq "ARRAY" and @{$val;} > 0
1496 5 289 if $c->{'fltr'} and grep /\D/, keys %{$$c{"fltr"};}
1497 223 71 if (defined $hdrs)
1498 52 171 if (not ref $hdrs or ref $hdrs eq "CODE")
1499 1 51 $c->{'hd_b'} ? :
1504 1 51 if (ref $hdrs) { }
1 50 elsif ($hdrs eq 'skip') { }
48 2 elsif ($hdrs eq 'auto') { }
1 1 elsif ($hdrs eq 'lc') { }
1 0 elsif ($hdrs eq 'uc') { }
1505 0 1 unless $has_h
1513 0 48 unless $has_h
1514 135 1 unless $hdr{$_}
1517 0 1 unless $has_h
1521 0 1 unless $has_h
1525 10 213 if $c->{'kh'} and $hdrs
1528 16 278 if ($c->{'fltr'})
1532 7 9 if (ref $hdrs)
1535 5 16 if exists $f{$hdr[$_]}
1543 51 64 if @hdr
1544 63 52 unless $f{$FLD}->($CSV, $ROW)
1553 2 70 $frag ? :
222 72 ref $hdrs ? :
1556 0 222 if exists $h{''}
1557 0 222 unless (keys %h == @h)
1562 17 203 $key ? :
2 220 if ($frag) { }
17 203 elsif ($key) { }
1563 5 12 ref $key ? :
1564 2 15 if (my(@mk) = grep({not exists $h{$_};} grep({defined $_;} $k, @f)))
1569 22 4 defined $k ? :
1574 2 3 ref $val ? :
5 21 $val ? :
1583 286 0 if ($ref) { }
1584 4 164 if @row1 and not $c->{'hd_c'} and not ref $hdrs
1589 268 18 if $c->{'cls'}
1590 0 286 if $c->{'fho_cls'}
1591 23 263 if ($ref and $c->{'cbai'} || $c->{'cboi'})
1593 22 1 ref $ref eq 'ARRAY' ? :
1595 34 40 if ref $r eq "HASH"
1596 33 41 if $c->{'cbai'}
1597 46 28 if $c->{'cboi'}
1601 14 272 if ($c->{'sink'})
1602 7 7 unless my $ro = ref $c->{'out'}
1604 2 5 if $ro eq "SCALAR" and ${$c->{'out'};} eq "skip"
1607 0 5 unless $ro eq ref $ref
1610 4 1 if ($ro eq "ARRAY")
1611 2 2 if (@{$c->{'out'};} and @$ref and ref $c->{'out'}[0] eq ref $ref->[0])
1618 1 0 if ($ro eq "HASH")
1630 1 271 unless defined wantarray