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::Bind::visitor - a binder that computes Fix-es for every element in record

Configuration

path
       A path in the data to visit:

         # Visit any field
         do visitor()
           ...
         end

         # Visit only the fields at my.deep.field
         do visitor(path: my.deep.field)
           ...
         end

Description

       The visitor binder will iterate over all the elements in a record and perform fixes on them.

       Special node names are available to process every visited element:

       scalar
           Process a Fix on every scalar value. E.g.

              upcase(scalar)
              replace_all(scalar,'$','tested')

       array
           Process a Fix on every array value. E.g.

              sort_field(array)

           Values  need  to  be  put  in  the 'array' field to be available for fixes. The scope of the array is
           limited to the array visited.

       hash
           Process a Fix on every hash value. E.g.

              copy_field(hash.age,hash.age2)

           Values need to be put in the 'hash' field to be available for fixes. The scope of the hash is limited
           to the hash visited.

       key Provides access to the key on which the scalar,array or hash value is found. Eg.

              # Upcase all 'name' fields in the record
              if all_match(key,name)
                 upcase(scalar)
              end

Name

       Catmandu::Fix::Bind::visitor - a binder that computes Fix-es for every element in record

See Also

       Catmandu::Fix::Bind

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

Synopsis

        # If data is like:

          numbers:
             - one
             - two
             - three
          person:
             name: jennie
             age: 44
             color:
                - green
                - purple
                - brown
                - more:
                   foo: bar

        do visitor()
           upcase(scalar)  # upcase every scalar value in the record
        end

        # will produce

          numbers:
             - ONE
             - TWO
             - THREE
          person:
             name: JENNIE
             age: 44
             color:
                - GREEN
                - PURPLE
                - BROWN
                - more:
                   foo: BAR

         do visitor()
           # upcase all the 'name' fields in the record
           if all_match(key,name)
             upcase(scalar)
           end
         end

         do visitor()
           # upcase all the field names in the record
           upcase(key)
         end

See Also