mirror of
https://github.com/perlbot/perlbuut-pastebin
synced 2025-06-07 14:17:26 -04:00
Merge branch 'master' of github.com:perlbot/perlbuut-pastebin
This commit is contained in:
commit
83ff291d6c
6 changed files with 80 additions and 8 deletions
1
cpanfile
1
cpanfile
|
@ -13,3 +13,4 @@ requires 'Mojolicious::Plugin::RemoteAddr';
|
||||||
requires 'App::EvalServerAdvanced::Protocol';
|
requires 'App::EvalServerAdvanced::Protocol';
|
||||||
requires 'Future::Mojo';
|
requires 'Future::Mojo';
|
||||||
requires 'Regexp::Assemble';
|
requires 'Regexp::Assemble';
|
||||||
|
requires 'Syntax::Keyword::Try';
|
||||||
|
|
|
@ -4,7 +4,6 @@ evalserver=true
|
||||||
blogspam=false
|
blogspam=false
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@localhost/perlbot_pastes_dev"
|
|
||||||
|
|
||||||
[mojolicious.hypnotoad]
|
[mojolicious.hypnotoad]
|
||||||
listen=["http://localhost:3001"]
|
listen=["http://localhost:3001"]
|
2
etc/development.cfg
Normal file
2
etc/development.cfg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[database]
|
||||||
|
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@localhost/perlbot_pastes_dev"
|
2
etc/production.cfg
Normal file
2
etc/production.cfg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[database]
|
||||||
|
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@localhost/perlbot_pastes"
|
|
@ -1,5 +1,6 @@
|
||||||
package App::Config;
|
package App::Config;
|
||||||
|
|
||||||
|
use v5.24;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
|
@ -8,17 +9,38 @@ use Data::Dumper;
|
||||||
use FindBin qw($Bin);
|
use FindBin qw($Bin);
|
||||||
|
|
||||||
use TOML;
|
use TOML;
|
||||||
|
use Hash::Merge qw/merge/;
|
||||||
|
use Syntax::Keyword::Try;
|
||||||
|
use Path::Tiny;
|
||||||
|
|
||||||
our @EXPORT=qw/$cfg/;
|
our @EXPORT=qw/$cfg/;
|
||||||
|
|
||||||
|
my $cfg_dir = path($Bin)->child('etc');
|
||||||
|
|
||||||
|
our $env = $ENV{MOJO_MODE} // $ENV{PLACK_ENV} // "development";
|
||||||
|
|
||||||
our $cfg = do {
|
our $cfg = do {
|
||||||
my $toml = do {open(my $fh, "<", "$Bin/app.cfg"); local $/; <$fh>};
|
my $merged_config;
|
||||||
# With error checking
|
|
||||||
my ($data, $err) = from_toml($toml);
|
try {
|
||||||
unless ($data) {
|
my $env_file = path($cfg_dir)->child($env.".cfg");
|
||||||
die "Error parsing toml: $err";
|
my $base_file = path($cfg_dir)->child('base.cfg');
|
||||||
}
|
|
||||||
$data;
|
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 {
|
sub get_config {
|
||||||
|
|
46
lib/App/Plugins/TomlConfig.pm
Normal file
46
lib/App/Plugins/TomlConfig.pm
Normal 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;
|
Loading…
Add table
Reference in a new issue