Catman...erlcode(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Catmandu::Fix::perlcode β€” execute Perl code as a fix function ✨


🌸 DESCRIPTION 🌸

okay bestie, listen. this fix is for when you're living in the Catmandu fix language but you're also feeling a little main character and you wanna run your own Perl script in there. so you just do this:

perlcode(myscript.pl)

and that's it, that's the whole vibe. πŸ’…

now β€” the script (in our lil example it's called myscript.pl) has to return a code reference. no exceptions, bestie, it's giving contract. 🫢

sub {
    my $data = shift;

    $data->{testing} = 1 ; # modify the item

    return $data;          # and return the data
}

see how it takes $data, messes with it, and hands it back? that's the whole personality. modify the item, then return the data. 🌈

and if you're not using the fix language (iconic of you honestly), this:

my $fixer = Catmandu::Fix->new( fixes => [ do 'myscript.pl' ] );
$fixer->fix( $item );

is roughly equivalent to:

my $code = do 'myscript.pl';
$item = $code->( $item )

roughly!! not exactly, don't come for me, that's literally what the manpage says. πŸ™ˆ


πŸŽ€ the caching thing (iykyk)

all scripts are cached based on their filename, so if you use this fix a bunch of times, each given script only gets loaded once. we love an efficient queen. βœ¨πŸ’–


πŸ¦‹ the second value (this one's important fr fr)

the code reference gets passed a second value so you can reject selected items β€” the same kind of energy as with see Catmandu::Fix::reject:

sub {
    my ($data, $reject) = @_;

    if ($data->{my_field} eq 'OK') {
        return $data;    # return the data and continue processing
    }
    else {
        return $reject;  # return the reject flag to ignore this record
    }
}

so like β€” return $data and the record keeps going, return $reject and that record gets ignored, bye bye, not our problem anymore. πŸ‘‘ that's the whole bit. periodt. πŸ’…


✨ SEE ALSO ✨

  • Catmandu::Fix::code
  • Catmandu::Fix::cmd

and that's the tea bestie πŸ“ this was written for perl v5.40.1, dated 2026-01-24, straight out of the User Contributed Perl Documentation collection, filed under Catman...erlcode(3pm) β€” slay, go write a fix, ily πŸ’–πŸ§šβœ¨

πŸ“¦ where this page comes from