.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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 "Config::YAML 3pm" .TH Config::YAML 3pm "2021-01-03" "perl v5.32.0" "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::YAML \- Simple configuration automation .SH "VERSION" .IX Header "VERSION" Version 1.42 .SH "SYNOPSIS" .IX Header "SYNOPSIS" Config::YAML is a somewhat object-oriented wrapper around the \s-1YAML\s0 module which makes reading and writing configuration files simple. Handling multiple config files (e.g. system and per-user configuration, or a gallery app with per-directory configuration) is a snap. .PP .Vb 1 \& use Config::YAML; \& \& # create Config::YAML object with any desired initial options \& # parameters; load system config; set alternate output file \& my $c = Config::YAML\->new( config => "/usr/share/foo/globalconf", \& output => "~/.foorc", \& param1 => value1, \& param2 => value2, \& ... \& paramN => valueN, \& ); \& \& # integrate user\*(Aqs own config \& $c\->read("~/.foorc"); \& \& # integrate command line args using Getopt::Long \& $rc = GetOptions ( $c, \& \*(Aqparam1|p!\*(Aq, \& \*(Aqparam2|P\*(Aq, \& \*(AqparamN|n\*(Aq, \& ); \& \& # Write configuration state to disk \& $c\->write; \& \& # simply get params back for use... \& do_something() unless $c\->{param1}; \& # or get them more OO\-ly if that makes you feel better \& my $value = $c\->get_param2; .Ve .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" Creates a new Config::YAML object. .PP .Vb 3 \& my $c = Config::YAML\->new( config => initial_config, \& output => output_config \& ); .Ve .PP The \f(CW\*(C`config\*(C'\fR parameter specifies the file to be read in during object creation. It is required, and must be the first parameter given. If the second parameter is \f(CW\*(C`output\*(C'\fR, then it is used to specify the file to which configuration data will later be written out. This positional dependency makes it possible to have parameters named \&\*(L"config\*(R" and/or \*(L"output\*(R" in config files. .PP Initial configuration values can be passed as subsequent parameters to the constructor: .PP .Vb 5 \& my $c = Config::YAML\->new( config => "~/.foorc", \& foo => "abc", \& bar => "xyz", \& baz => [ 1, 2, 3 ], \& ); .Ve .SS "get_*/set_*" .IX Subsection "get_*/set_*" If you'd prefer not to directly molest the object to store and retrieve configuration data, autoloading methods of the forms \&\f(CW\*(C`get_[param]\*(C'\fR and \f(CW\*(C`set_[param]\*(C'\fR are provided. Continuing from the previous example: .PP .Vb 2 \& print $c\->get_foo; # prints "abc" \& my $val = $c\->get_quux; # $c\->{quux} doesn\*(Aqt exist; returns undef \& \& $c\->set_bar(30); # $c\->{bar} now equals 30, not "xyz" \& my @list = qw(alpha beta gamma); \& $c\->set_baz(\e@list); # $c\->{baz} now a reference to @list .Ve .SS "fold" .IX Subsection "fold" Convenience method for folding multiple values into the config object at once. Requires a hashref as its argument. .PP .Vb 3 \& $prefs{theme} = param(theme); \& $prefs{format} = param(format); \& $prefs{sortby} = param(order); \& \& $c\->fold(\e%prefs); \& \& my $format = $c\->get_format; # value matches that of param(format) .Ve .SS "read" .IX Subsection "read" Imports a YAML-formatted config file. .PP .Vb 1 \& $c\->read(\*(Aq/usr/share/fooapp/fooconf\*(Aq); .Ve .PP \&\f(CW\*(C`read()\*(C'\fR is called at object creation and imports the file specified by \f(CW\*(C`new(config=>)\*(C'\fR, so there is no need to call it manually unless multiple config files exist. .SS "write" .IX Subsection "write" Dump current configuration state to a YAML-formatted flat file. .PP .Vb 1 \& $c\->write; .Ve .PP The file to be written is specified in the constructor call. See the \&\f(CW\*(C`new\*(C'\fR method documentation for details. .SH "DEPRECATED METHODS" .IX Header "DEPRECATED METHODS" These methods have been superseded and will likely be removed in the next release. .SS "get" .IX Subsection "get" Returns the value of a parameter. .PP .Vb 1 \& print $c\->get(\*(Aqfoo\*(Aq); .Ve .SS "set" .IX Subsection "set" Sets the value of a parameter: .PP .Vb 1 \& $c\->set(\*(Aqfoo\*(Aq,1); \& \& my @paints = qw( oil acrylic tempera ); \& $c\->set(\*(Aqpaints\*(Aq, \e@paints); .Ve .SH "AUTHOR" .IX Header "AUTHOR" Shawn Boyette (\f(CW\*(C`\*(C'\fR) .PP Original implementation by Kirrily \*(L"Skud\*(R" Robert (as \&\f(CW\*(C`YAML::ConfigFile\*(C'\fR). .SH "BUGS" .IX Header "BUGS" .IP "\(bu" 4 Config::YAML ignores the \s-1YAML\s0 document separation string (\f(CW\*(C`\-\-\-\*(C'\fR) because it has no concept of multiple targets for the data coming from a config file. .PP Please report any bugs or feature requests to \&\f(CW\*(C`bug\-yaml\-configfile@rt.cpan.org\*(C'\fR, 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. .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2004 Shawn Boyette, All Rights Reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.