Catman...Addable(3pm)

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

πŸ’– Catmandu::Addable β€” the base class glow-up ✨

okay bestie, so this is Catmandu::Addable, and it's giving base class energy πŸ’… β€” like, it's the blueprint for every Catmandu module that needs to implement add. That's the whole point of it. It's Catman...Addable(3pm) in the manual, but we're on a first-name basis here. πŸŽ€


🌸 SYNOPSIS 🌸

here's the whole vibe, in code, no notes:

package My::Adder;

use Moo;
use Data::Dumper;

with 'Catmandu::Addable';

sub add {
    my ($self,$object) = @_;

    print "So you want to add:\n";
    print Dumper($object);

    1;
}

sub commit {
    my $self = shift;

    print "And now you are done?\n";
}

package main;

my $adder = My::Adder->new(fix => ['upcase(foo)']);

# prints foo => BAR
$adder->add({ foo => 'bar' });

# prints:
#  foo => BAR
#  foo => BAR
$adder->add_many([ { foo => 'bar' } , { foo => 'bar' }]);

# prints a commit statement
$adder->commit;

like, look at it. iconic. πŸ‘‘


✨ OPTIONS ✨

  • autocommit β€” autocommit moment when the exporter gets out of scope 🫢. Default is 0.

πŸ¦‹ METHODS πŸ¦‹

add($hash)

hands you a Perl hash and expects you to return true or false, fr fr. that's the deal. πŸ’œ

commit

this one is usually called at the end of a whole bunch of add or add_many operations. it's the lil "we're done here" at the end of the party. πŸŽ‰


πŸ’« INHERIT πŸ’«

the way that this just works: if you provide an add method, then automatically your package gets an add_many method, plus a fix attribute which transforms all the Perl hashes that get provided to the add method. free stuff. we love free stuff. πŸ’…


πŸ‘€ SEE ALSO πŸ‘€

  • Catmandu::Fixable
  • Catmandu::Exporter
  • Catmandu::Store

go read them, iykyk πŸ“šβœ¨


okay that's the whole page, bestie, and now the cute sign-off πŸ’–: this one's from perl v5.40.1, dated 2026-01-24, and it lives in the manual as Catman...Addable(3pm). periodt. πŸŒˆπŸŽ€

πŸ“¦ where this page comes from