1Mojolicious::Plugin::CoUnsfeirg(C3o)ntributed Perl DocumMeonjtoaltiicoinous::Plugin::Config(3)
2
3
4

NAME

6       Mojolicious::Plugin::Config - Perl-ish configuration plugin
7

SYNOPSIS

9         # myapp.conf (it's just Perl returning a hash)
10         {
11           # Just a value
12           foo => "bar",
13
14           # Nested data structures are fine too
15           baz => ['♥'],
16
17           # You have full access to the application
18           music_dir => app->home->child('music')
19         };
20
21         # Mojolicious
22         my $config = $app->plugin('Config');
23         say $config->{foo};
24
25         # Mojolicious::Lite
26         my $config = plugin 'Config';
27         say $config->{foo};
28
29         # foo.html.ep
30         %= $config->{foo}
31
32         # The configuration is available application-wide
33         my $config = app->config;
34         say $config->{foo};
35
36         # Everything can be customized with options
37         my $config = plugin Config => {file => '/etc/myapp.stuff'};
38

DESCRIPTION

40       Mojolicious::Plugin::Config is a Perl-ish configuration plugin.
41
42       The application object can be accessed via $app or the "app" function,
43       strict, warnings, utf8 and Perl 5.10 features are automatically
44       enabled. A default configuration filename in the application home
45       directory will be generated from the value of "moniker" in Mojolicious
46       ("$moniker.conf"). You can extend the normal configuration file
47       "$moniker.conf" with "mode" specific ones like "$moniker.$mode.conf",
48       which will be detected automatically.
49
50       If the configuration value "config_override" has been set in "config"
51       in Mojolicious when this plugin is loaded, it will not do anything.
52
53       The code of this plugin is a good example for learning to build new
54       plugins, you're welcome to fork it.
55
56       See "PLUGINS" in Mojolicious::Plugins for a list of plugins that are
57       available by default.
58

OPTIONS

60       Mojolicious::Plugin::Config supports the following options.
61
62   default
63         # Mojolicious::Lite
64         plugin Config => {default => {foo => 'bar'}};
65
66       Default configuration, making configuration files optional.
67
68   ext
69         # Mojolicious::Lite
70         plugin Config => {ext => 'stuff'};
71
72       File extension for generated configuration filenames, defaults to
73       "conf".
74
75   file
76         # Mojolicious::Lite
77         plugin Config => {file => 'myapp.conf'};
78         plugin Config => {file => '/etc/foo.stuff'};
79
80       Path to configuration file, absolute or relative to the application
81       home directory, defaults to the value of the "MOJO_CONFIG" environment
82       variable or "$moniker.conf" in the application home directory.
83

METHODS

85       Mojolicious::Plugin::Config inherits all methods from
86       Mojolicious::Plugin and implements the following new ones.
87
88   load
89         $plugin->load($file, $conf, $app);
90
91       Loads configuration file and passes the content to "parse".
92
93         sub load {
94           my ($self, $file, $conf, $app) = @_;
95           ...
96           return $self->parse($content, $file, $conf, $app);
97         }
98
99   parse
100         $plugin->parse($content, $file, $conf, $app);
101
102       Parse configuration file.
103
104         sub parse {
105           my ($self, $content, $file, $conf, $app) = @_;
106           ...
107           return $hash;
108         }
109
110   register
111         my $config = $plugin->register(Mojolicious->new);
112         my $config = $plugin->register(Mojolicious->new, {file => '/etc/app.conf'});
113
114       Register plugin in Mojolicious application and merge configuration.
115

SEE ALSO

117       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
118
119
120
121perl v5.28.1                      2018-11-22    Mojolicious::Plugin::Config(3)
Impressum