MooseX::Iterator(3)
β¨ 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:
keyandvalueπ
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 π»
π COPYRIGHT AND LICENSE π
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=itemwas just out there raw-dogging it with no=overto 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
- fedora 43: perl-MooseX-Iterator 0.11-47.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms