Module:...Element(3)
π NAME π
Okay so this is the Module:...Element(3) page from the User Contributed Perl Documentation, and it's giving βtiny iterator element object with main character energy.β The actual NAME situation is:
Module::Generic::Iterator::Element - An Array Iterator Element Object Class
β¨ SYNOPSIS β¨
my $i = Module::Generic::Iterator->new( [qw( Joe John Mary )] );
# or also:
my $a = Module::Generic::Array->new( [qw( Joe John Mary )] );
my $i = $a->iterator;
while( $i->has_next )
{
my $elem = $i->next;
my $value = $elem->value;
# Get the next element relative to our element
printf( "Next value is: %s at offset %d\n", $elem->next, $elem->next->pos );
}
π VERSION π
v0.1.0 β cute, concise, iconic.
π¦ DESCRIPTION π¦
This is an object class for Module::Generic::Iterator::Element objects as returned by various methods of Module::Generic::Iterator. So like, it's the little element object that shows up when you're doing iterator things. Bestie, it's literally the element wrapper. π
π§Έ CONSTRUCTOR π§Έ
β¨ new β¨
Provided with an array value (whatever that may be) and an optional hash reference of parameters, and this will create a new iterator and return it.
Typical parameters are:
parentβ This is theModule::Generic::Iteratorobject and it is required. Required required, no cap. π«Ά
πΈ METHODS πΈ
πΈ has_next πΈ
Returns true if there is a next element relative to this element:
my $first = $iter->first;
if( $first->has_next )
{
print( "There is a next element\n" );
}
π has_prev π
Returns true if there is a previous element relative to this element:
my $last = $iter->last;
if( $last->has_prev )
{
print( "There is a previous element\n" );
}
π₯ next π₯
Returns the next element as a Module::Generic::Iterator::Element object when chaining. In scalar context, returns the elementβs value:
my $first = $iter->first;
my $next = $first->next; # Next element
print( $next->value, "\n" ); # Value of next element
my $value = $first->next; # In scalar context, returns the value
Returns undef in scalar context, or an empty list in list context if there are no more element. That's the vibe check: no next element, no value. π
π¦ parent π¦
Sets or gets a Module::Generic::Iterator object as the parent object for this array element.
my $elem = $iter->first;
my $parent = $elem->parent;
$parent->reset;
π pos π
Returns the position of the object in the iterator. This is read-only and returns an integer.
my $elem = $iter->find( "Jack" );
print( $elem->pos, "\n" ); # e.g., 1
π prev π
Returns the previous element as a Module::Generic::Iterator::Element object when chaining. In scalar context, returns the elementβs value:
my $last = $iter->last;
my $prev = $last->prev; # Previous element's value
print( $last->prev->value, "\n" ); # Same (value of previous element)
my $value = $last->prev; # In scalar context, returns the value
Returns undef in scalar context, or an empty list in list context if there are no more element. Same energy as next, just going backwards. π«Ά
π value π
Returns the raw value of the element object:
my $elem = $iter->first;
print( $elem->value, "\n" ); # e.g., "John"
π SERIALISATION π
Serialisation by CBOR, Sereal and Storable::Improved (or the legacy Storable) is supported by this package. To that effect, the following subroutines are implemented: FREEZE, THAW, STORABLE_freeze and STORABLE_thaw. Bestie, it freezes and thaws. Iconic. π§
π THREAD-SAFETY π
Module::Generic::Iterator::Element is thread-safe for all operations, as it operates on per-object state and does not modify shared resources at runtime.
Key considerations for thread-safety:
- Shared Variables β There are no shared variables that are modified at runtime. The global
$DEBUGvariable (inherited fromModule::Generic) is typically set before threads are created, and it is the user's responsibility to ensure thread-safety if modified at runtime:
use threads;
local $Module::Generic::Iterator::DEBUG = 0; # Set before threads
my @threads = map
{
threads->create(sub
{
my $iter = Module::Generic::Iterator->new( [1, 2, 3] );
$iter->next; # Thread-safe
});
} 1..5;
$_->join for( @threads );
- Object State β Iterator data (e.g.,
elements,pos,valueinModule::Generic::Iterator::Element) is stored per-object, ensuring thread isolation:
use threads;
my @threads = map
{
threads->create(sub
{
my $iter = Module::Generic::Iterator->new( [1, 2, 3] );
while( my $elem = $iter->next )
{
print( $elem->value, "\n" ); # Thread-safe
}
});
} 1..5;
$_->join for( @threads );
- Serialisation β Serialisation methods (
FREEZE,THAW) operate on per-object state, making them thread-safe.
For debugging in threaded environments (depending on your Operating System):
ls -l /proc/$$/fd # List open file descriptors
π SEE ALSO π
Module::Generic::Iterator::Element, Module::Generic::Array
π«Ά AUTHOR π«Ά
Jacques Deguest <jack@deguest.jp>
π COPYRIGHT & LICENSE π
Copyright (c) 2000-2025 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
okay bye bestie π
π«Ά β this page is from perl v5.42.2, dated 2026-02-15, and lives under Module:...Element(3). β¨
π¦ where this page comes from
- alpine 3.24: perl-module-generic-doc 1.1.3-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms