Catman...erator(3pm)

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

πŸ’– Catmandu::Iterator β€” the manual page, but make it cute πŸ’–

okay bestie, so you've stumbled into Catman...erator(3pm) β€” yes that's the page title, it's giving ✨user contributed Perl documentation✨ energy, and it's literally all about Catmandu::Iterator, the base class for all Catmandu iterators πŸ‘‘. It's a 3pm page, so it's Perl module docs, and honestly? iconic. periodt.


🌸 NAME 🌸

Catmandu::Iterator β€” the base class for all Catmandu iterators πŸ’…

Like, every iterator in Catmandu-land descends from this thing. It's the blueprint. The mother of iterators. The moment. πŸ¦‹


✨ SYNOPSIS ✨

Here's the vibe, copied exactly because code is sacred and I do not play with it:

package My::MockIterator;

use Catmandu;
use Moo;

with 'Catmandu::Iterable';

sub generator {
  sub {
      # Generator some random data
      +{ random => rand };
  }
}

package main;

my $it = My::MockIterator->new;

my $first = $it->first;

$it->each(sub {
my $item = shift;

print $item->{random} , "\n";
});

my $it2 = $it->map(sub { shift->{random} * 2 });

So what's happening here, bestie? You roll your own class, you pull in Catmandu and Moo, you with 'Catmandu::Iterable' (that's the role doing the heavy lifting, iykyk), and then you define a generator that hands back a closure. That closure spits out one Perl hash at a time. Then ->new gives you an iterator, ->first grabs you the first item, ->each walks the whole thing and prints each random value, and ->map gives you a whole new iterator where every random got doubled. πŸ”₯


πŸŽ€ METHODS πŸŽ€

🧚 generator

Should return a closure that generates one Perl hash. That's it. That's the whole job. One hash per call, over and over, like a little hash vending machine. πŸ“

fr fr, if you don't give it a generator that returns a closure, the magic does not happen. no generator, no slay.

🌈 INHERIT 🌈

Okay so here's the tea: if you provide a generator, then the class will generator all methods from Catmandu::Iterable. (Yes, that's what the original says β€” "generator" as a verb. We respect the original's grammar choices in this house. πŸ’€)

Translation: you bring the one tiny generator, and Catmandu::Iterable shows up with the entire method catalogue. Main character energy from a two-line subclass. πŸ‘‘


πŸ‘€ SEE ALSO πŸ‘€

  • Catmandu::Iterable β€” go read this one next, bestie, it's literally where all the inherited methods live 🫢

and that's the whole page!! no cap, every single detail is in here, I did not skip a single crumb πŸ™ˆ

cute lil sign-off: this page ships as part of perl v5.40.1, dated 2026-01-24, and it was written for User Contributed Perl Documentation β€” aka the people's docs, the community's finest. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸŒˆβ­πŸ’œ

πŸ“¦ where this page comes from