1Config::Tiny(3)       User Contributed Perl Documentation      Config::Tiny(3)
2
3
4

NAME

6       Config::Tiny - Read/Write .ini style files with as little code as
7       possible
8

SYNOPSIS

10           # In your configuration file
11           rootproperty=blah
12
13           [section]
14           one=twp
15           three= four
16           Foo =Bar
17           empty=
18
19           # In your program
20           use Config::Tiny;
21
22           # Create a config
23           my $Config = Config::Tiny->new;
24
25           # Open the config
26           $Config = Config::Tiny->read( 'file.conf' );
27
28           # Reading properties
29           my $rootproperty = $Config->{_}->{rootproperty};
30           my $one = $Config->{section}->{one};
31           my $Foo = $Config->{section}->{Foo};
32
33           # Changing data
34           $Config->{newsection} = { this => 'that' }; # Add a section
35           $Config->{section}->{Foo} = 'Not Bar!';     # Change a value
36           delete $Config->{_};                        # Delete a value or section
37
38           # Save a config
39           $Config->write( 'file.conf' );
40

DESCRIPTION

42       "Config::Tiny" is a perl class to read and write .ini style
43       configuration files with as little code as possible, reducing load time
44       and memory overhead. Most of the time it is accepted that Perl
45       applications use a lot of memory and modules. The "::Tiny" family of
46       modules is specifically intended to provide an ultralight alternative
47       to the standard modules.
48
49       This module is primarily for reading human written files, and anything
50       we write shouldn't need to have documentation/comments. If you need
51       something with more power move up to Config::Simple, Config::General or
52       one of the many other "Config::" modules. To rephrase, Config::Tiny
53       does not preserve your comments, whitespace, or the order of your
54       config file.
55

CONFIGURATION FILE SYNTAX

57       Files are the same format as for windows .ini files. For example:
58
59               [section]
60               var1=value1
61               var2=value2
62
63       If a property is outside of a section at the beginning of a file, it
64       will be assigned to the "root section", available at "$Config->{_}".
65
66       Lines starting with '#' or ';' are considered comments and ignored, as
67       are blank lines.
68
69       When writing back to the config file, all comments, custom whitespace,
70       and the ordering of your config file elements is discarded. If you need
71       to keep the human elements of a config when writing back, upgrade to
72       something better, this module is not for you.
73

METHODS

75   new
76       The constructor "new" creates and returns an empty "Config::Tiny"
77       object.
78
79   read $filename
80       The "read" constructor reads a config file, and returns a new
81       "Config::Tiny" object containing the properties in the file.
82
83       Returns the object on success, or "undef" on error.
84
85       When "read" fails, "Config::Tiny" sets an error message internally you
86       can recover via "Config::Tiny->errstr". Although in some cases a failed
87       "read" will also set the operating system error variable $!, not all
88       errors do and you should not rely on using the $! variable.
89
90   read_string $string;
91       The "read_string" method takes as argument the contents of a config
92       file as a string and returns the "Config::Tiny" object for it.
93
94   write $filename
95       The "write" method generates the file content for the properties, and
96       writes it to disk to the filename specified.
97
98       Returns true on success or "undef" on error.
99
100   write_string
101       Generates the file content for the object and returns it as a string.
102
103   errstr
104       When an error occurs, you can retrieve the error message either from
105       the $Config::Tiny::errstr variable, or using the "errstr()" method.
106

CAVEATS

108   Unsupported Section Headers
109       Some edge cases in section headers are not support, and additionally
110       may not be detected when writing the config file.
111
112       Specifically, section headers with leading whitespace, trailing
113       whitespace, or newlines anywhere in the section header, will not be
114       written correctly to the file and may cause file corruption.
115

SUPPORT

117       Bugs should be reported via the CPAN bug tracker at
118
119       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Config-Tiny>
120
121       For other issues, or commercial enhancement or support, contact the
122       author.
123

AUTHOR

125       Adam Kennedy <adamk@cpan.org>
126

ACKNOWLEGEMENTS

128       Thanks to Sherzod Ruzmetov <sherzodr@cpan.org> for Config::Simple,
129       which inspired this module by being not quite "simple" enough for me :)
130

SEE ALSO

132       Config::Simple, Config::General, ali.as
133
135       Copyright 2002 - 2011 Adam Kennedy.
136
137       This program is free software; you can redistribute it and/or modify it
138       under the same terms as Perl itself.
139
140       The full text of the license can be found in the LICENSE file included
141       with this module.
142
143
144
145perl v5.16.3                      2011-03-24                   Config::Tiny(3)
Impressum