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.*)
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 "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:
- Catmandu::Fix::append;
- Catmandu::Fix::replace_all
- Catmandu::Fix::upcase