.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Catalyst::Plugin::ConfigLoader 3pm" .TH Catalyst::Plugin::ConfigLoader 3pm "2020-07-30" "perl v5.30.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Catalyst::Plugin::ConfigLoader \- Load config files of various types .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& package MyApp; \& \& # ConfigLoader should be first in your list so \& # other plugins can get the config information \& use Catalyst qw( ConfigLoader ... ); \& \& # by default myapp.* will be loaded \& # you can specify a file if you\*(Aqd like \& _\|_PACKAGE_\|_\->config( \*(AqPlugin::ConfigLoader\*(Aq => { file => \*(Aqconfig.yaml\*(Aq } ); .Ve .PP In the file, assuming it's in \s-1YAML\s0 format: .PP .Vb 1 \& foo: bar .Ve .PP Accessible through the context object, or the class itself .PP .Vb 2 \& $c\->config\->{foo} # bar \& MyApp\->config\->{foo} # bar .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module will attempt to load find and load a configuration file of various types. Currently it supports \s-1YAML, JSON, XML, INI\s0 and Perl formats. Special configuration for a particular driver format can be stored in \f(CW\*(C`MyApp\->config\->{ \*(AqPlugin::ConfigLoader\*(Aq }\->{ driver }\*(C'\fR. For example, to pass arguments to Config::General, use the following: .PP .Vb 5 \& _\|_PACKAGE_\|_\->config( \*(AqPlugin::ConfigLoader\*(Aq => { \& driver => { \& \*(AqGeneral\*(Aq => { \-LowerCaseNames => 1 } \& } \& } ); .Ve .PP See Config::Any's \f(CW\*(C`driver_args\*(C'\fR parameter for more information. .PP To support the distinction between development and production environments, this module will also attemp to load a local config (e.g. \fImyapp_local.yaml\fR) which will override any duplicate settings. See \&\*(L"get_config_local_suffix\*(R" for details on how this is configured. .SH "METHODS" .IX Header "METHODS" .SS "setup( )" .IX Subsection "setup( )" This method is automatically called by Catalyst's setup routine. It will attempt to use each plugin and, once a file has been successfully loaded, set the \f(CW\*(C`config()\*(C'\fR section. .SS "load_config" .IX Subsection "load_config" This method handles loading the configuration data into the Catalyst context object. It does not return a value. .SS "find_files" .IX Subsection "find_files" This method determines the potential file paths to be used for config loading. It returns an array of paths (up to the filename less the extension) to pass to Config::Any for loading. .SS "get_config_path" .IX Subsection "get_config_path" This method determines the path, filename prefix and file extension to be used for config loading. It returns the path (up to the filename less the extension) to check and the specific extension to use (if it was specified). .PP The order of preference is specified as: .IP "\(bu" 4 \&\f(CW$ENV{ MYAPP_CONFIG }\fR .IP "\(bu" 4 \&\f(CW$ENV{ CATALYST_CONFIG }\fR .IP "\(bu" 4 \&\f(CW\*(C`$c\->config\->{ \*(AqPlugin::ConfigLoader\*(Aq }\->{ file }\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`$c\->path_to( $application_prefix )\*(C'\fR .PP If either of the first two user-specified options are directories, the application prefix will be added on to the end of the path. .SS "get_config_local_suffix" .IX Subsection "get_config_local_suffix" Determines the suffix of files used to override the main config. By default this value is \f(CW\*(C`local\*(C'\fR, which will load \f(CW\*(C`myapp_local.conf\*(C'\fR. The suffix can be specified in the following order of preference: .IP "\(bu" 4 \&\f(CW$ENV{ MYAPP_CONFIG_LOCAL_SUFFIX }\fR .IP "\(bu" 4 \&\f(CW$ENV{ CATALYST_CONFIG_LOCAL_SUFFIX }\fR .IP "\(bu" 4 \&\f(CW\*(C`$c\->config\->{ \*(AqPlugin::ConfigLoader\*(Aq }\->{ config_local_suffix }\*(C'\fR .PP The first one of these values found replaces the default of \f(CW\*(C`local\*(C'\fR in the name of the local config file to be loaded. .PP For example, if \f(CW $ENV{ MYAPP_CONFIG_LOCAL_SUFFIX }\fR is set to \f(CW\*(C`testing\*(C'\fR, ConfigLoader will try and load \fImyapp_testing.conf\fR instead of \&\fImyapp_local.conf\fR. .SS "finalize_config" .IX Subsection "finalize_config" This method is called after the config file is loaded. It can be used to implement tuning of config values that can only be done at runtime. If you need to do this to properly configure any plugins, it's important to load ConfigLoader before them. ConfigLoader provides a default \f(CW\*(C`finalize_config\*(C'\fR method which walks through the loaded config hash and calls the config_substitutions method on any string. .ie n .SS "config_substitutions( $value )" .el .SS "config_substitutions( \f(CW$value\fP )" .IX Subsection "config_substitutions( $value )" This method substitutes macros found with calls to a function. There are a number of default macros: .IP "\(bu" 4 \&\f(CW\*(C`_\|_HOME_\|_\*(C'\fR \- replaced with \f(CW\*(C`$c\->path_to(\*(Aq\*(Aq)\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`_\|_ENV(foo)_\|_\*(C'\fR \- replaced with the value of \f(CW$ENV{foo}\fR .IP "\(bu" 4 \&\f(CW\*(C`_\|_path_to(foo/bar)_\|_\*(C'\fR \- replaced with \f(CW\*(C`$c\->path_to(\*(Aqfoo/bar\*(Aq)\*(C'\fR .IP "\(bu" 4 \&\f(CW\*(C`_\|_literal(_\|_FOO_\|_)_\|_\*(C'\fR \- leaves _\|_FOO_\|_ alone (allows you to use \&\f(CW\*(C`_\|_DATA_\|_\*(C'\fR as a config value, for example) .PP The parameter list is split on comma (\f(CW\*(C`,\*(C'\fR). You can override this method to do your own string munging, or you can define your own macros in \&\f(CW\*(C`MyApp\->config\->{ \*(AqPlugin::ConfigLoader\*(Aq }\->{ substitutions }\*(C'\fR. Example: .PP .Vb 3 \& MyApp\->config\->{ \*(AqPlugin::ConfigLoader\*(Aq }\->{ substitutions } = { \& baz => sub { my $c = shift; qux( @_ ); } \& } .Ve .PP The above will respond to \f(CW\*(C`_\|_baz(x,y)_\|_\*(C'\fR in config strings. .SH "AUTHOR" .IX Header "AUTHOR" Brian Cassidy .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" The following people have generously donated their time to the development of this module: .IP "\(bu" 4 Joel Bernstein \- Rewrite to use Config::Any .IP "\(bu" 4 David Kamholz \- Data::Visitor integration .IP "\(bu" 4 Stuart Watt \- Addition of \s-1ENV\s0 macro. .PP Work to this module has been generously sponsored by: .IP "\(bu" 4 Portugal Telecom \- Work done by Joel Bernstein .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2006\-2010 by Brian Cassidy .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Catalyst .IP "\(bu" 4 Catalyst::Plugin::ConfigLoader::Manual .IP "\(bu" 4 Config::Any