blib/lib/Catmandu/Fix/to_json.pm

filter: Statementstmt 100% 22 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 96.5% 28 / 29 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/retain_field.pm ↑ Summary blib/lib/Catmandu/Importer/YAML.pm »
1 package Catmandu::Fix::to_json;
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 Cpanel::JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 has path => (fix_arg => 1);
13  
14 1 with 'Catmandu::Fix::SimpleGetValue';
15  
16 sub emit_value {
17 2 ▶ my ($self, $var, $fixer) = @_;
Subroutine emit_value: called CC=1 SCAR=0.0
Pod undocumented
18  
19 # memoize in case called multiple times
20 2 my $json_var = $fixer->capture(
21 Cpanel::JSON::XS->new->utf8(0)->pretty(0)->allow_nonref(1));
22  
23 2 "if (is_maybe_value(${var}) || is_array_ref(${var}) || is_hash_ref(${var})) {"
24 . "${var} = ${json_var}->encode(${var});" . "}";
25 }
26  
27 1 1;
28  
29 __END__
30  
31 =pod
32  
33 =head1 NAME
34  
35 Catmandu::Fix::to_json - convert the value of a field to json
36  
37 =head1 SYNOPSIS
38  
39 to_json(my.field)
40  
41 =head1 SEE ALSO
42  
43 L<Catmandu::Fix>
44  
45 =cut
46  
« blib/lib/Catmandu/Fix/retain_field.pm ↑ Summary blib/lib/Catmandu/Importer/YAML.pm »