File Coverage

blib/lib/Catmandu/Fix/set_hash.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   88361  
  1         3  
  1         6  
4             our $VERSION = '1.2019';
5              
6             use Moo;
7 1     1   7 use Catmandu::Util::Path qw(as_path);
  1         1  
  1         4  
8 1     1   639 use namespace::clean;
  1         2  
  1         45  
9 1     1   6 use Catmandu::Fix::Has;
  1         2  
  1         3  
10 1     1   591  
  1         2  
  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   34 as_path($self->path)->setter(sub {+{@$values}});
19 5         12 }
20 5     3   46  
  3         48  
21             1;
22              
23              
24             =pod
25              
26             =head1 NAME
27              
28             Catmandu::Fix::set_hash - add or change the value of a HASH key or ARRAY index to a hash
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 hash
38             set_hash(foo)
39             # Or a hash with initial contents
40             set_hash(a: b, c: d)
41              
42             =head1 SEE ALSO
43              
44             L<Catmandu::Fix>
45              
46             =cut