Nic Sandfield > Mojar-1.062 > Mojar::Config

Download:
Mojar-1.062.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.002   Source   Latest Release: Mojar-2.001

NAME ^

Mojar::Config - Perl-ish configuration utility for standalone code

SYNOPSIS ^

  use Mojar::Config;
  my $config = Mojar::Config->load('cfg/defaults.conf');
  say $config->{redis}{ip};

DESCRIPTION ^

A simple configuration file reader for a configuration written as a perl hash.

USAGE ^

  # cfg/defaults.conf
  {
    debug => undef,
    expiration => 60 * 60 * 10,
    secrets => [qw(where wild things roam)],
    redis => {
      ip => '192.168.1.1',
      port => 6379
    }
  }

The contents are evaluated, so compuatations are valid.

METHODS ^

load

  $hashref = Mojar::Config->load('path/to/file.conf');
  $hashref = Mojar::Config->load('path/to/file.conf', $log);

Loads a perl-ish configuration from the given file path. In normal usage, this is the only method required. The result is a plain (unblessed) hashref.

parse

  $content = '{ testing => 2 * 2 }';
  $config = Mojar::Config->parse(\$content);
  say $config->{testing};

Does the actual parsing of the configuration, being passed a ref to the configuration text.

DEBUGGING ^

Both methods accept a Mojar::Log/Mojo::Log object as their final argument. If passed a debug-level logger, some debugging statements become available.

  my $log = Mojar::Log->new(level => 'debug', path => '/tmp/stuff.log');
  my $config = Mojar::Config->new->load('/etc/stuff.conf', $log);

SEE ALSO ^

This is a fork of Mojolicious::Plugin::Config (v3.57) that can be used independently of having a Mojolicious app. So if your code is for a Mojolicious app, it makes sense to use the upstream module instead.

syntax highlighting: