Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages
Catalyst::Plugin::ConfigLoader::Environment(3) User Contributed Perl Documentation Catalyst::Plugin::ConfigLoader::Environment(3)

Catalyst::Plugin::ConfigLoader::Environment - Configure your application with environment variables.

Version 0.05

Catalyst::Plugin::ConfigLoader::Environment reads environment variables and sets up the configuration in your application accordingly.

Here's how you use it:

    package MyApp;
    use Catalyst qw(... ConfigLoader::Environment ...);

Then, before you run your application, set some environment variables:

    export MYAPP_foo='Hello, world!'
    export MYAPP_bar="foobar"
    perl script/

Inside your application, "$c->config->{foo}" will be equal to "Hello, world!", and "$c->config->{bar}" will be equal to "foobar".

You can use both ConfigLoader and this module in the same application. If you specify "ConfigLoader" before "ConfigLoader::Environment" in the import list to Catalyst, the environment will override any configuration files that ConfigLoader may find. This is the recommended setup.

You can reverse the order in the import list if you want static config files to override the environment, but that's not recommended.

Here's exactly how environment variables are translated into configuration.

First, your application's name is converted to ALL CAPS, any colons are converted to underscores (i.e. "My::App" is translated to "MY_APP"), and a "_" is appended. Then, any environment variables not starting with this prefix are discarded.

The prefix is then stripped, and the remaining variables are then converted to elements in the "config" hash as follows.

Variables starting with "Model::", "View::", or "Controller::" and then any character other than "_" are treated as configuration options for the corresponding component of your application. The prefix is saved as "prefix" and everything after the first "_" is used as a key into the "$c->config->{"prefix"}" hash.

Any other variables not starting with a special prefix are added directly to the "$c->config" hash.

Let's translate a YAML config file:

    name: MyApp
    title: This is My App!
      EXTENSION: tt
      EVAL_PERL: 1
      root: "/etc"
      connect_info: [ "dbi:Pg:dbname=foo", "username", "password" ]

into environment variables that would setup the same configuration:

    MYAPP_title=This is My App!
    MYAPP_Model__DBIC_connect_info=["dbi:Pg:dbname=foo", "username", "password"]

Double colons are converted into double underscores. For compatibility's sake, support for the 0.01-style use of bourne-incompatible variable names is retained.

Values are JSON-decoded if they look like JSON arrays or objects (i.e. if they're enclosed in []s or {}s). Taking advantage of that, we can write the same example this way:

    MYAPP_title=This is My App!
    MYAPP_Model__DBIC={"connect_info":["dbi:Pg:dbname=foo", "username", "password"]}

Overriding Catalyst' setup routine.

Jonathan Rockway, "<jrockway at>"


Ryan D Johnson, "<ryan at>"

Devin J. Austin "<>"

Please report any bugs or feature requests to "bug-catalyst-plugin-configloader-environment at", or through the web interface at <>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

You can find documentation for this module with the perldoc command.

    perldoc Catalyst::Plugin::ConfigLoader::Environment

You can also look for information at:

  • Catalyst Mailing List


  • RT: CPAN's request tracker


Copyright 2006 Jonathan Rockway, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

If you'd like to use it under a different license, that's probably OK. Please contact the author.

2010-06-05 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.