blib/lib/Catmandu/Fix/set_array.pm

filter: Statementstmt 100% 26 / 26 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 97.0% 33 / 34 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Catmandu/Fix/uri_decode.pm ↑ Summary blib/lib/Catmandu/Fix/set_hash.pm »
1 package Catmandu::Fix::set_array;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.0201_02';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 with 'Catmandu::Fix::Base';
12  
13 1 has path => (fix_arg => 1);
14 4 ▶has values => (fix_arg => 'collect', default => sub {[]});
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 sub emit {
17 5 ▶ my ($self, $fixer) = @_;
Subroutine emit: called CC=1 SCAR=0.0
Pod undocumented
18 5 my $path = $fixer->split_path($self->path);
19 5 my $key = pop @$path;
20 5 my $values = $self->values;
21  
22 $fixer->emit_walk_path(
23 $fixer->var,
24 $path,
25 sub {
26 5 ▶ my $var = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
27 $fixer->emit_set_key($var, $key,
28 5 "[" . join(',', map {$fixer->emit_value($_)} @$values) . "]");
29 }
30 5 );
31 }
32  
33 1 1;
34  
35 __END__
36  
37 =pod
38  
39 =head1 NAME
40  
41 Catmandu::Fix::set_array - add or change the value of a HASH key or ARRAY index to an array
42  
43 =head1 DESCRIPTION
44  
45 Contrary to C<add_field>, this will not create the intermediate structures
46 if they are missing.
47  
48 =head1 SYNOPSIS
49  
50 # Change the value of 'foo' to an empty array
51 set_array(foo)
52 # Or an array with initial contents
53 set_array(foo, "a", "b", "c")
54  
55 =head1 SEE ALSO
56  
57 L<Catmandu::Fix>
58  
59 =cut
« blib/lib/Catmandu/Fix/uri_decode.pm ↑ Summary blib/lib/Catmandu/Fix/set_hash.pm »