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.16 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       These configuration values are currently reserved:
51
52       "config_override"
53         If this configuration value has been set in "config" in Mojolicious
54         when this plugin is loaded, it will not do anything besides loading
55         deployment specific plugins.
56
57       "plugins"
58           plugins => [{SetUserGroup => {user => 'sri', group => 'staff'}}]
59
60         One or more deployment specific plugins that should be loaded right
61         after this plugin has been loaded.
62
63       The code of this plugin is a good example for learning to build new
64       plugins, you're welcome to fork it.
65
66       See "PLUGINS" in Mojolicious::Plugins for a list of plugins that are
67       available by default.
68

OPTIONS

70       Mojolicious::Plugin::Config supports the following options.
71
72   default
73         # Mojolicious::Lite
74         plugin Config => {default => {foo => 'bar'}};
75
76       Default configuration, making configuration files optional.
77
78   ext
79         # Mojolicious::Lite
80         plugin Config => {ext => 'stuff'};
81
82       File extension for generated configuration filenames, defaults to
83       "conf".
84
85   file
86         # Mojolicious::Lite
87         plugin Config => {file => 'myapp.conf'};
88         plugin Config => {file => '/etc/foo.stuff'};
89
90       Path to configuration file, absolute or relative to the application
91       home directory, defaults to the value of the "MOJO_CONFIG" environment
92       variable or "$moniker.conf" in the application home directory.
93

METHODS

95       Mojolicious::Plugin::Config inherits all methods from
96       Mojolicious::Plugin and implements the following new ones.
97
98   load
99         $plugin->load($file, $conf, $app);
100
101       Loads configuration file and passes the content to "parse".
102
103         sub load ($self, $file, $conf, $app) {
104           ...
105           return $self->parse($content, $file, $conf, $app);
106         }
107
108   parse
109         $plugin->parse($content, $file, $conf, $app);
110
111       Parse configuration file.
112
113         sub parse ($self, $content, $file, $conf, $app) {
114           ...
115           return $hash;
116         }
117
118   register
119         my $config = $plugin->register(Mojolicious->new);
120         my $config = $plugin->register(Mojolicious->new, {file => '/etc/app.conf'});
121
122       Register plugin in Mojolicious application and merge configuration.
123

SEE ALSO

125       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
126
127
128
129perl v5.34.0                      2021-07-22    Mojolicious::Plugin::Config(3)
Impressum