blib/lib/Tie/File/AnyData/MultiRecord_CSV.pm

filter: Statementstmt 100% 43 / 43 Branchbran 80.0% 8 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 91.3% 63 / 69 CC 9 SCAR 13.0
CC
9
Cov
93%
TIEARRAY
5.0
__ANON__
5.0
BEGIN
1.0
CRAP 3.7
↑ Summary
1 package Tie::File::AnyData::MultiRecord_CSV;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶BEGIN{
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 require Parse::CSV;
9 3 require Tie::File::AnyData;
10 }
11  
12 3 our $VERSION = '0.01';
13  
14 sub TIEARRAY
15 3 ▶ {
Subroutine TIEARRAY: called CC=5 SCAR=16.1
16 3 my ($pack,$file,%opts) = @_;
17 3 ▶ my $field_sep = $opts{'field_sep'} || "\t";
Condition50%1/2
$opts{'field_sep'} || "\t"
l!l
30
MC/DC0%0/1
$opts{'field_sep'} || "\t"
$opts{'field_sep'}
Truth table50%1/2
A
A= $opts{'field_sep'}
Aresult
11
00
18 3 ▶ my $key = $opts{'key'} || 0;
Condition100%2/2
$opts{'key'} || 0
l!l
12
MC/DC100%1/1
$opts{'key'} || 0
$opts{'key'}
Truth table100%2/2
A
A= $opts{'key'}
Aresult
11
00
19 3 ▶ my $recsep = $opts{'recsep'} || "\n";
Condition50%1/2
$opts{'recsep'} || "\n"
l!l
03
MC/DC0%0/1
$opts{'recsep'} || "\n"
$opts{'recsep'}
Truth table50%1/2
A
A= $opts{'recsep'}
Aresult
11
00
20 3 delete $opts{'field_sep'};
21 3 delete $opts{'key'};
22  
23 641 ▶ my $coderef = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
24 3 ▶ use Parse::CSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 641 my ($fh) = @_;
26 641 ▶ return undef if (eof $fh);
Branch: 1 branch
BranchTrueFalseTotal
if eof $fh 207 434 641
27 434 my $csv_parser = Parse::CSV->new (
28 handle => $fh,
29 sep_char => $field_sep
30 );
31 434 my $arref = $csv_parser->fetch;
32 434 my $rec = join ("$field_sep",@$arref).$recsep;
33 434 my $rec_key = ${$arref}[$key];
34 434 my $pos = tell($fh);
35 434 ▶ while (my $arref = $csv_parser->fetch){
Branch: 1 branch
BranchTrueFalseTotal
if (my $arref = $csv_parser->fetch) 2877 0 2877
36 2877 ▶ if (${$arref}[$key] eq $rec_key){
Branch: 1 branch
BranchTrueFalseTotal
if (do { $arref }->[$key] eq $rec_key) { } 2447 430 2877
37 2447 $rec .= join "$field_sep",(@$arref);
38 2447 $rec .= $recsep;
39 2447 $pos = tell($fh);
40 2447 ▶ return $rec if eof($fh);
Branch: 1 branch
BranchTrueFalseTotal
if eof $fh 4 2443 2447
41 } else {
42 430 seek $fh,$pos,0;
43 430 return $rec;
44 }
45 }
46 3 };
47  
48 3 ▶ carp "Overriding code ref" if (defined $opts{'code'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"code"} 0 3 3
49 3 local $/="\n";
50 3 Tie::File::AnyData::TIEARRAY (
51 'Tie::File::AnyData',
52 $file,
53 %opts,
54 code => $coderef
55 );
56 }
57  
58 3 1;
59  
60 __END__
↑ Summary