barnold
6ea53c5657
Added helpers and updated MyModel with a view to making rows-per-page a user preference.
29 lines
724 B
Perl
29 lines
724 B
Perl
package MyModel::Book;
|
|
use feature qw( signatures );
|
|
use Moose;
|
|
extends 'MyModel';
|
|
no warnings qw( experimental::signatures );
|
|
|
|
sub count_all ($self) {
|
|
my $book_count = $self->schema->resultset('Book')->count;
|
|
return $book_count;
|
|
}
|
|
|
|
sub get_page ($self, $page_number = 1, $title_like = undef) {
|
|
my $search_condition = (defined $title_like)
|
|
? { "me.title" => { ilike => "\%$title_like\%" } }
|
|
: undef;
|
|
my $rs = $self->schema->resultset('Book')->search_rs(
|
|
$search_condition,
|
|
{ prefetch => [ "author" ],
|
|
order_by => [ "me.title " ],
|
|
page => $page_number,
|
|
rows => $self->rows_per_page,
|
|
},
|
|
);
|
|
return $rs;
|
|
}
|
|
|
|
no Moose;
|
|
__PACKAGE__->meta->make_immutable;
|