blib/lib/Catmandu/Fix/add_field.pm

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