| 1 | package File::Process::Utils; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use File::Process qw(pre process_file :booleans); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Text::CSV_XS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use parent qw(Exporter); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | our @EXPORT_OK = qw(process_csv); | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | ######################################################################## | ||||||||||||||||||||
| 14 | sub process_csv { | ||||||||||||||||||||
| 15 | ######################################################################## | ||||||||||||||||||||
| 16 | 1 | ▶ | my ( $file, %options ) = @_; | ||||||||||||||||||
|
Subroutine
process_csv: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | my $csv_options = $options{csv_options} // {}; | ||||||||||||||||||
|
Condition50%1/2
$options{"csv_options"} // {}
MC/DC0%0/1
$options{"csv_options"} // {}
$options{"csv_options"}
Truth table50%1/2
A
A= $options{"csv_options"}
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 1 | my $csv = Text::CSV_XS->new($csv_options); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 1 | ▶ | $options{chomp} //= $TRUE; | ||||||||||||||||||
|
Condition33%1/3
$options{"chomp"} //= $File::Process::Utils::TRUE
MC/DC0%0/2
$options{"chomp"} //= $File::Process::Utils::TRUE
$options{"chomp"}
$File::Process::Utils::TRUE
Truth table33%1/3
A //= B
A= $options{"chomp"}B= $File::Process::Utils::TRUE
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | my ($csv_lines) = process_file( | ||||||||||||||||||||
| 25 | $file, | ||||||||||||||||||||
| 26 | csv => $csv, | ||||||||||||||||||||
| 27 | chomp => $options{chomp}, | ||||||||||||||||||||
| 28 | has_headers => $options{has_headers}, | ||||||||||||||||||||
| 29 | pre => sub { | ||||||||||||||||||||
| 30 | 1 | ▶ | my ( $file, $args ) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | my ( $fh, $all_lines ) = pre( $file, $args ); | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | ▶ | if ( $args->{'has_headers'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 1 | my @column_names = $args->{csv}->getline($fh); | |||||||||||||||||||
| 36 | 1 | $args->{csv}->column_names(@column_names); | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 1 | return ( $fh, $all_lines ); | |||||||||||||||||||
| 40 | }, | ||||||||||||||||||||
| 41 | next_line => sub { | ||||||||||||||||||||
| 42 | 10 | ▶ | my ( $fh, $all_lines, $args ) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | 10 | my $ref = $args->{csv}->getline_hr($fh); | |||||||||||||||||||
| 44 | 10 | return $ref; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 1 | ); | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | return $csv_lines; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 1 | 1; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||