logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Catmandu::Fix::SimpleGetValue - helper class for creating emit Fix-es

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::Fix. 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

Name

       Catmandu::Fix::SimpleGetValue - helper class for creating emit Fix-es

See Also

       Catmandu::Fix

perl v5.40.0                                       2025-01-17                 Catmandu::Fix::SimpleGetValue(3pm)

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.*)

See Also