.\" 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::Tiny 3pm" .TH Config::Tiny 3pm "2014-02-02" "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::Tiny \- Read/Write .ini style files with as little code as possible .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& # In your configuration file \& rootproperty=blah \& \& [section] \& one=twp \& three= four \& Foo =Bar \& empty= \& \& # In your program \& use Config::Tiny; \& \& # Create a config \& my $Config = Config::Tiny\->new; \& \& # Open the config \& $Config = Config::Tiny\->read( \*(Aqfile.conf\*(Aq ); \& $Config = Config::Tiny\->read( \*(Aqfile.conf\*(Aq, \*(Aqutf8\*(Aq ); # Neither \*(Aq:\*(Aq nor \*(Aq<:\*(Aq prefix! \& $Config = Config::Tiny\->read( \*(Aqfile.conf\*(Aq, \*(Aqencoding(iso\-8859\-1)\*(Aq); \& \& # Reading properties \& my $rootproperty = $Config\->{_}\->{rootproperty}; \& my $one = $Config\->{section}\->{one}; \& my $Foo = $Config\->{section}\->{Foo}; \& \& # Changing data \& $Config\->{newsection} = { this => \*(Aqthat\*(Aq }; # Add a section \& $Config\->{section}\->{Foo} = \*(AqNot Bar!\*(Aq; # Change a value \& delete $Config\->{_}; # Delete a value or section \& \& # Save a config \& $Config\->write( \*(Aqfile.conf\*(Aq ); \& $Config\->write( \*(Aqfile.conf\*(Aq, \*(Aqutf8\*(Aq ); # Neither \*(Aq:\*(Aq nor \*(Aq>:\*(Aq prefix! \& \& # Shortcuts \& my($rootproperty) = $$Config{_}{rootproperty}; \& \& my($config) = Config::Tiny \-> read_string(\*(Aqalpha=bet\*(Aq); \& my($value) = $$config{_}{alpha}; # $value is \*(Aqbet\*(Aq. \& \& my($config) = Config::Tiny \-> read_string("[init]\enalpha=bet"); \& my($value) = $$config{init}{alpha}; # $value is \*(Aqbet\*(Aq. .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Config::Tiny\*(C'\fR is a Perl class to read and write .ini style configuration files with as little code as possible, reducing load time and memory overhead. .PP Most of the time it is accepted that Perl applications use a lot of memory and modules. .PP The \f(CW*::Tiny\fR family of modules is specifically intended to provide an ultralight alternative to the standard modules. .PP This module is primarily for reading human written files, and anything we write shouldn't need to have documentation/comments. If you need something with more power move up to Config::Simple, Config::General or one of the many other \f(CW\*(C`Config::*\*(C'\fR modules. .PP Lastly, Config::Tiny does \fBnot\fR preserve your comments, whitespace, or the order of your config file. .PP See Config::Tiny::Ordered (and possibly others) for the preservation of the order of the entries in the file. .SH "CONFIGURATION FILE SYNTAX" .IX Header "CONFIGURATION FILE SYNTAX" Files are the same format as for \s-1MS\s0 Windows \f(CW\*(C`*.ini\*(C'\fR files. For example: .PP .Vb 3 \& [section] \& var1=value1 \& var2=value2 .Ve .PP If a property is outside of a section at the beginning of a file, it will be assigned to the \f(CW"root section"\fR, available at \f(CW\*(C`$Config\->{_}\*(C'\fR. .PP Lines starting with \f(CW\*(Aq#\*(Aq\fR or \f(CW\*(Aq;\*(Aq\fR are considered comments and ignored, as are blank lines. .PP When writing back to the config file, all comments, custom whitespace, and the ordering of your config file elements is discarded. If you need to keep the human elements of a config when writing back, upgrade to something better, this module is not for you. .SH "METHODS" .IX Header "METHODS" .SS "\fIerrstr()\fP" .IX Subsection "errstr()" Returns a string representing the most recent error, or the empty string. .PP You can also retrieve the error message from the \f(CW$Config::Tiny::errstr\fR variable. .SS "\fInew()\fP" .IX Subsection "new()" The constructor \f(CW\*(C`new\*(C'\fR creates and returns an empty \f(CW\*(C`Config::Tiny\*(C'\fR object. .SS "read($filename, [$encoding])" .IX Subsection "read($filename, [$encoding])" Here, the [] indicate an optional parameter. .PP The \f(CW\*(C`read\*(C'\fR constructor reads a config file, \f(CW$filename\fR, and returns a new \&\f(CW\*(C`Config::Tiny\*(C'\fR object containing the properties in the file. .PP \&\f(CW$encoding\fR may be used to indicate the encoding of the file, e.g. 'utf8' or 'encoding(iso\-8859\-1)'. .PP Do not add a prefix to \f(CW$encoding\fR, such as '<' or '<:'. .PP Returns the object on success, or \f(CW\*(C`undef\*(C'\fR on error. .PP When \f(CW\*(C`read\*(C'\fR fails, \f(CW\*(C`Config::Tiny\*(C'\fR sets an error message internally you can recover via \f(CW\*(C`Config::Tiny\->errstr\*(C'\fR. Although in \fBsome\fR cases a failed \f(CW\*(C`read\*(C'\fR will also set the operating system error variable \f(CW$!\fR, not all errors do and you should not rely on using the \f(CW$!\fR variable. .PP See t/04.utf8.t and t/04.utf8.txt. .SS "read_string($string)" .IX Subsection "read_string($string)" The \f(CW\*(C`read_string\*(C'\fR method takes as argument the contents of a config file as a string and returns the \f(CW\*(C`Config::Tiny\*(C'\fR object for it. .SS "write($filename, [$encoding])" .IX Subsection "write($filename, [$encoding])" Here, the [] indicate an optional parameter. .PP The \f(CW\*(C`write\*(C'\fR method generates the file content for the properties, and writes it to disk to the filename specified. .PP \&\f(CW$encoding\fR may be used to indicate the encoding of the file, e.g. 'utf8' or 'encoding(iso\-8859\-1)'. .PP Do not add a prefix to \f(CW$encoding\fR, such as '>' or '>:'. .PP Returns true on success or \f(CW\*(C`undef\*(C'\fR on error. .PP See t/04.utf8.t and t/04.utf8.txt. .SS "\fIwrite_string()\fP" .IX Subsection "write_string()" Generates the file content for the object and returns it as a string. .SH "FAQ" .IX Header "FAQ" .SS "Why can't I put comments at the ends of lines?" .IX Subsection "Why can't I put comments at the ends of lines?" Because a line like: .PP .Vb 1 \& key=value # A comment .Ve .PP Sets key to 'value # A comment' :\-(. .PP This conforms to the syntax discussed in \*(L"\s-1CONFIGURATION FILE SYNTAX\*(R"\s0. .SS "Why can't I omit the '=' signs?" .IX Subsection "Why can't I omit the '=' signs?" E.g.: .PP .Vb 5 \& [Things] \& my = \& list = \& of = \& things = .Ve .PP Instead of: .PP .Vb 5 \& [Things] \& my \& list \& of \& things .Ve .PP Because the use of '=' signs is a type of mandatory documentation. It indicates that that section contains 4 items, and not 1 odd item split over 4 lines. .SS "Why do I have to assign the result of a method call to a variable?" .IX Subsection "Why do I have to assign the result of a method call to a variable?" This question comes from RT#85386. .PP Yes, the syntax may seem odd, but you don't have to call both \fInew()\fR and \fIread_string()\fR. .PP Try: .PP .Vb 1 \& perl \-MData::Dumper \-MConfig::Tiny \-E \*(Aqmy $c=Config::Tiny\->read_string("one=s"); say Dumper $c\*(Aq .Ve .PP Or: .PP .Vb 2 \& my($config) = Config::Tiny \-> read_string(\*(Aqalpha=bet\*(Aq); \& my($value) = $$config{_}{alpha}; # $value is \*(Aqbet\*(Aq. .Ve .PP Or even, a bit ridiculously: .PP .Vb 1 \& my($value) = ${Config::Tiny \-> read_string(\*(Aqalpha=bet\*(Aq)}{_}{alpha}; # $value is \*(Aqbet\*(Aq. .Ve .SH "CAVEATS" .IX Header "CAVEATS" .SS "Unsupported Section Headers" .IX Subsection "Unsupported Section Headers" Some edge cases in section headers are not supported, and additionally may not be detected when writing the config file. .PP Specifically, section headers with leading whitespace, trailing whitespace, or newlines anywhere in the section header, will not be written correctly to the file and may cause file corruption. .SS "Setting an option more than once" .IX Subsection "Setting an option more than once" \&\f(CW\*(C`Config::Tiny\*(C'\fR will only recognize the first time an option is set in a config file. Any further attempts to set the same option later in the config file are ignored. .SH "SUPPORT" .IX Header "SUPPORT" Bugs should be reported via the \s-1CPAN\s0 bug tracker at .PP .PP For other issues, or commercial enhancement or support, contact the author. .SH "AUTHOR" .IX Header "AUTHOR" Adam Kennedy .PP Maintanence from V 2.15: Ron Savage . .SH "ACKNOWLEGEMENTS" .IX Header "ACKNOWLEGEMENTS" Thanks to Sherzod Ruzmetov for Config::Simple, which inspired this module by being not quite \&\*(L"simple\*(R" enough for me :). .SH "SEE ALSO" .IX Header "SEE ALSO" See, amongst many: Config::Simple and Config::General. .PP See Config::Tiny::Ordered (and possibly others) for the preservation of the order of the entries in the file. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2002 \- 2011 Adam Kennedy. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the \&\s-1LICENSE\s0 file included with this module.