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

Merge branch 'master' of github.com:perlbot/perlbuut-pastebin

This commit is contained in:
Ryan Voots 2021-04-26 15:48:24 -04:00
commit 83ff291d6c
6 changed files with 80 additions and 8 deletions

View file

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

View file

@ -4,7 +4,6 @@ evalserver=true
blogspam=false
[database]
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@localhost/perlbot_pastes_dev"
[mojolicious.hypnotoad]
listen=["http://localhost:3001"]

2
etc/development.cfg Normal file
View file

@ -0,0 +1,2 @@
[database]
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@localhost/perlbot_pastes_dev"

2
etc/production.cfg Normal file
View file

@ -0,0 +1,2 @@
[database]
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@localhost/perlbot_pastes"

View file

@ -1,5 +1,6 @@
package App::Config;
use v5.24;
use strict;
use warnings;
@ -8,17 +9,38 @@ use Data::Dumper;
use FindBin qw($Bin);
use TOML;
use Hash::Merge qw/merge/;
use Syntax::Keyword::Try;
use Path::Tiny;
our @EXPORT=qw/$cfg/;
my $cfg_dir = path($Bin)->child('etc');
our $env = $ENV{MOJO_MODE} // $ENV{PLACK_ENV} // "development";
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;
my $merged_config;
try {
my $env_file = path($cfg_dir)->child($env.".cfg");
my $base_file = path($cfg_dir)->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, $env_error) = 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";
}
$merged_config;
};
sub get_config {

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;