36 lines
No EOL
664 B
Perl
36 lines
No EOL
664 B
Perl
package AppConfig;
|
|
|
|
use v5.38.0;
|
|
use Object::Pad;
|
|
use feature 'signatures';
|
|
|
|
our $config_singleton;
|
|
|
|
class AppConfig {
|
|
use TOML;
|
|
use Path::Tiny;
|
|
use Carp qw/carp/;
|
|
|
|
field $api_services :param :accessor;
|
|
field $rss_services :param :accessor;
|
|
|
|
sub get_config($class) {
|
|
return $class->load_config("config.toml");
|
|
}
|
|
|
|
sub load_config($class, $file) {
|
|
return $config_singleton if $config_singleton;
|
|
|
|
my $toml_data = path($file)->slurp_utf8();
|
|
my ($data, $err) = from_toml($toml_data);
|
|
|
|
if ($err) {
|
|
carp "Couldn't parse $file: $err";
|
|
}
|
|
|
|
$config_singleton = $class->new($data->%*);
|
|
return $config_singleton;
|
|
}
|
|
}
|
|
|
|
1; |