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

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

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