line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Process::Utils; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
757
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
447
|
use File::Process qw(pre process_file :booleans); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
166
|
|
7
|
1
|
|
|
1
|
|
967
|
use Text::CSV_XS; |
|
1
|
|
|
|
|
13084
|
|
|
1
|
|
|
|
|
54
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
8
|
use parent qw(Exporter); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(process_csv); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
######################################################################## |
16
|
|
|
|
|
|
|
sub process_csv { |
17
|
|
|
|
|
|
|
######################################################################## |
18
|
1
|
|
|
1
|
1
|
1009
|
my ( $file, %options ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
50
|
|
|
6
|
my $csv_options = $options{csv_options} // {}; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
4
|
my $csv = Text::CSV_XS->new($csv_options); |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
33
|
|
|
134
|
$options{chomp} //= $TRUE; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my ($csv_lines) = process_file( |
27
|
|
|
|
|
|
|
$file, |
28
|
|
|
|
|
|
|
csv => $csv, |
29
|
|
|
|
|
|
|
chomp => $options{chomp}, |
30
|
|
|
|
|
|
|
has_headers => $options{has_headers}, |
31
|
|
|
|
|
|
|
pre => sub { |
32
|
1
|
|
|
1
|
|
2
|
my ( $file, $args ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
3
|
my ( $fh, $all_lines ) = pre( $file, $args ); |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
|
|
|
3
|
if ( $args->{'has_headers'} ) { |
37
|
1
|
|
|
|
|
52
|
my @column_names = $args->{csv}->getline($fh); |
38
|
1
|
|
|
|
|
58
|
$args->{csv}->column_names(@column_names); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
33
|
return ( $fh, $all_lines ); |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
next_line => sub { |
44
|
10
|
|
|
10
|
|
20
|
my ( $fh, $all_lines, $args ) = @_; |
45
|
10
|
|
|
|
|
24
|
my $ref = $args->{csv}->getline_hr($fh); |
46
|
10
|
|
|
|
|
586
|
return $ref; |
47
|
|
|
|
|
|
|
} |
48
|
1
|
|
|
|
|
9
|
); |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
22
|
return $csv_lines; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |