Catman...nerator(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

✨ NAME ✨

Catmandu::IdGenerator β€” a base role for identifier generators πŸŽ€

okay so picture this: you need IDs, like, a LOT of IDs, and you don't wanna hand-roll that logic every single time. so this is a role β€” a base role, the blueprint kind β€” that you with into your own class so your class becomes An Identifier Generator. it's giving template, it's giving "just give me a generate method and I'll handle the rest" πŸ‘‘


🌸 SYNOPSIS 🌸

package MyGenerator;

use Moo;

with 'Catmandu::IdGenerator';

sub generate {
   my ($self) = @_;
   return int(rand(999999)) . "-" . time;
}

package main;

my $gen = MyGenerator->new;

for (1..100) {
   printf "id: %s\n" m $gen->generate;
}

like. look at her go πŸ’… you roll a class, you pull in the role with with, you write your very own generate sub β€” and that's literally the whole job. the example does int(rand(999999)) . "-" . time which is giving chaos-chic random-number-plus-timestamp energy πŸ”₯ then in package main you build one with MyGenerator->new, loop for (1..100), and print each id.

bestie I need you to know I am copying that printf line character for character, m and all, exactly like the original has it. no editing, no "fixing", no notes πŸ™ˆ we reproduce, we do not rewrite. that's the rule.

πŸ¦‹ SEE ALSO πŸ¦‹

  • Catmandu::IdGenerator::Mock β€” the fake one, for when you need a stand-in
  • Catmandu::IdGenerator::UUID β€” the UUID one, for when you want the real deal ✨

and that's the whole page, bestie, short and sweet like a good iced coffee 🧚 this one came from the User Contributed Perl Documentation, shipped with perl v5.40.1, dated 2026-01-24. go forth and generate ids, you absolute icon πŸ’–πŸŒˆπŸ‘‘

πŸ“¦ where this page comes from