---
name: "Catmandu::Iterator"
section: "3pm"
platform: "linux"
package: "libcatmandu-perl"
version: "1.2024-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Catmandu::Iterator"
---

# Catmandu::Iterator(3pm)

Base class for all Catmandu iterators

## NAME

Catmandu::Iterator - Base class for all Catmandu iterators

## SYNOPSIS

```
  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 });
```

## METHODS

### generator

Should return a closure that generates one Perl hash.

## INHERIT

If you provide a generator, then the class will generator all methods from Catmandu::Iterable.

## SEE ALSO

Catmandu::Iterable
