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 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
60 Mojolicious::Plugin::NotYAMLConfig inherits all options from
61 Mojolicious::Plugin::JSONConfig and supports the following new ones.
62
63 module
64 # Mojolicious::Lite
65 plugin NotYAMLConfig => {module => 'YAML::PP'};
66
67 Alternative YAML module to use for parsing.
68
70 Mojolicious::Plugin::NotYAMLConfig inherits all methods from
71 Mojolicious::Plugin::JSONConfig and implements the following new ones.
72
73 parse
74 $plugin->parse($content, $file, $conf, $app);
75
76 Process content with "render" in Mojolicious::Plugin::JSONConfig and
77 parse it with CPAN::Meta::YAML.
78
79 sub parse ($self, $content, $file, $conf, $app) {
80 ...
81 $content = $self->render($content, $file, $conf, $app);
82 ...
83 return $hash;
84 }
85
86 register
87 my $config = $plugin->register(Mojolicious->new);
88 my $config = $plugin->register(Mojolicious->new, {file => '/etc/foo.conf'});
89
90 Register plugin in Mojolicious application and merge configuration.
91
93 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
94
95
96
97perl v5.32.1 2021-02-M0o7jolicious::Plugin::NotYAMLConfig(3)