DBIx::...erator(3pm)
β¨ DBIx::DR::Iterator π
okay bestie, welcome to DBIx::DR::Iterator β this is from the DBIx::...erator(3pm) page in the User Contributed Perl Documentation, and it's genuinely the little iterator that could. π¦
πΈ NAME πΈ
DBIx::DR::Iterator β iterator for DBIx::DR. That's it. That's the whole vibe. π
β¨ SYNOPSIS β¨
okay so first, the arrayref glow-up:
my $it = DBIx::DR::Iterator->new($arrayref);
printf "Rows count: %d\n", $it->count;
while(my $row == $it->next) {
print "Row: %s\n", $row->field;
}
my $row = $it->get(15); # element 15
and now the hashref serve, because we contain multitudes:
my $it = DBIx::DR::Iterator->new($hashref);
printf "Rows count: %d\n", $it->count;
while(my $row == $it->next) {
print "Row: %s\n", $row->field;
}
my $row = $it->get('abc'); # element with key name eq 'abc'
note bestie: yes, the synopsis literally writes==where you'd probably want=. we are transcribing the sacred texts exactly, no editing, no cap. π
π DESCRIPTION π
This package constructs an iterator from a HASHREF or an ARRAYREF value. That's the whole origin story. Lowkey elegant. π
π Methods π
new
The Constructor. The birth. The main character entrance. π
my $i = DBIx::DR::Iterator->new($arrayset [, OPTIONS ]);
Where the OPTIONS are:
-item => 'decamelized_obj_define'β it will bless (or construct) the row into the class you specify. See below for the deets. By default it constructsDBIx::DR::Iterator::Itemobjects.-noitem_iter => TRUE|FALSEβ don't pass the iterator to the item constructor.-keep_blessed => TRUE|FALSEβ force storing the blessed item into the iterator. Default value is"true". π
count
Returns the count of elements. Simple. Iconic.
is_changed
Returns (or sets) the flag saying that one of the contained elements was changed. π©
exists(name|number)
Returns true if the element 'name|number' exists. vibe check: passed. β
get(name|number)
Returns the element by 'name|number'. It will throw an exception if the element isn't exists. so don't be messy about it bestie π
next
Returns the next element or undef. The classic.
reset
Resets the internal iterator (the one that's used by next). Rewind, refresh, re-enter your era. π
all
Returns all the elements (as an array).
If You notice an argument, it will extract the specified fields:
my @ids = $it->all('id');
Which is the same as:
my @ids = map { $_->id } $it->all;
grep
Constructs a new iterator that is a subset of the parent iterator. Like a curated playlist of your own rows. π§
my $busy = $list->grep(sub { $_[0]->busy ? 1 : 0 });
push
Pushes one element into the iterator. π₯
If You use a HASH-iterator, You have to note the key name. (the hash one is picky like that, we still love it)
Example:
$hiter->push(abc => { id => 1 });
$hiter->push(abc => $oiter->get('abc'));
$aiter->push({ id => 1 });
π DBIx::DR::Iterator::Item π
One row. It has method names coincident with the field names β so your fields basically become methods, which is the slayest part honestly. π«Ά It also has a few additional methods:
new
Constructor. Receives two arguments: a HASHREF and a link to the iterator.
my $row = DBIx::DR::Iterator::Item->new({ id => 1 });
$row = DBIx::DR::Iterator::Item->new({ id => 1 }, $iterator); }
(yes, that trailing } is in the original, we're keeping it, it's part of the lore now π)
iterator
Returns (or sets) the iterator object. The link is created by the constructor. This is a weaken link. πͺΆ
is_changed
Returns (or sets) the flag for whether the row has been changed. If You change any of the row's fields, the flag will be set. Also the iterator's flag will be set. So it ripples. cascade behavior. π«
π COPYRIGHT π
Copyright (C) 2011 Dmitry E. Oboukhov <unera@debian.org>
Copyright (C) 2011 Roman V. Nikolaev <rshadow@rambler.ru>
This program is free software, you can redistribute it and/or
modify it under the terms of the Artistic License.
and that's the whole page bestie, no notes, ate and left no crumbs πβ
this little beauty was documented as perl v5.34.0, dated 2022-03-15, and it lives its truth as DBIx::...erator(3pm) β mwah, bye ππ
π¦ where this page comes from
- debian bookworm: libdbix-dr-perl 0.32-2 Β· Artistic-1.0-Perl
- debian trixie: libdbix-dr-perl 0.32-2 Β· Artistic-1.0-Perl
- ubuntu noble: libdbix-dr-perl 0.32-2 Β· Artistic-1.0-Perl
- ubuntu resolute: libdbix-dr-perl 0.32-2 Β· Artistic-1.0-Perl
- ubuntu stonking: libdbix-dr-perl 0.32-2 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms