blib/lib/Catmandu/Fix/set_field.pm

filter: Statementstmt 100% 27 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 97.1% 34 / 35 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/Condition/SimpleAnyTest.pm ↑ Summary blib/lib/Catmandu/Fix/copy_field.pm »
1 package Catmandu::Fix::set_field;
2  
3 16 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 16 our $VERSION = '1.0201_02';
6  
7 16 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 16 with 'Catmandu::Fix::Base';
13  
14 16 has path => (fix_arg => 1);
15 16 has value => (fix_arg => 1);
16  
17 sub emit {
18 51 ▶ my ($self, $fixer) = @_;
Subroutine emit: called CC=1 SCAR=0.0
Pod undocumented
19 51 my $path = $fixer->split_path($self->path);
20 51 my $key = pop @$path;
21 51 my $value = $fixer->emit_value($self->value);
22  
23 $fixer->emit_walk_path(
24 $fixer->var,
25 $path,
26 sub {
27 51 ▶ my $var = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
28 51 $fixer->emit_set_key($var, $key, $value);
29 }
30 51 );
31 }
32  
33 16 1;
34  
35 __END__
36  
37 =pod
38  
39 =head1 NAME
40  
41 Catmandu::Fix::set_field - add or change the value of a HASH key or ARRAY index
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 'bar 123'
51 set_field(foo, 'bar 123')
52  
53 # Change a deeply nested key
54 set_field(my.deep.nested.key, hi)
55  
56 =head1 SEE ALSO
57  
58 L<Catmandu::Fix>
59  
60 =cut
« blib/lib/Catmandu/Fix/Condition/SimpleAnyTest.pm ↑ Summary blib/lib/Catmandu/Fix/copy_field.pm »