package CMTD; use strict; use warnings; use Mojo::Base 'Mojolicious'; sub startup { my $self = shift; $self->plugin('CMTD::Helpers'); $self->plugin(Config => {file => 'cmtd.conf'}); $self->plugin(I18N => {namespace => 'CMTD::I18N', default => 'en'}); if (my $s = $self->app->config->{secret}) { $self->app->secrets([ $s ]); } else { my $s = sprintf "%08X%08X%08X", time(), rand(), rand(); $self->app->log->warn("!!! You should set a sign key for cookies in config !!!"); $self->app->secrets([ $s ]); } $self->app->attr(captcha => sub { my $config = $self->app->config->{captcha}; require CMTD::Captcha; my $cap = CMTD::Captcha->new(%{ $config }); return $cap; }); $self->app->attr(db => sub { my $c = $self->app->config->{db} || {}; require DBIx::Simple; my %opts = (AutoCommit => 1, RaiseError => 1, sqlite_see_if_its_a_number => 1); my $dbh = DBIx::Simple->new($c->{dsn}, $c->{user}, $c->{pass}, \%opts); return $dbh; }); # initial $self->app->maintenance; # periodic my $loop = Mojo::IOLoop->singleton; $loop->recurring(60 => sub { $self->app->maintenance; }); my $r = $self->routes; $r->get('/') -> to('main#index'); $r->get('/captcha') -> to('main#captcha'); $r->get('/comments/list') -> to('main#c_list'); $r->get('/comments/add') -> to('main#c_add'); } 1;