CSVUtils/csv_each_row.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 4 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 94.7% 36 / 38 CC 4 SCAR 4.8
CC
4
Cov
97%
__ANON__
2.1
__ANON__
2.0
__ANON__
2.0
CRAP 1.6
« CSVUtils/csv_replace_newline.pm ↑ Summary CSVUtils/csv_sum.pm »
1 package App::CSVUtils::csv_each_row;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 2 our $DATE = '2026-07-09'; # DATE
9 2 our $DIST = 'App-CSVUtils'; # DIST
10 2 our $VERSION = '1.038'; # VERSION
11  
12 2 ▶use App::CSVUtils qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 gen_csv_util
14 compile_eval_code
15 eval_code
16 2 );
17  
18 gen_csv_util(
19 name => 'csv_each_row',
20 summary => 'Run Perl code for every data row',
21 description => <<'MARKDOWN',
22  
23 This is like <prog:csv-map>, except result of code is not printed.
24  
25 MARKDOWN
26 add_args => {
27 %App::CSVUtils::argspecopt_hash,
28 %App::CSVUtils::argspec_eval,
29 },
30 tags => ['category:iterating', 'accepts-code'],
31 examples => [
32 {
33 summary => 'Delete user data',
34 argv => ['-He', '"unlink qq(/home/data/$_->{username}.dat)"', 'users.csv'],
35 test => 0,
36 'x.doc.show_result' => 0,
37 },
38 ],
39  
40 writes_csv => 0,
41  
42 2 ▶ on_begin => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
43 2 my $r = shift;
44  
45 # for when we are called directly as a function without wrapper to set
46 # defaults etc.
47 2 ▶ $r->{util_args}{add_newline} //= 1;
Condition50%1/2
$r->{"util_args"}{"add_newline"} //= 1
l!l
02
MC/DC0%0/1
$r->{"util_args"}{"add_newline"} //= 1
$r->{"util_args"}{"add_newline"}
Truth table50%1/2
A
A= $r->{"util_args"}{"add_newline"}
Aresult
11
00
48 },
49  
50 2 ▶ on_input_header_row => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
51 2 my $r = shift;
52  
53 # we add the following keys to the stash
54 2 $r->{code} = compile_eval_code($r->{util_args}{eval}, 'eval');
55  
56 2 ▶ $r->{wants_input_row_as_hashref} = 1 if $r->{util_args}{hash};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"util_args"}{"hash"} 1 1 2
57 },
58  
59 6 ▶ on_input_data_row => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
60 6 my $r = shift;
61  
62 6 ▶ eval_code($r->{code}, $r, $r->{wants_input_row_as_hashref} ? $r->{input_row_as_hashref} : $r->{input_row});
Branch: 1 branch
BranchTrueFalseTotal
$r->{'wants_input_row_as_hashref'} ? : 3 3 6
63 },
64 2 );
65  
66 2 1;
67 # ABSTRACT: Run Perl code for every data row
68  
69 __END__
« CSVUtils/csv_replace_newline.pm ↑ Summary CSVUtils/csv_sum.pm »