DBIx::...erator(3pm)

πŸ“¦
version 0.32 Β· 2 versions
  • 0.32 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.32 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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 constructs DBIx::DR::Iterator::Item objects.
  • -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 (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 πŸŽ€πŸ’–