Catman...:Index(3pm)

πŸ“¦
version 1.16 Β· 4 versions
, in debian bookworm, ubuntu noble

πŸ’– 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::Bag
  • Catmandu::FileBag::Index
  • Catmandu::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