Catman...y::Bag(3pm)

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

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::Bag
  • Catmandu::FileBag
  • Catmandu::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