BeastBB/lib/BeastBB.pm

68 lines
1.6 KiB
Perl

package BeastBB;
use 5.30.3;
use strict;
use warnings;
use Data::Dumper;
use Mojo::Base 'Mojolicious';
use Mojo::File;
use Const::Fast;
use Params::ValidationCompiler 'validation_for';
use Crypt::URandom 'urandom';
use BeastBB::Constants ( '$HOME_DIR', '$HOME_CONFIG_DIR', '$CONFIG_FILE', '$SECRET_DEFAULT_SIZE' );
use BeastBB::ConfigWriter;
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self;
}
sub startup {
my $self = shift;
$self->PrepareConfig;
$self->PrepareSecrets;
$self->PrepareRoutes;
return $self;
}
sub PrepareSecrets {
my $self = shift;
my $config = $self->config;
$self->secrets( $config->{secrets} );
}
sub PrepareRoutes {
my $self = shift;
my $routes = $self->routes;
@{ $self->renderer->paths() } =
( Mojo::File::curfile->dirname->child('BeastBB')->child('templates')
->to_string );
@{ $self->static->paths() } =
( Mojo::File::curfile->dirname->child('BeastBB')->child('public')
->to_string );
print Data::Dumper::Dumper $self->renderer->paths;
if ( !exists $self->config->{installed} ) {
$routes->get('/')->to('install#welcome');
$routes->post('/install/database')->to('install#install_database');
}
}
sub PrepareConfig {
my $self = shift;
$HOME_CONFIG_DIR->make_path if !-e $HOME_CONFIG_DIR;
if ( !-e $CONFIG_FILE ) {
my $config_writer =
BeastBB::ConfigWriter->new( config_file => $CONFIG_FILE );
$config_writer->PopulateExampleConfigFile(
secret_size => $SECRET_DEFAULT_SIZE );
}
$self->plugin( Config => file => $CONFIG_FILE->to_string );
}
1;