Scroll to navigation

Catmandu::DirectoryIndex::Map(3pm) User Contributed Perl Documentation Catmandu::DirectoryIndex::Map(3pm)


Catmandu::DirectoryIndex::Map - translates between id and path using a Catmandu::Bag as lookup


    use Catmandu::DirectoryIndex::Map;
    use Catmandu::Store::DBI;
    # Bag to store/retrieve all path -> directory mapping
    my $bag = Catmandu::Store::DBI->new(
        data_source => "dbi:sqlite:dbname=/data/index.db"
    my $p = Catmandu::DirectoryIndex::Map->new(
        base_dir => "/data",
        bag => $bag
    # Tries to find a mapping for id "a".
    # return: mapping or undef
    my $mapping = $p->get("a");
    # Returns a mapping like { _id => "a", _path => "/data/2018/01/01/16/00/00/0cc175b9c0f1b6a831c399e269772661" }
    my $mapping = $p->add("a");
    # Catmandu::DirectoryIndex::Map is a Catmandu::Iterable
    # Returns list of records: [{ _id => "a", _path => "/data/2018/01/01/16/00/00/0cc175b9c0f1b6a831c399e269772661" }]
    my $mappings = $p->to_array();


    This package uses a Catmandu::Bag backend to translate between ids and paths.
    Each record looks like this:
        { _id => "a", _path => "/data/2018/01/01/16/00/00/0cc175b9c0f1b6a831c399e269772661" }
    If the mapping for the id does not exist yet, this package calculates it by concatenating
    into a path:
    * $base_dir which is configurable
    * YYYY: current year
    * MM: current month
    * DD: current day of month
    * HH: current hour
    * MM: current minute
    * SS: current second
    * TEXT: the md5 of the _id
    Every call to C<add> will generate a directory entry in the backend database,
    if it didn't already exist.


new( OPTIONS )

Create a new Catmandu::DirectoryIndex::Map with the following configuration parameters:

See Catmandu::DirectoryIndex
Name of the store in the Catmandu configuration.

Ignored when bag instance is given.

Name of the bag in the Catmandu configuration.

Ignored when bag instance is given

Instance of Catmandu::Bag where all mappings between _id and _path are stored.


This Catmandu::DirectoryIndex::Map implements:



2020-05-22 perl v5.30.2