MooseX::Iterator(3)

πŸ“¦
version 0.11 Β· 2 versions
, in fedora 43

✨ NAME ✨

MooseX::Iterator β€” bestie, it's literally "iterate over collections". That's the whole vibe. πŸ’…

(this is MooseX::Iterator(3) from the User Contributed Perl Documentation, in case u were wondering where u are 🫢)


🌈 SYNOPSIS 🌈

okay so there's two ways to do this, pick ur fighter ✨

Option 1: access the Iterator directly πŸ’–

use Moose;
use MooseX::Iterator;

my $iter = MooseX::Iterator::Array->new( collection => [ 1, 2, 3, 4, 5, 6 ] );

my $count = 1;
while ( $iter->has_next ) {
    print $iter->next;
}

Option 2: use the meta class πŸ‘‘

package TestIterator;

use Moose;
use MooseX::Iterator;

has collection => (
    is      => 'ro',
    isa     => 'HashRef',
    default => sub { { one => '1', two => '2', three => '3' } },
);

has iter => (
    metaclass    => 'Iterable',
    iterate_over => 'collection',
);

no Moose;

package main;
use Data::Dumper;

my $test = TestIterator->new;

my $iter = $test->iter;

while ( $iter->has_next ) {
    my $next = $iter->next;
    print $next->{'key'}   . "\n";
    print $next->{'value'} . "\n";
}

πŸ’« DESCRIPTION πŸ’«

so basically this is an attempt to add smalltalk-like streams to Moose. rn it works with ArrayRefs and HashRefs. that's it, that's the tea πŸ“

next πŸ¦‹

the next method hands u the next item in the collection. no cap.

  • for arrays it returns the element of the array ✨
  • for hashes it returns a pair as a hashref with the keys: key and value πŸ’–

has_next πŸ’…

the has_next method is a boolean method that's true if there's another item in the collection after the current item, and false if there isn't. vibe check for "is there more?" 😌

peek πŸ™ˆ

the peek method returns the next item without moving the state of the iterator forward. it's giving "look but don't touch". it returns undef if it's at the end of the collection.

reset πŸŽ€

resets the cursor, so u can iterate through the elements again. main character gets a redo, periodt. πŸ”₯

Subclassing MooseX::Iterator::Meta::Iterable 🧚

when ur subclassing MooseX::Iterator::Meta::Iterable for ur own iterators, override MooseX::Iterator::Meta::Iterable::_calculate_iterator_class_for_type to return the name of the class that iterates over ur new collection type. that class must implement the MooseX::Iterator::Role role. iykyk πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

Robert Boone <rlb@cpan.org>

and thank u to Steven Little (steven) and Matt Trout (mst) for the help and advice they gave. absolute icons, both of them πŸ’œ


🌸 CONTRIBUTORS 🌸

Johannes Plunien

Code Repository πŸ’»


this library is free software; u can redistribute it and/or modify it under the same terms as Perl itself. slay ✨


πŸ’€ POD ERRORS πŸ’€

hey! so the above document had some coding errors, which are explained below:

around line 96:

  • '=item' outside of any '=over'
not me pointing out that the docs themselves need a little glow-up 😭 the =item was just out there raw-dogging it with no =over to hold it down. anyway.

and that's the whole page bestie!! 🌈 this was MooseX::Iterator(3) from perl v5.42.0, dated 2025-07-25. go forth and iterate, ur doing amazing sweetie πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from