File Coverage

blib/lib/Catmandu/Fix/set_array.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 26 100.0


line stmt bran cond sub pod time code
1              
2             use Catmandu::Sane;
3 1     1   88601  
  1         3  
  1         6  
4             our $VERSION = '1.2018';
5              
6             use Moo;
7 1     1   6 use Catmandu::Util::Path qw(as_path);
  1         3  
  1         4  
8 1     1   796 use namespace::clean;
  1         3  
  1         45  
9 1     1   5 use Catmandu::Fix::Has;
  1         2  
  1         3  
10 1     1   587  
  1         3  
  1         5  
11             with 'Catmandu::Fix::Builder';
12              
13             has path => (fix_arg => 1);
14             has values => (fix_arg => 'collect', default => sub {[]});
15              
16             my ($self) = @_;
17             my $values = $self->values;
18 5     5   38 as_path($self->path)->setter(sub {[@$values]});
19 5         12 }
20 5     3   41  
  3         45  
21             1;
22              
23              
24             =pod
25              
26             =head1 NAME
27              
28             Catmandu::Fix::set_array - add or change the value of a HASH key or ARRAY index to an array
29              
30             =head1 DESCRIPTION
31              
32             Contrary to C<add_field>, this will not create the intermediate structures
33             if they are missing.
34              
35             =head1 SYNOPSIS
36              
37             # Change the value of 'foo' to an empty array
38             set_array(foo)
39             # Or an array with initial contents
40             set_array(foo, "a", "b", "c")
41              
42             =head1 SEE ALSO
43              
44             L<Catmandu::Fix>
45              
46             =cut