1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut-pastebin synced 2025-06-07 14:17:26 -04:00

not happy with this, going to almost immediately revert it and then bring small pieces back

This commit is contained in:
Ryan Voots 2021-04-26 15:35:38 -04:00
parent 8c27b3e2b9
commit a165836816
9 changed files with 58 additions and 37 deletions

5
app.pl
View file

@ -5,6 +5,11 @@ use warnings;
use lib 'lib';
use Mojolicious::Commands;
use Mojolicious::Plugins;
my $plugins = Mojolicious::Plugins->new;
push @{$plugins->namespaces}, 'App::Plugins';
# Start command line interface for application
Mojolicious::Commands->start_app('App');

0
config/development.toml Normal file
View file

View file

@ -13,3 +13,4 @@ requires 'Mojolicious::Plugin::RemoteAddr';
requires 'App::EvalServerAdvanced::Protocol';
requires 'Future::Mojo';
requires 'Regexp::Assemble';
requires 'Hash::Merge';

View file

@ -7,7 +7,6 @@ use v5.22;
use Mojo::Base 'Mojolicious';
use Mojolicious::Plugin::TtRenderer;
use App::Config;
use App::Controller::Paste;
use App::Controller::Eval;
use App::Controller::Apiv1;
@ -20,10 +19,13 @@ use App::Model::Languages;
sub startup {
my $self = shift;
$self->config($cfg->{mojolicious});
# TODO get this to load the proper stuff from the config into the app
my $cfg_plg = $self->plugin('TomlConfig');
# $self->config($cfg->{mojolicious});
$self->plugin('RemoteAddr');
$self->plugin('tt_renderer' => {
template_options => {
PRE_CHOMP => 1,

View file

@ -1,30 +0,0 @@
package App::Config;
use strict;
use warnings;
use Exporter qw/import/;
use Data::Dumper;
use FindBin qw($Bin);
use TOML;
our @EXPORT=qw/$cfg/;
our $cfg = do {
my $toml = do {open(my $fh, "<", "$Bin/app.cfg"); local $/; <$fh>};
# With error checking
my ($data, $err) = from_toml($toml);
unless ($data) {
die "Error parsing toml: $err";
}
$data;
};
sub get_config {
my $key = shift;
return $cfg->{$key};
}
1;

View file

@ -3,7 +3,6 @@ package App::Controller::Paste;
use strict;
use warnings;
use App::Config;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::IOLoop;
use Mojo::Promise;
@ -40,7 +39,7 @@ sub to_root {
sub root {
my $c = shift;
$c->stash({languages => $c->languages->get_languages});
$c->stash({pastedata => q{}, channels => $cfg->{announce}{channels}, page_tmpl => 'editor.html'});
$c->stash({pastedata => q{}, channels => $c->app->config('announce')->{channels}, page_tmpl => 'editor.html'});
$c->render("page");
};
@ -53,7 +52,7 @@ sub edit_paste {
if ($row->{when}) {
$c->stash({languages => $c->languages->get_languages});
$c->stash({pastedata => $row->{paste}, channels =>$cfg->{announce}{channels}});
$c->stash({pastedata => $row->{paste}, channels =>$c->app->config('announce')->{channels}});
$c->stash({page_tmpl => 'editor.html'});
$c->render(template => 'page');

View file

@ -4,7 +4,6 @@ use strict;
use warnings;
use DBI;
use App::Config;
use Mojo::Base '-base';
use DateTime;
use Mojo::Pg;
@ -12,7 +11,6 @@ use Regexp::Assemble;
# TODO config for dbname
# has 'dbh' => sub {DBI->connect("dbi:SQLite:dbname=pastes.db", "", "", {RaiseError => 1, sqlite_unicode => 1})};
my $cfg = App::Config::get_config('database');
has 'pg' => sub {
Mojo::Pg->new($cfg->{dsc});

View file

@ -0,0 +1,46 @@
package App::Plugins::TomlConfig;
use Mojo::Base 'Mojolicious::Plugin::Config';
use v5.24;
use strict;
use warnings;
use Data::Dumper;
use TOML;
use Hash::Merge;
use Syntax::Keyword::Try;
use Path::Tiny;
sub parse {
my ($self, $content, $file, $conf, $app) = @_;
my $merged_config;
try {
my $env_file = path($file)->child($env.".cfg");
my $base_file = path($file)->child('base.cfg');
my $base_config_data = $base_file->slurp_utf8();
my $env_config_data = $env_file->slurp_utf8();
my ($base_config, $base_error) = from_toml($base_config_data);
die "$base_file: $base_error" if $base_error;
my $env_config = from_toml($env_config_data);
die "$env_file: $env_error" if $env_error;
$merged_config = merge($base_config, $env_config);
} catch($e) {
die "Unable to process config file: $e";
}
die Dumper($merged_config);
return $merged_config;
}
# TODO figure out what i want here
sub register { shift->SUPER::register(shift, {%{shift()}}) }
1;