.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" 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 turned on, 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Config::Onion 3pm" .TH Config::Onion 3pm "2014-05-09" "perl v5.18.2" "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" Config::Onion \- Layered configuration, because configs are like ogres .SH "VERSION" .IX Header "VERSION" version 1.004 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& my $cfg = Config::Onion\->new; \& my $cfg = Config::Onion\->set_default(db => {name => \*(Aqfoo\*(Aq, password => \*(Aqbar\*(Aq}); \& my $cfg = Config::Onion\->load(\*(Aq/etc/myapp\*(Aq, \*(Aq./myapp\*(Aq); \& my $cfg = Config::Onion\->load_glob(\*(Aq./plugins/*\*(Aq); \& \& $cfg\->set_default(font => \*(AqComic Sans\*(Aq); \& $cfg\->load(\*(Aqconfig\*(Aq); \& $cfg\->load_glob(\*(Aqconf.d/myapp*\*(Aq); \& $cfg\->set_override(font => \*(AqArial\*(Aq); \& \& my $dbname = $cfg\->get\->{db}{name}; \& my $plain_hashref_conf = $cfg\->get; \& my $dbpassword = $plain_hashref_conf\->{db}{password}; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" All too often, configuration is not a universal or one-time thing, yet most configuration-handling treats it as such. Perhaps you can only load one config file. If you can load more than one, you often have to load all of them at the same time or each is stored completely independently, preventing one from being able to override another. Config::Onion changes that. .PP Config::Onion stores all configuration settings in four layers: Defaults, Main, Local, and Override. Each layer can be added to as many times as you like. Within each layer, settings which are given multiple times will take the last specified value, while those which are not repeated will remain untouched. .PP .Vb 4 \& $cfg\->set_default(name => \*(AqArthur Dent\*(Aq, location => \*(AqEarth\*(Aq); \& $cfg\->set_default(location => \*(AqMagrathea\*(Aq); \& # In the Default layer, \*(Aqname\*(Aq is still \*(AqArthur Dent\*(Aq, but \*(Aqlocation\*(Aq has \& # been changed to \*(AqMagrathea\*(Aq. .Ve .PP Regardless of the order in which they are set, values in Main will always override values in the Default layer, the Local layer always overrides both Default and Main, and the Override layer overrides all the others. .PP The design intent for each layer is: .IP "\(bu" 4 Default .Sp Hardcoded default values to be used when no further configuration is present .IP "\(bu" 4 Main .Sp Values loaded from standard configuration files shipped with the application .IP "\(bu" 4 Local .Sp Values loaded from local configuration files which are kept separate to prevent them from being overwritten by application upgrades, etc. .IP "\(bu" 4 Override .Sp Settings provided at run-time which take precendence over all configuration files, such as settings provided via command line switches .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Returns a new, empty configuration object. .SS "load(@file_stems)" .IX Subsection "load(@file_stems)" Loads files matching the given stems using \f(CW\*(C`Config::Any\->load_stems\*(C'\fR into the Main layer. Also concatenates \*(L".local\*(R" to each stem and loads matching files into the Local layer. e.g., \f(CW\*(C`$cfg\->load(\*(Aqmyapp\*(Aq)\*(C'\fR would load \&\f(CW\*(C`myapp.yml\*(C'\fR into Main and \f(CW\*(C`myapp.local.js\*(C'\fR into Local. All filename extensions supported by \f(CW\*(C`Config::Any\*(C'\fR are recognized along with their corresponding formats. .SS "load_glob(@globs)" .IX Subsection "load_glob(@globs)" Uses the Perl \f(CW\*(C`glob\*(C'\fR function to expand each parameter into a list of filenames and loads each file using \f(CW\*(C`Config::Any\*(C'\fR. Files whose names contain the string \*(L".local.\*(R" are loaded into the Local layer. All other files are loaded into the Main layer. .ie n .SS "set_default([\e%settings,...,] %settings)" .el .SS "set_default([\e%settings,...,] \f(CW%settings\fP)" .IX Subsection "set_default([%settings,...,] %settings)" .ie n .SS "set_override([\e%settings,...,] %settings)" .el .SS "set_override([\e%settings,...,] \f(CW%settings\fP)" .IX Subsection "set_override([%settings,...,] %settings)" Imports \f(CW%settings\fR into the Default or Override layer. Accepts settings both as a plain hash and as hash references, but, if the two are mixed, all hash references must appear at the beginning of the parameter list, before any non-hashref settings. .SH "PROPERTIES" .IX Header "PROPERTIES" .SS "cfg" .IX Subsection "cfg" .SS "get" .IX Subsection "get" Returns the complete configuration as a hash reference. .SS "default" .IX Subsection "default" .SS "main" .IX Subsection "main" .SS "local" .IX Subsection "local" .SS "override" .IX Subsection "override" These properties each return a single layer of the configuration. This is not likely to be useful other than for debugging. For most other purposes, you probably want to use \f(CW\*(C`get\*(C'\fR instead. .SS "prefix_key" .IX Subsection "prefix_key" If set, enables the Prefix Structures functionality described below when using the \f(CW\*(C`load\*(C'\fR or \f(CW\*(C`load_glob\*(C'\fR methods. The value of \f(CW\*(C`prefix_key\*(C'\fR specifies the name of the key under which the prefix structure may be found. .PP Default value is \f(CW\*(C`undef\*(C'\fR. .SH "Prefix Structures" .IX Header "Prefix Structures" If you find that your configuration structure is becoming unwieldy due to deeply-nested structures, you can define a file-specific \*(L"prefix structure\*(R" and all other settings within that file will be loaded as children of the prefix structure. For example, if your main program uses .PP .Vb 2 \& $cfg = Config::Onion\->new(prefix_key => \*(Aq_prefix\*(Aq); \& $cfg\->load("myapp/config"); .Ve .PP and \f(CW\*(C`myapp/config.yml\*(C'\fR contains .PP .Vb 3 \& _prefix: \& foo: \& bar: \& \& baz: 1 .Ve .PP then \f(CW$cfg\fR will contain the configuration .PP .Vb 3 \& foo: \& bar: \& baz: 1 .Ve .PP Note that the top-level \f(CW\*(C`prefix_key\*(C'\fR is removed. .PP There are some limitations on the prefix structure, in order to keep it sane and deterministic. First, the prefix structure may only contain hashes. Second, each hash must contain exactly one key. Finally, the value associated with the final key must be left undefined. .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" No bugs have been reported. .PP Please report any bugs or feature requests at .SH "AUTHOR" .IX Header "AUTHOR" Dave Sherohman .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2014 by Lund University Library. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.