Catman...e::Bag(3pm)
β¨ NAME β¨
Catmandu::Store::File::Simple::Bag β bestie, it's the index of, like, ALL the "files" chillin' inside a Catmandu::Store::File::Simple "folder" π
π SYNOPSIS π
okay so here's the vibe, no cap:
use Catmandu;
my $store = Catmandu->store('File::Simple' , root => 't/data');
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");
literally the whole workflow in one screen, we love to see it π
π¦ DESCRIPTION π¦
A Catmandu::Store::File::Simple::Bag holds every single "file" that's available in a Catmandu::Store::File::Simple FileStore "folder". It's giving β¨organizedβ¨.
All the methods of Catmandu::Bag, Catmandu::FileBag::Index and Catmandu::Droppable are implemented. π
And plot twist β every Catmandu::Bag is also an Catmandu::Iterable, so you can loop through it like it's nothing. main character energy fr fr πΈ
π FOLDERS π
All files in a Catmandu::Store::File::Simple are organized into "folders" β yes bestie, everything has a home π .
To add a "folder", you gotta add a new record to the Catmandu::Store::File::Simple::Index:
$index->add({_id => '1234'});
The _id field is the ONLY metadata available in Simple stores. That's it. That's the whole menu. π
Wanna add more metadata fields to a Simple store? You're gonna need a Catmandu::Plugin::SideCar. No SideCar, no extra fields. periodt. π
πΈ FILES πΈ
Files can be 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);
upload β get β download, a little three-step dance, obsessed honestly π
π INHERITED METHODS π
This Catmandu::Bag implements:
Catmandu::BagCatmandu::FileBagCatmandu::Droppable
three whole inheritance situations, and it ate every single one π₯
okay and for the little footer moment: this page is from perl v5.36.0, dated 2022-12-10 β documented in the User Contributed Perl Documentation, and it was written by the lovely humans at Catman...e::Bag(3pm). ty for coming to my TED talk, mwah πβ¨ππ¦
π¦ 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