line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::sum; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
104307
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Catmandu::Util qw(is_number); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
8
|
1
|
|
|
1
|
|
436
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
9
|
1
|
|
|
1
|
|
7
|
use List::Util qw(all sum); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
10
|
1
|
|
|
1
|
|
6
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
368
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
12
|
1
|
|
|
1
|
|
756
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
16
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_fixer { |
19
|
5
|
|
|
5
|
|
42
|
my ($self) = @_; |
20
|
|
|
|
|
|
|
as_path($self->path)->updater( |
21
|
|
|
|
|
|
|
if_array_ref => sub { |
22
|
5
|
|
|
5
|
|
11
|
my $val = $_[0]; |
23
|
5
|
100
|
|
|
|
25
|
return undef, 1 unless all {is_number($_)} @$val; |
|
17
|
|
|
|
|
64
|
|
24
|
4
|
|
50
|
|
|
109
|
sum(@$val) // 0; |
25
|
|
|
|
|
|
|
} |
26
|
5
|
|
|
|
|
21
|
); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__END__ |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=pod |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Catmandu::Fix::sum - replace the value of an array field with the sum of its elements |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 SYNOPSIS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# e.g. numbers => [2, 3] |
42
|
|
|
|
|
|
|
sum(numbers) |
43
|
|
|
|
|
|
|
# numbers => 5 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SEE ALSO |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
L<Catmandu::Fix> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |