Scroll to navigation

Catmandu::Store::File::Simple::Index(3pm) User Contributed Perl Documentation Catmandu::Store::File::Simple::Index(3pm)


Catmandu::Store::File::Simple::Index - Index of all "Folders" in a Catmandu::Store::File::Simple


    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
    # 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
    # Retrieve a file
    my $file = $files->get("data.dat");
    # Stream a file to an IO::Handle
    # Delete a file
    # Delete a folders


A Catmandu::Store::File::Simple::Index contains all "folders" available in a Catmandu::Store::File::Simple FileStore. All methods of Catmandu::Bag, Catmandu::FileBag::Index and Catmandu::Droppable are implemented.

Every Catmandu::Bag is also an Catmandu::Iterable.


All files in a Catmandu::Store::File::Simple are organized in "folders". To add a "folder" a new record needs to be added to the Catmandu::Store::File::Simple::Index :

    $index->add({_id => '1234'});

The "_id" field is the only metadata available in Simple stores. To add more metadata fields to a Simple store a Catmandu::Plugin::SideCar is required.


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".

    my $file = $files->get('data.txt');


This Catmandu::Bag implements:

2020-05-22 perl v5.30.2