| 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"
MC/DC0%0/1
$opts{'field_sep'} || "\t"
$opts{'field_sep'}
Truth table50%1/2
A
A= $opts{'field_sep'}
| |||||||||||||
| 18 | 3 | ▶ | my $key = $opts{'key'} || 0; | ||||||||||
|
Condition100%2/2
$opts{'key'} || 0
MC/DC100%1/1
$opts{'key'} || 0
$opts{'key'}
Truth table100%2/2
A
A= $opts{'key'}
| |||||||||||||
| 19 | 3 | ▶ | my $recsep = $opts{'recsep'} || "\n"; | ||||||||||
|
Condition50%1/2
$opts{'recsep'} || "\n"
MC/DC0%0/1
$opts{'recsep'} || "\n"
$opts{'recsep'}
Truth table50%1/2
A
A= $opts{'recsep'}
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 36 | 2877 | ▶ | if (${$arref}[$key] eq $rec_key){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||