Catman...ex::Map(3pm)

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

πŸ’– NAME πŸ’–

Catmandu::DirectoryIndex::Map β€” she translates between id and path using a Catmandu::Bag as her lookup table ✨

(also bestie this is a 3pm page, i.e. a Perl module doc from the User Contributed Perl Documentation, so you know it's the good stuff 🫢)


🌸 SYNOPSIS 🌸

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"
)->bag("paths");

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();

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this package uses a Catmandu::Bag backend to translate between ids and paths. that's the whole vibe πŸ’…

Every record looks like this, no cap:

{ _id => "a", _path => "/data/2018/01/01/16/00/00/0cc175b9c0f1b6a831c399e269772661" }

If the mapping for the id doesn't exist yet, this package just 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 add will generate a directory entry in the backend database, if it didn't already exist. so it's idempotent-ish bestie, it's not gonna duplicate on you 🫢


✨ METHODS ✨

πŸ’œ new( OPTIONS )

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

  • base_dir β€” See Catmandu::DirectoryIndex
  • store_name β€” Name of the store in the Catmandu configuration.

Ignored when bag instance is given.

  • bag_name β€” Name of the bag in the Catmandu configuration.

Ignored when bag instance is given

  • bag β€” Instance of Catmandu::Bag where all mappings between _id and _path are stored.

πŸŽ€ INHERITED METHODS πŸŽ€

This Catmandu::DirectoryIndex::Map implements:

  • Catmandu::DirectoryIndex

🌈 SEE ALSO 🌈

  • Catmandu::DirectoryIndex

and that's the whole page bestie, go forth and map some directories πŸ§šπŸ’–

this was perl v5.36.0, dated 2022-12-10, from the User Contributed Perl Documentation β€” Catman...ex::Map(3pm) ✨ slay, periodt πŸ’…

πŸ“¦ where this page comes from