This module is offered as a convenience to the user, and is not used to configure PlackX::Framework directly.

It will load and parse the specific configuration file and make the resulting data structure available in a config() method/functino of your application's main class, and also a ::Config class.

IMPORT: This module does NOT export the config() function to the caller, but rather to your application's namespace! See the examples below for clarification!

Option one is to have PXF automatically generate your ::Config subclass.

Store your config filename in an environment variable, in accordance with the convention described below:

My::Web::App => $ENV{'MY_WEB_APP_CONFIG'}

or pass it in your use statement.

Example 1:

package My::WebApp {
  use PlackX::Framework qw(:config);
  use My::WebApp::Config '/path/to/config_file';

  my $some_value = config->{some_key};

  # May also be written as:
  #   My::WebApp->config
  #   My::WebApp::config()
  #   My::WebApp::Config->config
  #   My::WebApp::Config::config()
}

Alternatively, create an empty ::Config subclass. This technique must be used if you want to load your configuration before loading the rest of your app.

Example 2:

# You must create a subclass of PlackX::Framework::Config!
# It MUST be named [NameOfApp]::Config!

# My/WebApp/Config.pm:
package My::WebApp::Config {
  use parent 'PlackX::Framework::Config';
}

# My/WebApp.pm
package My::WebApp {
  use PlackX::Framework;
  use My::WebApp::Router;
  use Data::Dumper;
  route '/' => sub ($request, $response) {
    $response->print(Dumper config());
  }
}

# app.psgi
use My::WebApp::Config '/path/to/config_file';
use My::WebApp;

If the config file ends in .pl or if $ENV{MYAPP_CONFIG_TYPE} is set to 'PERL', or 'PL', this module will use perl to "do" the file and return a perl data structure; otherwise Config::Any will be loaded to attempt to parse the file based on its extension.

If you would like to write your own custom config-file parsing routine, override load_config() in your ::Config subclass, returning a reference to the perl data structure.

package My::WebApp::Config {
  use parent 'PlackX::Framework::Config';
  sub load_config ($class, @options) {
    my $fname = shift @options || $ENV{..};
    require My::Parser::Module;
    my $config = My::Parser::Module->parse($fname);
    return $config;
  }
}