The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojolicious::Plugin::INIConfig - Mojolicious plugin to load INI format config file

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.

If the configuration value config_override has been set in "config" in Mojo when this plugin is loaded, it will not do anything.

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

OP

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-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.