pgc-www/lib/MyModel.pm
barnold 6ea53c5657 More on rows-per-page...
Added helpers and updated MyModel with a view to making rows-per-page
a user preference.
2022-09-19 10:04:57 +01:00

37 lines
722 B
Perl

package MyModel;
use feature qw( signatures );
use Moose;
use Moose::Util::TypeConstraints;
use Mojo::Log;
use Book::Schema;
use List::Util qw( max min );
no warnings qw( experimental::signatures );
# Keep rows-per-page within a sane range.
subtype 'RowsPerPage',
as 'Int',
where { 5 <= $_ && $_ <= 100 };
has 'rows_per_page' => (
is => 'rw',
isa => 'RowsPerPage',
required => 1,
default => 20,
);
our $logger = Mojo::Log->new;
# Share this among all model instances.
our $schema;
sub schema ($self) {
if (!defined $schema) {
$logger->info("Connecting to database.");
$schema = Book::Schema->connect('dbi:Pg:');
}
return $schema;
}
no Moose;
__PACKAGE__->meta->make_immutable;