Catman...ns::Bag(3pm)
π Catman...ns::Bag(3pm) π
okay bestie, welcome to Catmandu::Store::File::FedoraCommons::Bag β it's a perl manual page, section 3pm, from the User Contributed Perl Documentation. yes we're doing Perl lore today. sit down, hydrate, we're going in π«Ά
β¨ NAME β¨
Catmandu::Store::File::FedoraCommons::Bag β it's literally the index of all the "files" in a Catmandu::Store::File::FedoraCommons "folder". think of it as the little card catalogue for your vibe-coded file collection. πβ¨
πΈ SYNOPSIS πΈ
here's the whole serve, exactly as written, no edits, no notes:
use Catmandu;
my $store = Catmandu->store('File::FedoraCommons'
, baseurl => 'http://localhost:8080/fedora'
, username => 'fedoraAdmin'
, password => 'fedoraAdmin'
, namespace => 'demo'
, purge => 1);
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");
# or (faster)
$files->upload(IO::File::WithFilename->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");
okay the way this whole thing is set up?? you build a $store with your baseurl, username, password, namespace and purge, you grab $store->index, and then you're off. add a folder, delete a folder, get a folder, list every container with $index->each and print $container->{_id}. then $index->files(1234) gets you the files inside a folder and $files->each walks them β pull _id, size, content_type, created, modified off each $file, and stream it wherever you want with an IO::File. upload with IO::File->new("<data.dat") or the faster IO::File::WithFilename->new("<data.dat"). get it back with $files->get("data.dat"), stream it out, delete it, delete the folder. whole cycle. iconic. π
ngl the original comments say "Get the files in an folder" and "Delete a folders" β that's them, not me, we're keeping the receipts fr fr π«Ά
π¦ INHERITED METHODS π¦
this Catmandu::Bag implements β as in, it gets all of this for free, no cap:
Catmandu::BagCatmandu::FileBagCatmandu::Droppable
so like, that's the whole family tree. you get bag behaviour, file-bag behaviour, and droppable behaviour, and the fact that the inherited list is literally these three is the entire tea. periodt. π
π that's the page bestie!! π this one's from perl v5.36.0, dated 2023-02-05, and it lives under Catman...ns::Bag(3pm). go forth and index your folders, you absolute legend ππ¦πΈπ
π¦ where this page comes from
- debian bookworm: libcatmandu-fedoracommons-perl 0.5-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libcatmandu-fedoracommons-perl 0.5-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatmandu-fedoracommons-perl 0.5-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatmandu-fedoracommons-perl 0.5-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-fedoracommons-perl 0.5-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