Config::Tiny - Read/Write .ini style files with as little code as possible
# 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( 'file.conf' );
# Reading properties my $rootproperty = $Config->{_}->{rootproperty}; my $one = $Config->{section}->{one}; my $Foo = $Config->{section}->{Foo};
# Changing data $Config->{newsection} = { this => 'that' }; # Add a section $Config->{section}->{Foo} = 'Not Bar!'; # Change a value delete $Config->{_}; # Delete a value or section
# Save a config $Config->write( 'file.conf' );
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 "Config::" modules. To rephrase, Config::Tiny does not preserve your comments, whitespace, or the order of your config file.
[section] var1=value1 var2=value2
If a property is outside of a section at the beginning of a file, it will be assigned to the "root section", available at "$Config->{_}".
Lines starting with '#' or ';' are considered comments and ignored, as are blank lines.
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.
Returns the object on success, or "undef" on error.
When "read" fails, "Config::Tiny" sets an error message internally you can recover via "<Config::Tiny-"errstr>>. Although in some cases a failed "read" will also set the operating system error variable $!, not all errors do and you should not rely on using the $! variable.
Returns true on success or "undef" on error.
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Config-Tiny>
For other issues, or commercial enhancement or support, contact the author.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |