NAME

Mojolicious::Plugin::INIConfig - Mojolicious Plugin to create routes automatically

CAUTION =head1 NAME

Mojolicious::Plugin::INIConfig - INI configuration plugin

SYNOPSIS

# 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'};

DESCRIPTION

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.

The code of this plugin is a good example for learning to build new plugins, you're welcome to fork it.

OPTIONS

Mojolicious::Plugin::INIConfig inherits all options from Mojolicious::Plugin::Config and supports the following new ones.

default

# Mojolicious::Lite
plugin Config => {default => {section => {foo => 'bar'}}};

Default configuration, making configuration files optional.

template

# Mojolicious::Lite
plugin INIConfig => {template => {line_start => '.'}};

Attribute values passed to Mojo::Template object used to preprocess configuration files.

METHODS

Mojolicious::Plugin::INIConfig inherits all methods from Mojolicious::Plugin::Config and implements the following new ones.

parse

$plugin->parse($content, $file, $conf, $app);

Process content with render and parse it with Config::Tiny.

sub parse {
  my ($self, $content, $file, $conf, $app) = @_;
  ...
  $content = $self->render($content, $file, $conf, $app);
  ...
  return $hash;
}

register

my $config = $plugin->register(Mojolicious->new);
my $config = $plugin->register(Mojolicious->new, {file => '/etc/foo.conf'});

Register plugin in Mojolicious application.

render

$plugin->render($content, $file, $conf, $app);

Process configuration file with Mojo::Template.

sub render {
  my ($self, $content, $file, $conf, $app) = @_;
  ...
  return $content;
}

BACKWARDS COMPATIBILITY POLICY

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.

DEPRECATION warnings can be suppressed by MOJOLICIOUS_PLUGIN_INICONFIG_DEPRECATION environment variable.

EXPERIMENTAL features will be changed without warnings.

BUGS

Please tell me bugs if you find bug.

<kimoto.yuki at gmail.com>

http://github.com/yuki-kimoto/Mojolicious-Plugin-INIConfig

COPYRIGHT & LICENSE

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.