/usr/share/perl5/Catmandu/Fix/SimpleGetValue.pm is in libcatmandu-perl 0.9505-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | package Catmandu::Fix::SimpleGetValue;
use Catmandu::Sane;
our $VERSION = '0.9505';
use Moo::Role;
use namespace::clean;
with 'Catmandu::Fix::Base';
requires 'path';
requires 'emit_value';
sub emit {
my ($self, $fixer) = @_;
my $path = $fixer->split_path($self->path);
my $key = pop @$path;
$fixer->emit_walk_path($fixer->var, $path, sub {
my $var = shift;
$fixer->emit_get_key($var, $key, sub {
my $var = shift;
$self->emit_value($var, $fixer);
});
});
}
1;
__END__
=pod
=head1 NAME
Catmandu::Fix::SimpleGetValue - helper class for creating emit Fix-es
=head1 SYNOPSIS
# Create a Rot13 encrypter
package Catmandu::Fix::rot13;
use Catmandu::Sane;
use Moo;
use Catmandu::Fix::Has;
has path => (fix_arg => 1);
with 'Catmandu::Fix::SimpleGetValue';
sub emit_value {
my ($self, $var, $fixer) = @_;
"${var} =~ y/A-Za-z/N-ZA-Mn-za-m/ if is_string(${var});";
}
# Now you can use this Fix in your scripts
rot13(my.deep.nested.path)
rot13(authors.*)
=head1 DESCRIPTION
Catmandu::Fix::SimpleGetValue eases the creation of emit Fixes that transform
values on a JSON path. A Fix package implementing Catmandu::Fix::SimpleGetValue
needs to implement a method C<emit_value> which accepts the variable name on
which the Fix operates and an instance of Catmandu::Fixer. The method should
return a string containing the Perl code to transform values on a JSON path.
It is not possible to inspect in an emit Fix the actual value on which this Fix
runs: $var contains a variable name not the actual value. The real values are
only available at run time. Emit Fixes are used to compile Perl code into Fix
modules which do the actual transformation.
For more examples look at the source code of:
=over 4
=item Catmandu::Fix::append;
=item Catmandu::Fix::replace_all
=item Catmandu::Fix::upcase
=back
=head1 SEE ALSO
L<Catmandu::Fix>
=cut
|