Catman...Number(3pm)

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

✨ NAME ✨

Catmandu::DirectoryIndex::Number β€” bestie it's a natural number based directory translator πŸ’… (yes this is Catman...Number(3pm) from the User Contributed Perl Documentation, we're doing the whole thing, sit down, hydrate πŸ“)


🌸 SYNOPSIS 🌸

use Catmandu::DirectoryIndex::Number;

my $p = Catmandu::DirectoryIndex::Number->new(
    base_dir => "/data",
    keysize => 9
);

# get mapping for id: { _id => 1234, _path => "/data/000/001/234" }
# can be undef
my $mapping = $p->get(1234);

# create mapping for id. Path created if necessary
my $mapping = $p->add(1234);

# Catmandu::DirectoryIndex::Number is a Catmandu::Iterable
# Returns list of records: [{ _id => "000001234", _path => "/data/000/001/234" }]
my $mappings = $p->to_array();

obsessed with her honestly πŸ¦‹ so you spin up a new one with a base_dir and a keysize, you get(1234) to find where that id lives (and heads up, it can come back undef, no drama), you add(1234) to actually make the mapping and the path gets created if it doesn't exist yet, and because this whole thing is a Catmandu::Iterable you can just to_array() and get your list of records back. iconic behavior ✨


πŸŽ€ METHODS πŸŽ€

πŸ’– new( base_dir => $base_dir , keysize => NUM )

Build yourself a fresh new Catmandu::DirectoryIndex::Number, and here's the config tea you can pass in:

  • base_dir β€” go look at Catmandu::DirectoryIndex, it's all explained over there πŸ‘€
  • keysize β€” so by default the directory structure is 3 levels deep. But if you want more nesting you can have it, just set keysize. The one rule bestie: keysize needs to be a multiple of 3. Not 4, not 5, multiples of 3 only, periodt πŸ’…

😭 LIMITATIONS 😭

ngl there's a whole vibe check on the keys: the keys in this directory can only be natural numbers β€” 0,1,2 ... and that's it. No strings, no negatives, no chaos πŸ™ˆ


πŸ‘‘ INHERITED METHODS πŸ‘‘

This Catmandu::DirectoryIndex::Number implements:

  • Catmandu::DirectoryIndex

🌈 SEE ALSO 🌈

  • Catmandu::DirectoryIndex

okay that's the whole page, you ate that 🫢 this little baddie is running under perl v5.36.0 and got its last glow-up on 2022-12-10 β€” go forth and index your natural numbers, bestie πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from