Mojolicious::Plugin::INIConfig - Mojolicious Plugin to create routes automatically
This module is alpha release. the feature will be changed without warnings.
# 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.
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; }
If a feature is DEPRECATED, you can know it by DEPRECATED warnings. DEPRECATED feature is removed after five years, but if at least one person use the feature and tell me that thing I extend one year each time he tell me it.
five years
DEPRECATION warnings can be suppressed by MOJOLICIOUS_PLUGIN_INICONFIG_SUPPRESS_DEPRECATION environment variable.
MOJOLICIOUS_PLUGIN_INICONFIG_SUPPRESS_DEPRECATION
EXPERIMENTAL features will be changed without warnings.
Please tell me bugs if you find bug.
<kimoto.yuki at gmail.com>
http://github.com/yuki-kimoto/Mojolicious-Plugin-INIConfig
Copyright 2013-2013 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.