Catmandu::Bag(3pm)
β¨ Catmandu::Bag β¨
okay bestie, listen up π this is Catmandu::Bag β the manual page for the Perl module, straight outta the User Contributed Perl Documentation. It's a Catmandu::Store compartment that persists data β like, it's the lil drawer inside your store where your stuff actually lives and stays. no cap. π«Ά
πΈ SYNOPSIS πΈ
here's the whole vibe, code and all, do NOT skip it:
my $store = Catmandu::Store::DBI->new(data_source => 'DBI:mysql:database=test');
my $store = Catmandu::Store::DBI->new(
data_source => 'DBI:mysql:database=test',
bags => { journals => {
fix => [ ... ] ,
autocommit => 1 ,
plugins => [ ... ] ,
id_generator => Catmandu::IdGenerator::UUID->new ,
}
},
bag_class => Catmandu::Bag->with_plugins('Datestamps')
);
# Use the default bag...
my $bag = $store->bag;
# Or a named bag...
my $bag = $store->bag('journals');
# Every bag is an iterator...
$bag->each(sub { ... });
$bag->take(10)->each(sub { ... });
$bag->add($hash);
$bag->add_many($iterator);
$bag->add_many([ $hash, $hash , ...]);
# Commit changes...
$bag->commit;
if ($bag->exists($id)) {
# ...
}
my $obj = $bag->get($id);
$bag->delete($id);
$bag->delete_all;
π CONFIGURATION π
fixβ holds an array of fixes (or Fix files π ) that get applied before data gets imported into the bag. pre-game glow-up, basically.pluginsβ an array ofCatmandu::Pluggableto apply to the bag items. slay.autocommitβ when you set this to a true value, a commit gets executed automatically when the bag goes out of scope. it's giving β¨set it and forget itβ¨.id_generatorβ aCatmandu::IdGeneratoror the name of an IdGenerator class. by defaultCatmandu::IdGenerator::UUIDis used. the default is iconic, ngl.id_keyβ use a custom key to hold id's in this bag. seeCatmandu::Storefor the default or the store-wide value. it's also aliased as"id_field"π.
π METHODS π
add($hash)
add a hash to the bag, or update an existing hash by using its '_id' key. returns the stored hash on success, or undef on failure π. periodt.
add_many($array) / add_many($iterator)
add or update one or more items to the bag. one item? forty items? doesn't matter, she ate. π₯
get($id)
retrieves the item with identifier $id from the bag. go get your girl π«Ά
exists($id)
returns 1 if the item with identifier $id exists in the bag. simple as that, fr fr.
get_or_add($id, $hash)
retrieves the item with identifier $id from the store, or β if it's not found β adds $hash with _id $id instead. it's giving "if you can't find her, make her" π.
delete($id)
deletes the item with $id from the bag. bye bestie π
delete_all
clear the bag. everything gone. no take-backs. π
touch($key, $format)
add the current datetime to each record. like stamping the whole bag with "here, right now":
$bag->touch('date_updated', 'iso_date_time');
see Catmandu::Util::now for possible format values π.
commit
commit changes. lock it in πβ¨
log
return the current logger. keep the receipts π
π CLASS METHODS π
with_plugins($plugin) / with_plugins(\@plugins)
plugins are a kind of fixes that should be available for each bag. for example, the Datestamps plugin will automatically store into each bag item the fields 'date_updated' and 'date_created' πΈ. with_plugins accepts one plugin classname, or an array of them, and returns a subclass of the Bag with the plugin methods implemented. main character energy, honestly.
π SEE ALSO π
Catmandu::IterableCatmandu::SearchableCatmandu::FixCatmandu::Pluggable
okay that's the whole page bestie, go forth and persist your data πβ¨
this was perl v5.40.1, dated 2026-01-24 β mwah, love u, bye ππ¦π
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms