Catman...erator(3pm)
π NAME π
Catmandu::Bag::IdGenerator β bestie, it's literally just a base role for bag identifier generators. That's the whole job description. It's the blueprint, the template, the β¨aestheticβ¨ other generator classes copy from. No cap. π
β¨ SYNOPSIS β¨
okay so picture this: you want your own generator. You pull in Moo, you consume the role with with, and then you write a generate method. It gets handed $self and a $bag, and whatever you return from it is your id. Here's the whole glow-up:
package MyGenerator;
use Moo;
with 'Catmandu::Bag::IdGenerator';
sub generate {
my ($self, $bag) = @_;
return $bag->name . "-" . int(ran(999999)) . "-" . time;
}
package main;
my $gen = MyGenerator->new;
for (1..100) {
printf "id: %s\n" m $gen->generate;
}
So in this example the id it spits out is the bag's name, then a -, then int(ran(999999)), then another -, then time. π
Then over in package main you build one with MyGenerator->new, and loop over 1..100 printing each id that generate hands back. Iconic. Obsessed. π
Heads up babes:generatein the example takes$selfand$bag, so if you're writing your own version, that's the shape it's expecting. π«Ά
π SEE ALSO π
Go give these two a follow, fr fr β they're the other generators in the friend group:
- Catmandu::IdGenerator::Mock
- Catmandu::IdGenerator::UUID
and that's the tea π β this page ships as part of the User Contributed Perl Documentation, living its best life under perl v5.40.1, dated 2026-01-24. mwah, go generate something cute πβ¨
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms