Process/Utils.pm

filter: Statementstmt 100% 32 / 32 Branchbran 50.0% 1 / 2 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 86.2% 44 / 51 CC 4 SCAR 5.6
CC
4
Cov
90%
process_csv
3.1
__ANON__
2.0
BEGIN
1.0
CRAP 1.7
« Process.pm ↑ Summary
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"} // {}
l!l
10
MC/DC0%0/1
$options{"csv_options"} // {}
$options{"csv_options"}
Truth table50%1/2
A
A= $options{"csv_options"}
Aresult
11
00
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
l!l&&r!l&&!r
001
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($args->{"has_headers"}) 1 0 1
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__
« Process.pm ↑ Summary