NAME
DBIx::Class::Util::ResultSet::Iterator - Iterator Helper
SYNOPSIS
Given a DBIx::Class::ResultSet wrap a basic iterator object around it
my $rs = $schema->resultset('Bar');
my $itr = DBIx::Class::Util::ResultSet::Iterator->new(resultset=>$rs);
while(my $row = $itr->next) {
...
}
DESCRIPTION
A DBIx::Class::ResultSet doesn't give you a lot of information by default that you might wish to have, such as the location one is at in the set, etc. This wraps a small class around the resultset to provide these.
METHODS
This component defines the following methods.
index
A positive number starting from zero which is the location in the set the current row is at.
count
A positive number starting from one which is the location in the set the current row is at.
escape
Upon completion of the current, stop execution and return the resultset at the current state.
is_first
Returns boolean true if the current row is the first in the set
is_not_first
Returns boolean true if the current row is NOT the first in the set
is_even
Returns true if the count of the location in the set is even
is_odd
Returns true if the count of the location in the set is odd
resultset
Accessor for the raw DBIx::Class::ResultSet we are wrapping.
first
Args: $coderef, ?$if_empty
If the current row is first in the set, execute a $coderef
, otherwise execute a $if_empty
coderef. Returns the $each
object so you can chain.
not_first
Args: $coderef, ?$if_empty
If the current row is NOT the first in the set, execute a $coderef
, otherwise execute a $if_empty
coderef. Returns the $each
object so you can chain.
even
Args: $coderef, ?$if_empty
If the current row is even in the set, execute a $coderef
, otherwise execute a $if_empty
coderef. Returns the $each
object so you can chain.
$each->even(
sub { print "Current item is even in index" },
);
odd
Args: $coderef, ?$if_empty
If the current row is odd in the set, execute a $coderef
, otherwise execute a $if_empty
coderef. Returns the $each
object so you can chain.
$each->odd(
sub { print "Current item is odd in index" },
);
next
Return the next row in the set or undef.
if
Arguments: $cond|$cond_codered, $pass_coderef, ?$fail_coderef, ?@args Returns: $self
Given a condition, execute either a pass or fail anonymous subroutine. The fail coderef is optional and the method returns $self
for chaining.
$each->if
(
$a>$b,
sub { warn "$a > $b" },
sub { warn "$a < $b" },
);
If the condition is a coderef, then $self
is passed as an argument along with any other @args
and the return is considered in boolean context.
$each->if
(
sub { shift->is_odd },
sub { warn "is odd" },
sub { warn "is even" },
);
AUTHOR
See DBIx::Class::ResultSet::SetControl