NAME

DBIx::DR::Iterator - iterator for DBIx::DR.

SYNOPSIS

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'

DESCRIPTION

The package constructs iterator from HASHREF or ARRAYREF value.

Methods

new

Constructor.

my $i = DBIx::DR::Iterator->new($arrayset [, OPTIONS ]);

Where OPTIONS are:

-item => 'decamelized_obj_define';

It will bless (or construct) row into specified class. See below.

By default it constructs DBIx::DR::Iterator::Item objects.

count

Returns count of elements.

is_changed

Returns (or set) flag that one of contained elements was changed.

exists(name|number)

Returns true if element 'name|number' is exists.

get(name|number)

Returns element by 'name|number'. It will throw exception if element isn't exists.

next

Returns next element or undef.

reset

Resets internal iterator (that is used by next).

all

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;

grep

Constructs new iterator that is subset of parent iterator.

my $busy = $list->grep(sub { $_[0]->busy ? 1 : 0 });

push

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 });

DBIx::DR::Iterator::Item

One row. It has methods names coincident with field names. Also it has a few additional methods:

new

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); }

iterator

Returns (or set) iterator object. The link is created by constructor. This is a weaken link.

is_changed

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

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.