Catman...y::Bag(3pm)
hi bestie π you just opened the Catman...y::Bag(3pm) manual page and honestly? it's a whole serve. this one's the little bag that keeps track of every "file" chillin' inside a Catmandu::Store::File::Memory "folder". let's get into it, no cap. π
πΈ NAME πΈ
Catmandu::Store::File::Memory::Bag β the index of all the "files" that live in a Catmandu::Store::File::Memory "folder". like, every single one. π
β¨ SYNOPSIS β¨
okay so here's the whole tour, bestie β look at all these moves:
use Catmandu;
my $store = Catmandu->store('File::Memory');
my $index = $store->index;
# List all containers
$index->each(sub {
my $container = shift;
print "%s\n" , $container->{_id};
});
# Add a new folder
$index->add({_id => '1234'});
# Delete a folder
$index->delete(1234);
# Get a folder
my $folder = $index->get(1234);
# Get the files in an folder
my $files = $index->files(1234);
$files->each(sub {
my $file = shift;
my $name = $file->{_id};
my $size = $file->{size};
my $content_type = $file->{content_type};
my $created = $file->{created};
my $modified = $file->{modified};
$file->stream(IO::File->new(">/tmp/$name"), file);
});
# Add a file
$files->upload(IO::File->new("<data.dat"),"data.dat");
# Retrieve a file
my $file = $files->get("data.dat");
# Stream a file to an IO::Handle
$files->stream(IO::File->new(">data.dat"),$file);
# Delete a file
$files->delete("data.dat");
# Delete a folders
$index->delete("1234");
π« DESCRIPTION π«
so, a Catmandu::Store::File::Memory::Bag contains all the "files" available in a Catmandu::Store::File::Memory FileStore "folder". that's the whole job, and it does it flawlessly, obviously. π
every method of Catmandu::Bag, Catmandu::FileBag::Index and Catmandu::Droppable is implemented β all of them, she's not holding back.
and plot twist: every Catmandu::Bag is also an Catmandu::Iterable. it's giving multitalented. π
ποΈ FOLDERS ποΈ
all files in a Catmandu::Store::File::Memory are organized in "folders". to add a "folder" you gotta add a new record to the Catmandu::Store::File::Memory::Index, like so:
$index->add({_id => '1234'});
heads up bestie β the _id field is the only metadata available in Memory stores. that's it, that's the whole metadata menu. π if you want more metadata fields in a Memory store, you need a Catmandu::Plugin::SideCar. iykyk.
π FILES π
files are accessed via the "folder" identifier:
my $files = $index->files('1234');
use the upload method to add new files to a "folder". use the download method to retrieve files from a "folder". π«Ά
$files->upload(IO::File->new("</tmp/data.txt"),'data.txt');
my $file = $files->get('data.txt');
$files->download(IO::File->new(">/tmp/data.txt"),$file);
π INHERITED METHODS π
this Catmandu::Bag implements, and she ate:
Catmandu::BagCatmandu::FileBagCatmandu::Droppable
that's the page, bestie! go index some files, you main character. β¨
and that's a wrap on the Catman...y::Bag(3pm) page β perl v5.36.0, dated 2022-12-10, from the User Contributed Perl Documentation. mwah, take care of her π«Ά
π¦ where this page comes from
- debian bookworm: libcatmandu-filestore-perl 1.16-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatmandu-filestore-perl 1.16-2 Β· 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