summaryrefslogtreecommitdiff
path: root/lib/JWebmail/Plugin/TOMLConfig.pm
blob: 20a29508d20afcd251ea03c671dae231a57de44d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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