Aniki

 view release on metacpan or  search on metacpan

lib/Aniki/Result/Collection.pm  view on Meta::CPAN

package Aniki::Result::Collection;
use 5.014002;

use namespace::autoclean;
use Mouse v2.4.5;
extends qw/Aniki::Result/;

use overload
    '@{}'    => sub { shift->rows },
    fallback => 1;

has row_datas => (
    is       => 'ro',
    required => 1,
);

has inflated_rows => (
    is      => 'ro',
    lazy    => 1,
    builder => '_inflate',
);

sub _inflate {
    my $self = shift;
    my $row_class  = $self->row_class;
    my $table_name = $self->table_name;
    my $handler    = $self->handler;
    return [
        map {
            $row_class->new(
                table_name => $table_name,
                handler    => $handler,
                row_data   => $_
            )
        } @{ $self->row_datas }
    ];
}

sub rows {
    my $self = shift;
    return $self->suppress_row_objects ? $self->row_datas : $self->inflated_rows;
}

sub count { scalar @{ shift->rows(@_) } }

sub first        { shift->rows(@_)->[0]  }
sub last :method { shift->rows(@_)->[-1] }
sub all          { @{ shift->rows(@_) }  }

__PACKAGE__->meta->make_immutable();
__END__

=pod

=encoding utf-8

=head1 NAME

Aniki::Result::Collection - Rows as a collection

=head1 SYNOPSIS

    my $result = $db->select(foo => { bar => 1 });
    for my $row ($result->all) {



( run in 0.935 second using v1.01-cache-2.11-cpan-5a3173703d6 )