Mojolicious::Plugin::INIConfig - Mojolicious plugin to load INI format config file
# myapp.ini [section] foo=bar music_dir=<%= app->home->rel_dir('music') %> # Mojolicious my $config = $self->plugin('INIConfig'); # Mojolicious::Lite my $config = plugin 'INIConfig'; # foo.html.ep %= $config->{section}{foo} # The configuration is available application wide my $config = app->config; # Everything can be customized with options my $config = plugin INIConfig => {file => '/etc/myapp.conf'};
Mojolicious::Plugin::INIConfig is a INI configuration plugin that preprocesses its input with Mojo::Template.
The application object can be accessed via $app or the app function. You can extend the normal config file myapp.ini with mode specific ones like myapp.$mode.ini. A default configuration filename will be generated from the value of "moniker" in Mojolicious.
$app
app
myapp.ini
mode
myapp.$mode.ini
The code of this plugin is a good example for learning to build new plugins, you're welcome to fork it.
If the configuration value config_override has been set in "config" in Mojo when this plugin is loaded, it will not do anything.
config_override
Mojolicious::Plugin::INIConfig inherits all options from Mojolicious::Plugin::Config and supports the following new ones.
# Mojolicious::Lite plugin Config => {default => {section => {foo => 'bar'}}};
Default configuration, making configuration files optional.
# Mojolicious::Lite plugin INIConfig => {template => {line_start => '.'}};
Attribute values passed to Mojo::Template object used to preprocess configuration files.
Mojolicious::Plugin::INIConfig inherits all methods from Mojolicious::Plugin::Config and implements the following new ones.
$plugin->parse($content, $file, $conf, $app);
Process content with render and parse it with Config::Tiny.
render
sub parse { my ($self, $content, $file, $conf, $app) = @_; ... $content = $self->render($content, $file, $conf, $app); ... return $hash; }
my $config = $plugin->register(Mojolicious->new); my $config = $plugin->register(Mojolicious->new, {file => '/etc/foo.conf'});
Register plugin in Mojolicious application.
$plugin->render($content, $file, $conf, $app);
Process configuration file with Mojo::Template.
sub render { my ($self, $content, $file, $conf, $app) = @_; ... return $content; }
Please tell me bugs if you find bug.
<kimoto.yuki at gmail.com>
http://github.com/yuki-kimoto/Mojolicious-Plugin-INIConfig
Copyright 2013-2017 Yuki Kimoto, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Mojolicious::Plugin::INIConfig, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::INIConfig
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::INIConfig
For more information on module installation, please visit the detailed CPAN module installation guide.