BeastBB/test/BeastBB/Mock/Controller.pm

35 lines
667 B
Perl

package BeastBB::Mock::Controller;
use Mojo::Base 'Mojolicious::Controller';
use 5.32.1;
use strict;
use warnings;
use Params::ValidationCompiler 'validation_for';
use BeastBB::Types qw/IsClassTypeGenerator/;
use BeastBB::Mock::Database;
{
my $validator = validation_for(
params => {
db => { type => IsClassTypeGenerator('BeastBB::Database'), optional => 1},
}
);
sub new {
my $class = shift;
my %params = $validator->(@_);
my $db = $params{db} // BeastBB::Mock::Database->new;
return bless { db => $db }, $class;
}
}
sub db {
my $self = shift;
return $self->{db};
}
1;