Branch Coverage

blib/lib/Text/CSV_XS.pm
Criterion Covered Total %
branch 687 730 94.1


line true false branch
133 12047 3564 unless $aw
136 3562 2 unless defined $quo and length $quo
139 242 3322 if defined $quo and $quo =~ /^[ \t]/
140 290 3032 if defined $esc and $esc =~ /^[ \t]/
150 12270 35 unless defined $sep and length $sep
152 12287 18 unless defined $quo and length $quo
160 2 12303 unless $sep ne ""
161 1 12302 if length $sep > 16
162 6 12296 if $sep =~ /[\r\n]/
164 12286 10 if (defined $quo)
165 228 12058 if $quo eq $sep
166 1 12057 if length $quo > 16
167 6 12051 if $quo =~ /[\r\n]/
169 12045 16 if (defined $esc)
170 168 11877 if $esc eq $sep
171 6 11871 if $esc =~ /[\r\n]/
173 11883 4 if (defined $eol)
174 1 11882 if length $eol > 16
189 1 906 unless my $class = ref $proto || $proto
190 8 898 if @_ > 0 and ref $_[0] ne "HASH"
193 2073 1 /^[a-zA-Z]\w+$/ ? :
194 21 2053 if exists $attr_alias{$k}
199 10 888 if (exists $attr{'sep'})
204 25 873 if (exists $attr{'quote'})
209 12 886 if exists $attr{'formula_handling'}
213 2030 6 if (/^[a-z]/ and exists $def_attr{$_})
215 188 1842 if defined $attr{$_} and /_char$/
220 1 6 if $attr{'auto_diag'}
223 10 881 if ($sep_aliased)
225 6 4 if (@b > 1) { }
233 21 870 if ($quote_aliased and defined $attr{'quote_char'})
235 7 14 if (@b > 1) { }
245 35 856 if (my $ec = _check_sanity($self))
247 1 34 if $attr{'auto_diag'}
250 6 850 if (defined $self->{'callbacks'} and ref $self->{'callbacks'} ne "HASH")
256 8 848 if defined $\ and not exists $attr{'eol'}
258 1 855 if defined $self->{'types'}
259 36 820 if defined $attr_formula
302 11087 8 if defined $val
304 910 10185 if $ec = _check_sanity($self)
311 1 5641 unless defined $val
327 3601 1235 if (@_)
336 11 9 if (@_)
338 1 10 unless defined $quote
341 5 6 if (@b > 1) { }
342 1 4 if @b > 16
352 1 9 if $ec
357 6 12 defined $quote && length $quote ? :
362 3595 1231 if (@_)
365 6 3474 unless $ec
372 3899 1243 if (@_)
381 313 33 if (@_)
383 1 312 unless defined $sep
386 13 300 if (@b > 1) { }
387 1 12 if @b > 16
397 1 308 if $ec
402 21 320 defined $sep && length $sep ? :
407 125 32 if (@_)
409 3 122 unless defined $eol
410 1 124 if length $eol > 16
419 1799 1233 if @_
425 6 4 if @_
431 3 2 if @_
437 4 2 if @_
444 6 1 if @_
450 12 9 if @_
456 1 1 if @_
462 1 1 if @_
470 0 17 if $em =~ s/^\d+$//
471 0 17 $em =~ /[;\n]$/ ? :
477 1 102 unless defined $f
478 6 83 if ($self and $f and ref $f and ref $f eq "CODE")
488 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 ? :
496 29 15 if @_
497 36 2 unless $self->{'formula'} == 6
507 1 1 if @_
513 11 1 if (@_)
515 2 9 if not defined $v or $v eq ""
516 1 1 lc $v eq 'false' ? :
2 9 unless $v =~ /^[0-9]/
524 11 1 if @_
530 11 1 if @_
536 3725 1229 if (@_)
538 4 3721 if _unhealthy_whitespace($self, $aw)
547 2 1 if @_
553 1 1 if @_
559 1 1 if @_
565 7 2 if @_
571 11 1 if (@_)
573 9 2 defined $v ? :
581 14 1 if (@_)
583 13 1 defined $v ? :
591 9 3 if (@_)
593 2 7 if not defined $v or $v eq ""
594 1 1 lc $v eq 'false' ? :
2 7 unless $v =~ /^[0-9]/
602 8 2 if (@_)
604 2 6 if not defined $v or $v eq ""
605 1 1 lc $v eq 'false' ? :
2 6 unless $v =~ /^[0-9]/
628 2 5 if (@_) { }
629 1 1 if (my $types = shift()) { }
648 43 30 if (@_)
651 41 2 if (defined $_[0]) { }
1 1 elsif (@_ > 1) { }
652 2 39 if grep {not defined $_;} @_
653 26 5 @_ % 2 == 0 ? :
8 31 @_ == 1 && ref $_[0] eq 'HASH' ? :
659 14 22 unless $cbk =~ /^[\w.]+$/ and ref $cb->{$cbk} eq "CODE"
662 2 18 if exists $cb->{'error'}
663 18 2 if exists $cb->{'after_parse'}
664 1 19 if exists $cb->{'before_print'}
687 1535 105 if ($self and ref $self and (UNIVERSAL::isa($self, "Text::CSV_XS") and exists $self->{'_ERROR_DIAG'}))
691 251 1284 if exists $self->{'_ERROR_POS'}
693 251 1284 if exists $self->{'_ERROR_FLD'}
696 9 253 if $diag[0] and $self->{'callbacks'} and $self->{'callbacks'}{'error'}
700 281 1420 unless (defined $context)
701 19 262 if ($diag[0] and $diag[0] != 2012)
703 8 11 if $diag[4]
705 4 15 unless ($self and ref $self)
712 2 0 if $self->{'diag_verbose'} and $self->{'_ERROR_INPUT'}
716 12 3 if ($lvl < 2)
718 0 9 if (@c >= 11 and $c[10] and ref $c[10] eq "HASH")
722 0 0 if exists $hints->{'autodie'} and $hints->{'autodie'} or exists $hints->{'guard Fatal'} and not exists $hints->{'no Fatal'}
729 3 12 $lvl > 1 ? :
733 228 1192 $context ? :
749 1397 1 ref $self->{'_STRING'} ? :
760 1599 1 ref $self->{'_FIELDS'} ? :
772 16 5 ref $self->{'_FFLAGS'} ? :
778 2 7 unless ref $self->{'_FFLAGS'} and $idx >= 0 and $idx < @{$self->{'_FFLAGS'};}
779 3 4 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_QUOTED() ? :
785 2 8 unless ref $self->{'_FFLAGS'} and $idx >= 0 and $idx < @{$self->{'_FFLAGS'};}
786 4 4 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_BINARY() ? :
791 8 11 if $idx < 0 or not ref $self->{'_FFLAGS'}
792 1 10 if $idx >= @{$self->{'_FFLAGS'};}
793 4 6 $self->{'_FFLAGS'}[$idx] & CSV_FLAGS_IS_MISSING() ? :
831 4 1934 if ref $str
836 1724 207 if (defined $str and $self->Parse($str, $fields, $fflags)) { }
852 282 43 defined $self->{'_COLUMN_NAMES'} ? :
325 657 unless @keys
855 138 519 if @keys == 1 and not defined $keys[0]
857 211 308 if (@keys == 1 and ref $keys[0] eq 'ARRAY') { }
5 303 elsif (join '', map({defined $_ ? ref $_ : '';} @keys)) { }
860 654 1 defined $_ ? :
864 1 513 if $self->{'_BOUND_COLUMNS'} and @keys != @{$self->{'_BOUND_COLUMNS'};}
867 1152 1 defined $_ ? :
874 1 319 unless $fh
878 18 194 if (ref $_ eq "ARRAY")
882 193 1 if (ref $_ eq "HASH")
890 1 317 if defined $args{'munge'} and not defined $args{'munge_column_names'}
891 317 1 unless defined $args{'detect_bom'}
892 310 8 unless defined $args{'set_column_names'}
893 297 21 unless defined $args{'munge_column_names'}
898 310 8 if $args{'set_column_names'}
899 310 8 if $args{'set_column_names'}
901 27 291 if (defined $args{'sep_set'})
902 5 22 unless ref $args{'sep_set'} eq "ARRAY"
907 0 313 if $^O eq "MSWin32"
910 2 311 unless defined $hdr and $hdr ne ""
913 271 40 unless @seps
915 308 398 if index($hdr, $sep) >= 0
918 4 307 if keys %sep >= 2
922 306 1 if ($args{'detect_bom'})
923 24 282 if ($hdr =~ s/^\x00\x00\xfe\xff//) { }
24 258 elsif ($hdr =~ s/^\xff\xfe\x00\x00//) { }
25 233 elsif ($hdr =~ s/^\xfe\xff//) { }
24 209 elsif ($hdr =~ s/^\xff\xfe//) { }
48 161 elsif ($hdr =~ s/^\xef\xbb\xbf//) { }
1 160 elsif ($hdr =~ s/^\xf7\x64\x4c//) { }
1 159 elsif ($hdr =~ s/^\xdd\x73\x66\x73//) { }
1 158 elsif ($hdr =~ s/^\x0e\xfe\xff//) { }
1 157 elsif ($hdr =~ s/^\xfb\xee\x28//) { }
1 156 elsif ($hdr =~ s/^\x84\x31\x95\x33//) { }
36 120 elsif ($hdr =~ s/^\x{feff}//) { }
935 150 156 $enc ? :
937 6 300 if $hdr eq ""
939 144 156 if ($enc)
940 0 144 if $ebcdic and $enc eq "utf-ebcdic"
941 48 96 if ($enc =~ /([13]).le$/)
947 144 0 if ($enc)
948 96 48 if ($enc ne "utf-8")
958 1 300 if ($hdr and $hdr =~ s/\Asep=(\S)([\r\n]+)//i)
960 1 0 unless length $hdr
962 142 159 if ($hdr =~ s/^([^\r\n]+)([\r\n]+)([^\r\n].+)\z/$1/s)
968 0 301 unless open my $h, "<", $hr
970 2 299 unless my $row = $self->getline($h)
973 280 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') { }
987 142 157 if ($ahead)
990 72 70 if $eol =~ /^\r([^\n]|\z)/
995 2 297 if ref $args{'munge_column_names'} eq "CODE"
997 2 1 unless $args{'munge_column_names'}{$_}
1 298 if ref $args{'munge_column_names'} eq "HASH"
999 2 297 if exists $hdr{''}
1000 1 296 unless (keys %hdr == @hdr)
1004 288 8 if $args{'set_column_names'}
1005 181 115 wantarray ? :
1011 2 2 defined $self->{'_BOUND_COLUMNS'} ? :
4 23 unless @refs
1013 5 18 if (@refs == 1 and not defined $refs[0])
1018 1 17 if $self->{'_COLUMN_NAMES'} and @refs != @{$self->{'_COLUMN_NAMES'};}
1021 74601 5 ref $_ eq 'SCALAR' ? :
2 15 if join "", map({ref $_ eq "SCALAR" ? "" : "*";} @refs)
1031 1 118 unless $self->{'_COLUMN_NAMES'}
1032 2 116 unless my $fr = $self->getline(@args)
1033 5 111 if (ref $self->{'_FFLAGS'})
1035 5 0 @{$fr;} ? :
1037 2 1 if @{$fr;} == 1 and !defined($fr->[0]) || $fr->[0] eq ''
1045 2 233 unless $self->{'_COLUMN_NAMES'}
1053 11 2 if $eol eq ""
1055 1 12 @f == 1 && !defined($f[0]) ? :
1062 1 2 unless $self->{'_COLUMN_NAMES'}
1063 1 1 unless ref $hr eq "HASH"
1074 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
1086 21 17 if ($type eq "cell")
1091 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
1095 19 17 unless defined $brr
1096 4 26 if $tlr == 0 or $tlc == 0 or $brr ne "*" and $brr == 0 || $brr < $tlr or $brc ne "*" and $brc == 0 || $brc < $tlc
1101 26 2 unless $brc eq "*"
1102 14 14 unless defined $min_row
1103 1 27 if $tlr < $min_row
1104 19 9 if $brr eq "*" or $brr > $max_row
1110 44 33 if ++$r < $min_row
1115 32 45 if $r < $tlr or $brr ne "*" and $r > $brr
1116 36 9 if not defined $lc or $tlc < $lc
1117 5 40 $brc eq '*' ? :
1121 2 31 if (@h)
1125 10 23 if $max_row ne "*" and $r == $max_row
1134 0 25 unless my($from, $to) = /^\s* ([0-9]+) (?: \s* - \s* ([0-9]+ | \* ))? \s* $/x
1137 2 23 if $to eq "*"
1139 3 22 if $from <= 0 or $to < $from
1144 5 9 if $type eq "col"
1148 64 45 if ($type eq "row")
1149 20 44 if ($r > $#r and $eod or $r[$r])
1151 3 17 if (@h)
1158 126 279 $_ > $#r && $eod || $r[$_] ? :
1159 9 36 if (@h)
1171 4 296 @_ == 1 && ref $_[0] eq 'HASH' ? :
0 300 unless my(%attr) = @_ == 1 && ref $_[0] eq 'HASH' ? %{$_[0];} : @_
1176 42 258 if $enc eq "auto"
1177 0 300 $enc =~ s/(:\w.*)// ? :
1178 3 297 if $enc =~ /^[-\w.]+$/
1184 3 297 unless my $in = delete $attr{'in'} || delete $attr{'file'}
1186 0 297 exists $attr{'out'} && !$attr{'out'} ? :
1188 25 272 if ref $in eq "CODE" or ref $in eq "ARRAY"
1190 1 32 if $in and $out and not ref $in and not ref $out
1194 32 264 if ($out)
1195 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') { }
1207 1 11 unless open $fh, ">", $out
1210 25 6 if ($fh)
1211 1 24 if ($enc)
1215 18 7 unless (defined $attr{'eol'})
1217 1 17 grep(/crlf/, @layers) ? :
1222 24 271 if (ref $in eq 'CODE' or ref $in eq 'ARRAY') { }
23 248 elsif (ref $in eq 'SCALAR') { }
16 232 elsif (ref $in or 'GLOB' eq ref \$in) { }
1228 0 23 unless open $fh, "<", $in
1232 0 16 if (not ref $in and $] < 5.008005) { }
1240 1 230 unless open $fh, "<$enc", $in
1243 0 293 unless $fh or $sink
1275 6 873 if exists $attr{$f} and not exists $attr{$t}
1280 2 8 unless @{$_[1];} > 1
1281 26 0 if defined $_
1282 26 0 if defined $_
1285 3 0 if defined $fltr and not ref $fltr and exists $fltr{$fltr}
1286 2 291 if ref $fltr eq "CODE"
1287 277 16 unless ref $fltr eq "HASH"
1291 280 13 unless defined $attr{'auto_diag'}
1292 292 1 unless defined $attr{'escape_null'}
1293 0 293 unless my $csv = delete $attr{'csv'} || 'Text::CSV_XS'->new(\%attr)
1295 1 292 if defined $form
1297 8 11 if $kh and not ref $kh and $kh =~ /^(?:1|yes|true|internal|auto)$/i
1326 9 292 if @_ and ref $_[0] eq "Text::CSV_XS"
1327 1 300 unless @_
1333 2 291 if (ref $hdrs eq "HASH")
1338 24 269 if ($c->{'out'} and not $c->{'sink'})
1340 4 14 if not $hdrs and ref $c->{'kh'} and $c->{'kh'} == \@internal_kh
1342 3 21 if (ref $in eq 'CODE') { }
10 11 elsif (@{$in;} == 0 or ref $in->[0] eq 'ARRAY') { }
1345 3 4 if (ref $row eq "ARRAY")
1349 4 0 if (ref $row eq "HASH")
1350 2 2 if ($hdr)
1351 3 0 unless $hdr{$_}
1360 0 10 if ref $hdrs
1362 2 10 if $c->{'cboi'}
1363 0 12 if $c->{'cbbo'}
1368 5 6 ref $hdrs ? :
1369 2 9 unless defined $hdrs
1371 19 1 unless $hdr{$_}
10 1 if ref $hdrs || $hdrs eq 'auto' and @hdrs
1375 0 17 if $c->{'cboi'}
1376 0 17 if $c->{'cbbo'}
1381 11 13 if $c->{'cls'}
1386 8 106 if (defined $c->{'hd_s'} or defined $c->{'hd_b'} or defined $c->{'hd_m'} or defined $c->{'hd_c'})
1389 3 150 if not defined $c->{'hd_s'} and $c->{'attr'}{'sep_char'}
1391 3 147 if not defined $c->{'hd_s'} and $c->{'attr'}{'sep'}
1392 16 147 if defined $c->{'hd_s'}
1393 0 163 if defined $c->{'hd_d'}
1394 0 8 $hdrs ? :
8 155 if defined $c->{'hd_m'}
1395 0 4 $hdrs ? :
4 159 if defined $c->{'hd_c'}
1398 156 4 if @hdr
1401 15 251 if ($c->{'kh'})
1403 5 10 unless ref $c->{'kh'} eq "ARRAY"
1408 27 234 if ($key)
1409 7 5 unless not ref $key or ref $key eq "ARRAY" and @{$key;} > 1
1413 9 245 if ($val)
1414 1 8 unless $key
1415 3 2 unless not ref $val or ref $val eq "ARRAY" and @{$val;} > 0
1418 5 245 if $c->{'fltr'} and grep /\D/, keys %{$$c{"fltr"};}
1419 208 42 if (defined $hdrs)
1420 45 163 if (not ref $hdrs) { }
1 162 elsif (ref $hdrs eq 'CODE') { }
1421 1 44 if ($hdrs eq 'skip') { }
42 2 elsif ($hdrs eq 'auto') { }
1 1 elsif ($hdrs eq 'lc') { }
1 0 elsif ($hdrs eq 'uc') { }
1425 0 42 unless my $h = $csv->getline($fh)
1426 121 1 unless $hdr{$_}
1429 0 1 unless my $h = $csv->getline($fh)
1433 0 1 unless my $h = $csv->getline($fh)
1438 0 1 unless my $h = $csv->getline($fh)
1442 10 198 if $c->{'kh'} and $hdrs
1445 16 234 if ($c->{'fltr'})
1449 7 9 if (ref $hdrs)
1452 5 16 if exists $f{$hdr[$_]}
1460 51 64 if @hdr
1461 63 52 unless $f{$FLD}->($CSV, $ROW)
1470 2 41 $frag ? :
207 43 ref $hdrs ? :
1473 0 207 if exists $h{''}
1474 0 207 unless (keys %h == @h)
1479 17 188 $key ? :
2 205 $frag ? :
1480 5 12 ref $key ? :
1481 2 15 if (my(@mk) = grep({not exists $h{$_};} grep({defined $_;} $k, @f)))
1486 22 4 defined $k ? :
1491 2 3 ref $val ? :
5 21 $val ? :
1500 248 0 if ($ref) { }
1501 4 156 if @row1 and not $c->{'hd_c'} and not ref $hdrs
1506 232 16 if $c->{'cls'}
1507 22 226 if ($ref and $c->{'cbai'} || $c->{'cboi'})
1509 21 1 ref $ref eq 'ARRAY' ? :
1511 34 37 if ref $r eq "HASH"
1512 30 41 if $c->{'cbai'}
1513 46 25 if $c->{'cboi'}
1517 6 242 if ($c->{'sink'})
1518 0 6 unless my $ro = ref $c->{'out'}
1520 1 5 if $ro eq "SCALAR" and ${$c->{'out'};} eq "skip"
1523 0 5 unless $ro eq ref $ref
1526 4 1 if ($ro eq "ARRAY")
1527 2 2 if (@{$c->{'out'};} and @$ref and ref $c->{'out'}[0] eq ref $ref->[0])
1534 1 0 if ($ro eq "HASH")
1546 1 241 unless defined wantarray