Branch Coverage

blib/lib/Text/CSV_XS.pm
Criterion Covered Total %
branch 743 790 94.0


line true false branch
132 12166 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 12394 35 unless defined $sep and length $sep
151 12411 18 unless defined $quo and length $quo
159 2 12427 unless $sep ne ""
160 1 12426 if length $sep > 16
161 6 12420 if $sep =~ /[\r\n]/
163 12410 10 if (defined $quo)
164 228 12182 if $quo eq $sep
165 1 12181 if length $quo > 16
166 6 12175 if $quo =~ /[\r\n]/
168 12169 16 if (defined $esc)
169 168 12001 if $esc eq $sep
170 6 11995 if $esc =~ /[\r\n]/
172 12006 5 if (defined $eol)
173 1 12005 if length $eol > 16
188 1 1004 unless my $class = ref $proto || $proto
189 8 996 if @_ > 0 and ref $_[0] ne "HASH"
192 2760 1 /^[a-zA-Z]\w+$/ ? :
193 21 2740 if exists $attr_alias{$k}
198 10 986 if (exists $attr{'sep'})
203 25 971 if (exists $attr{'quote'})
208 12 984 if exists $attr{'formula_handling'}
212 2718 6 if (/^[a-z]/ and exists $def_attr{$_})
214 201 2517 if defined $attr{$_} and /_char$/
219 1 6 if $attr{'auto_diag'}
222 10 979 if ($sep_aliased)
224 6 4 if (@b > 1) { }
232 21 968 if ($quote_aliased and defined $attr{'quote_char'})
234 7 14 if (@b > 1) { }
244 35 954 if (my $ec = _check_sanity($self))
246 1 34 if $attr{'auto_diag'}
249 6 948 if (defined $self->{'callbacks'} and ref $self->{'callbacks'} ne "HASH")
255 8 946 if defined $\ and not exists $attr{'eol'}
257 1 953 if defined $self->{'types'}
258 954 0 if defined $self->{'skip_empty_rows'}
259 36 918 if defined $attr_formula
303 11100 8 if defined $val
305 910 10198 if $ec = _check_sanity($self)
312 1 5643 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 975 unless defined $f
475 5 57 if ($self and $f and ref $f and ref $f eq "CODE")
485 0 1 $f =~ /^(?: 6 | cb )$/xi ? :
5 1 $f =~ /^(?: 5 | error )$/xi ? :
6 6 $f =~ /^(?: 4 | croak )$/xi ? :
6 12 $f =~ /^(?: 3 | die )$/xi ? :
7 18 $f =~ /^(?: 2 | eof | stop )$/xi ? :
32 25 $f =~ /^(?: 1 | skip )$/xi ? :
913 57 if ($f =~ /^(?: 0 | undef )$/xi) { }
493 22 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 18 if $em =~ s/^\d+$//
506 0 18 $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 45 30 if (@_)
687 43 2 if (defined $_[0]) { }
1 1 elsif (@_ > 1) { }
688 2 41 if grep {not defined $_;} @_
689 28 5 @_ % 2 == 0 ? :
8 33 @_ == 1 && ref $_[0] eq 'HASH' ? :
695 14 24 unless $cbk =~ /^[\w.]+$/ and ref $cb->{$cbk} eq "CODE"
698 3 19 if exists $cb->{'error'}
699 19 3 if exists $cb->{'after_parse'}
700 1 21 if exists $cb->{'before_print'}
723 1644 108 if ($self and ref $self and (UNIVERSAL::isa($self, __PACKAGE__) and exists $self->{'_ERROR_DIAG'}))
727 300 1344 if exists $self->{'_ERROR_POS'}
729 300 1344 if exists $self->{'_ERROR_FLD'}
730 64 1580 if exists $self->{'_ERROR_SRC'} and $self->{'diag_verbose'}
733 10 280 if $diag[0] and $self->{'callbacks'} and $self->{'callbacks'}{'error'}
737 344 1469 unless (defined $context)
738 36 308 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 269 1200 $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 689 unless @keys
893 138 551 if @keys == 1 and not defined $keys[0]
895 227 324 if (@keys == 1 and ref $keys[0] eq 'ARRAY') { }
5 319 elsif (join '', map({defined $_ ? ref $_ : '';} @keys)) { }
898 711 1 defined $_ ? :
902 1 545 if $self->{'_BOUND_COLUMNS'} and @keys != @{$self->{'_BOUND_COLUMNS'};}
905 1261 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 249 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* \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
1126 21 17 if ($type eq "cell")
1131 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
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)
1212 4 341 if (@_ == 1 and ref $_[0] eq 'HASH') { }
1 340 elsif (scalar @_ % 2) { }
1226 42 302 if $enc eq "auto"
1227 0 344 $enc =~ s/(:\w.*)// ? :
1228 3 341 if $enc =~ /^[-\w.]+$/
1261 3 341 unless my $in = delete $attr{'in'} || delete $attr{'file'}
1263 1 340 exists $attr{'out'} && !$attr{'out'} ? :
1265 25 316 if ref $in eq "CODE" or ref $in eq "ARRAY"
1268 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')
1270 2 5 if (ref $out or 'GLOB' eq ref \$out) { }
1274 0 5 unless open $fho, ">", $out
1275 0 5 if (my $e = $attr{'encoding'})
1277 0 0 if $hd_b
1281 1 6 if ($cboi and not $cbai)
1285 2 5 if ($cbai) { }
1302 33 308 if ($out)
1303 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') { }
1315 1 11 unless open $fh, ">", $out
1318 25 7 if ($fh)
1319 1 24 if ($enc)
1323 18 7 unless (defined $attr{'eol'} or defined $fho)
1325 1 17 grep(/crlf/, @layers) ? :
1330 24 316 if (ref $in eq 'CODE' or ref $in eq 'ARRAY') { }
30 286 elsif (ref $in eq 'SCALAR') { }
18 268 elsif (ref $in or 'GLOB' eq ref \$in) { }
1336 0 30 unless open $fh, "<", $in
1340 0 18 if (not ref $in and $] < 5.008005) { }
1348 1 266 unless open $fh, "<$enc", $in
1351 0 338 unless $fh or $sink
1358 6 1008 if exists $attr{$f} and not exists $attr{$t}
1363 2 8 unless @{$_[1];} > 1
1364 26 0 if defined $_
1365 26 0 if defined $_
1368 3 0 if defined $fltr and not ref $fltr and exists $fltr{$fltr}
1369 2 336 if ref $fltr eq "CODE"
1370 321 17 unless ref $fltr eq "HASH"
1374 307 31 unless defined $attr{'auto_diag'}
1375 337 1 unless defined $attr{'escape_null'}
1376 0 338 unless my $csv = delete $attr{'csv'} || 'Text::CSV_XS'->new(\%attr)
1378 1 337 if defined $form
1379 1 337 if defined $cboe
1381 8 11 if $kh and not ref $kh and $kh =~ /^(?:1|yes|true|internal|auto)$/i
1412 13 333 if @_ and ref $_[0] eq __PACKAGE__
1413 1 345 unless @_
1419 2 336 if (ref $hdrs eq "HASH")
1424 24 314 if ($c->{'out'} and not $c->{'sink'})
1426 4 14 if not $hdrs and ref $c->{'kh'} and $c->{'kh'} == \@internal_kh
1428 3 21 if (ref $in eq 'CODE') { }
10 11 elsif (@{$in;} == 0 or ref $in->[0] eq 'ARRAY') { }
1431 3 4 if (ref $row eq "ARRAY")
1435 4 0 if (ref $row eq "HASH")
1436 2 2 if ($hdr)
1437 3 0 unless $hdr{$_}
1446 0 10 if ref $hdrs
1448 2 10 if $c->{'cboi'}
1449 0 12 if $c->{'cbbo'}
1454 5 6 ref $hdrs ? :
1455 2 9 unless defined $hdrs
1457 19 1 unless $hdr{$_}
10 1 if ref $hdrs || $hdrs eq 'auto' and @hdrs
1461 0 17 if $c->{'cboi'}
1462 0 17 if $c->{'cbbo'}
1467 11 13 if $c->{'cls'}
1468 0 24 if $c->{'fho_cls'}
1473 8 141 if (defined $c->{'hd_s'} or defined $c->{'hd_b'} or defined $c->{'hd_m'} or defined $c->{'hd_c'})
1476 3 160 if not defined $c->{'hd_s'} and $c->{'attr'}{'sep_char'}
1478 3 157 if not defined $c->{'hd_s'} and $c->{'attr'}{'sep'}
1479 16 157 if defined $c->{'hd_s'}
1480 161 12 if defined $c->{'hd_b'}
1481 0 8 $hdrs ? :
8 165 if defined $c->{'hd_m'}
1482 0 4 $hdrs ? :
4 169 if defined $c->{'hd_c'}
1485 166 4 if @hdr
1488 15 296 if ($c->{'kh'})
1490 5 10 unless ref $c->{'kh'} eq "ARRAY"
1495 27 279 if ($key)
1496 7 5 unless not ref $key or ref $key eq "ARRAY" and @{$key;} > 1
1500 9 290 if ($val)
1501 1 8 unless $key
1502 3 2 unless not ref $val or ref $val eq "ARRAY" and @{$val;} > 0
1505 6 289 if $c->{'fltr'} and grep /\D/, keys %{$$c{"fltr"};}
1506 224 71 if (defined $hdrs)
1507 53 171 if (not ref $hdrs or ref $hdrs eq "CODE")
1508 1 52 $c->{'hd_b'} ? :
1513 1 52 if (ref $hdrs) { }
1 51 elsif ($hdrs eq 'skip') { }
49 2 elsif ($hdrs eq 'auto') { }
1 1 elsif ($hdrs eq 'lc') { }
1 0 elsif ($hdrs eq 'uc') { }
1514 0 1 unless $has_h
1522 0 49 unless $has_h
1523 138 1 unless $hdr{$_}
1526 0 1 unless $has_h
1530 0 1 unless $has_h
1534 10 214 if $c->{'kh'} and $hdrs
1537 17 278 if ($c->{'fltr'})
1541 8 9 if (ref $hdrs)
1544 6 18 if exists $f{$hdr[$_]}
1552 53 64 if @hdr
1553 64 53 unless $f{$FLD}->($CSV, $ROW)
1562 2 70 $frag ? :
223 72 ref $hdrs ? :
1565 0 223 if exists $h{''}
1566 0 223 unless (keys %h == @h)
1571 17 204 $key ? :
2 221 if ($frag) { }
17 204 elsif ($key) { }
1572 5 12 ref $key ? :
1573 2 15 if (my(@mk) = grep({not exists $h{$_};} grep({defined $_;} $k, @f)))
1578 22 4 defined $k ? :
1583 2 3 ref $val ? :
5 21 $val ? :
1592 287 0 if ($ref) { }
1593 4 164 if @row1 and not $c->{'hd_c'} and not ref $hdrs
1598 269 18 if $c->{'cls'}
1599 0 287 if $c->{'fho_cls'}
1600 23 264 if ($ref and $c->{'cbai'} || $c->{'cboi'})
1602 22 1 ref $ref eq 'ARRAY' ? :
1604 34 40 if ref $r eq "HASH"
1605 33 41 if $c->{'cbai'}
1606 46 28 if $c->{'cboi'}
1610 14 273 if ($c->{'sink'})
1611 7 7 unless my $ro = ref $c->{'out'}
1613 2 5 if $ro eq "SCALAR" and ${$c->{'out'};} eq "skip"
1616 0 5 unless $ro eq ref $ref
1619 4 1 if ($ro eq "ARRAY")
1620 2 2 if (@{$c->{'out'};} and @$ref and ref $c->{'out'}[0] eq ref $ref->[0])
1627 1 0 if ($ro eq "HASH")
1639 1 272 unless defined wantarray