Catman...:Index(3pm)
π NAME π
Catman...:Index β bestie, this is the manual page for the Index of all "Folders" in a Catmandu::Store::File::Memory. It's the 3pm one, so you know it's Perl module territory. π«Ά
β¨ SYNOPSIS β¨
Okay so here's the whole vibe, verbatim, no notes:
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");
Like, look at her go. She does everything. π
πΈ DESCRIPTION πΈ
So a Catmandu::Store::File::Memory::Index holds all the "folders" that exist in a Catmandu::Store::File::Memory FileStore. That's it, that's the whole job, and she does it flawlessly.
Every single method from Catmandu::Bag, Catmandu::FileBag::Index and Catmandu::Droppable is implemented here. No gaps, no "coming soon", no cap. π
And heads up bestie: every Catmandu::Bag is also a Catmandu::Iterable. So yeah, you can iterate her. The way that just works? Obsessed. β¨
π FOLDERS π
Every file in a Catmandu::Store::File::Memory lives inside a "folder". They're organized, they're tidy, they're giving organization skills.
Wanna add a "folder"? You gotta add a brand new record to the Catmandu::Store::File::Memory::Index:
$index->add({_id => '1234'});
Now listen, this part matters: the "_id" field is the only metadata available in Memory stores. That's it. One field. Iconic minimalist behaviour, honestly.
If you want more metadata fields on a Memory store, you need a Catmandu::Plugin::SideCar. That's the plug. π
π¦ FILES π¦
Files get accessed through the "folder" identifier:
my $files = $index->files('1234');
Use the "upload" method to add new files to a "folder", and use the "download" method to pull files back out of 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, download, slay. π
π INHERITED METHODS π
This Catmandu::Bag implements all of these, so go read them too (iykyk):
Catmandu::BagCatmandu::FileBag::IndexCatmandu::Droppable
Just a lil reminder that this page is from the User Contributed Perl Documentation, bestie β so give her the respect she deserves. π
Okay that's the whole page!! Thanks for reading, you ate. This was perl v5.36.0, dated 2022-12-10, and I'm literally so proud of you for making it to the end. 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