DBIx::DR::Iterator(3pm) | User Contributed Perl Documentation | DBIx::DR::Iterator(3pm) |
DBIx::DR::Iterator - iterator for DBIx::DR.
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 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'
The package constructs iterator from HASHREF or ARRAYREF value.
Constructor.
my $i = DBIx::DR::Iterator->new($arrayset [, OPTIONS ]);
Where OPTIONS are:
By default it constructs DBIx::DR::Iterator::Item objects.
Returns count of elements.
Returns (or set) flag that one of contained elements was changed.
Returns true if element 'name|number' is exists.
Returns element by 'name|number'. It will throw exception if element isn't exists.
Returns next element or undef.
Resets internal iterator (that is used by next).
Returns all elements (as an array).
If You notice an argument it will extract specified fields:
my @ids = $it->all('id');
The same as:
my @ids = map { $_->id } $it->all;
Constructs new iterator that is subset of parent iterator.
my $busy = $list->grep(sub { $_[0]->busy ? 1 : 0 });
Pushes one element into iterator.
If You use HASH-iterator You have to note key name.
Example
$hiter->push(abc => { id => 1 }); $hiter->push(abc => $oiter->get('abc')); $aiter->push({ id => 1 });
One row. It has methods names coincident with field names. Also it has a few additional methods:
Constructor. Receives two arguments: HASHREF and link to iterator.
my $row = DBIx::DR::Iterator::Item->new({ id => 1 }); $row = DBIx::DR::Iterator::Item->new({ id => 1 }, $iterator); }
Returns (or set) iterator object. The link is created by constructor. This is a weaken link.
Returns (or set) flag if the row has been changed. If You change any of row's fields the flag will be set. Also iterator's flag will be set.
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.
2022-03-15 | perl v5.34.0 |