summaryrefslogtreecommitdiff
path: root/lib/JWebmail/Plugin
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de>2022-05-06 02:24:42 +0200
committerJannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de>2022-05-06 02:24:42 +0200
commite629a35ea29dd9da9f61511130cbbee6d910e4cf (patch)
tree97c25c1da8f29967e8205902142a9b038b1684e3 /lib/JWebmail/Plugin
parent3fbc68b0892b2914471eeab7885bd4f9e7f9175f (diff)
switched to toml config format
improved security with load over require
Diffstat (limited to 'lib/JWebmail/Plugin')
-rw-r--r--lib/JWebmail/Plugin/TOMLConfig.pm61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/JWebmail/Plugin/TOMLConfig.pm b/lib/JWebmail/Plugin/TOMLConfig.pm
new file mode 100644
index 0000000..20a2950
--- /dev/null
+++ b/lib/JWebmail/Plugin/TOMLConfig.pm
@@ -0,0 +1,61 @@
+package JWebmail::Plugin::TOMLConfig;
+
+use Mojo::Base Mojolicious::Plugin::Config;
+
+use TOML::Tiny 'from_toml';
+
+
+has parse_func => sub { \&from_toml };
+
+
+sub parse {
+ my ($self, $content, $_file, $_plugin_conf, $_app) = @_;
+
+ my $config = $self->parse_func->($content);
+ die "parse_func must return hash ref" unless ref $config eq 'HASH';
+
+ return $config;
+}
+
+sub register { shift->SUPER::register(shift, {ext => 'toml', %{shift()}}) }
+
+
+1
+
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+TOMLConfig - Reads in TOML config files.
+
+=head1 SYNOPSIS
+
+ $app->plugin('TOMLConfig');
+
+ @@ my_app.toml
+
+ # global section
+ key = "val" # line comment
+ [section]
+ other_key = "other_val"
+ number_key = 5
+ [other.section]
+ values = ["key1", "key2", "key3"]
+
+=head1 DESCRIPTION
+
+TOML is my favorite config format :)
+
+=head1 OPTIONS
+
+=head2 default
+
+Sets default configuration values.
+
+=head1 DEPENDENCIES
+
+TOML::Tiny
+
+=cut