1Mojolicious::Plugin::NoUtsYeArMLCCoonntfriigb(u3t)ed PerMlojDoolciucmieonutsa:t:iPolnugin::NotYAMLConfig(3)
2
3
4
6 Mojolicious::Plugin::NotYAMLConfig - Not quite YAML configuration
7 plugin
8
10 # myapp.yml (it's just YAML with embedded Perl)
11 ---
12 foo: bar
13 baz:
14 - ♥
15 music_dir: <%= app->home->child('music') %>
16
17 # Mojolicious
18 my $config = $app->plugin('NotYAMLConfig');
19 say $config->{foo};
20
21 # Mojolicious::Lite
22 my $config = plugin 'NotYAMLConfig';
23 say $config->{foo};
24
25 # foo.html.ep
26 %= config->{foo}
27
28 # The configuration is available application-wide
29 my $config = app->config;
30 say $config->{foo};
31
32 # Everything can be customized with options
33 my $config = plugin NotYAMLConfig => {file => '/etc/myapp.conf'};
34
36 Mojolicious::Plugin::NotYAMLConfig is a YAML configuration plugin that
37 preprocesses its input with Mojo::Template. By default it uses
38 CPAN::Meta::YAML for parsing, which is not the best YAML module
39 available, but good enough for most config files. If you need something
40 more correct you can use a different module like YAML::XS with the
41 "module" option.
42
43 The application object can be accessed via $app or the "app" function.
44 A default configuration filename in the application home directory will
45 be generated from the value of "moniker" in Mojolicious
46 ("$moniker.yml"). You can extend the normal configuration file
47 "$moniker.yml" with "mode" specific ones like "$moniker.$mode.yml",
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:
59 - SetUserGroup:
60 user: sri
61 group: staff
62
63 One or more deployment specific plugins that should be loaded right
64 after this plugin has been loaded.
65
66 The code of this plugin is a good example for learning to build new
67 plugins, you're welcome to fork it.
68
69 See "PLUGINS" in Mojolicious::Plugins for a list of plugins that are
70 available by default.
71
73 Mojolicious::Plugin::NotYAMLConfig inherits all options from
74 Mojolicious::Plugin::JSONConfig and supports the following new ones.
75
76 module
77 # Mojolicious::Lite
78 plugin NotYAMLConfig => {module => 'YAML::PP'};
79
80 Alternative YAML module to use for parsing.
81
83 Mojolicious::Plugin::NotYAMLConfig inherits all methods from
84 Mojolicious::Plugin::JSONConfig and implements the following new ones.
85
86 parse
87 $plugin->parse($content, $file, $conf, $app);
88
89 Process content with "render" in Mojolicious::Plugin::JSONConfig and
90 parse it with CPAN::Meta::YAML.
91
92 sub parse ($self, $content, $file, $conf, $app) {
93 ...
94 $content = $self->render($content, $file, $conf, $app);
95 ...
96 return $hash;
97 }
98
99 register
100 my $config = $plugin->register(Mojolicious->new);
101 my $config = $plugin->register(Mojolicious->new, {file => '/etc/foo.conf'});
102
103 Register plugin in Mojolicious application and merge configuration.
104
106 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
107
108
109
110perl v5.34.0 2021-07-M2o2jolicious::Plugin::NotYAMLConfig(3)