=encoding utf-8 =head1 NAME =begin original Config::Tiny - Read/Write .ini style files with as little code as possible =end original Config::Tiny - 必要最小限のコードで .ini形式のファイルの読み書き =head1 SYNOPSIS =begin original # 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' ); =end original # コンフィグファイル rootproperty=blah [section] one=twp three= four Foo =Bar empty= # プログラム use Config::Tiny; # コンフィグの作成 my $Config = Config::Tiny->new; # コンフィグファイルのオープン $Config = Config::Tiny->read( 'file.conf' ); # プロパティの読み取り my $rootproperty = $Config->{_}->{rootproperty}; my $one = $Config->{section}->{one}; my $Foo = $Config->{section}->{Foo}; # データの変更 $Config->{newsection} = { this => 'that' }; # セクションの追加 $Config->{section}->{Foo} = 'Not Bar!'; # 値の変更 delete $Config->{_}; # 値 or セクションの削除 # コンフィグの保存 $Config->write( 'file.conf' ); =head1 DESCRIPTION =begin original C is a perl class to read and write .ini style configuration files with as little code as possible, reducing load time and memory overhead. Most of the time it is accepted that Perl applications use a lot of memory and modules. The C<::Tiny> family of modules is specifically intended to provide an ultralight alternative to the standard modules. 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 L, L or one of the many other C modules. To rephrase, L does B preserve your comments, whitespace, or the order of your config file. =end original Cは .ini形式のコンフィグファイルを, 必要最小限のコード, ロード時間, メモリ消費量で読み書きするための, Perlクラスです. 多くの場合 Perlアプリケーションは多くのメモリとモジュールを利用することが, 許容されます. モジュールのC<::Tiny>とつくものは特別で, 標準的なモジュールの超軽量版の代替として, 利用することを意図しています. このモジュールは, 人間の書いたファイルの読み取りを第一とし, ドキュメントやコメントなど必要ないものは保持しません. より強力なものが必要であれば, L, L, その他多くの Cモジュールを利用してください. 言い換えると, Lはコンフィグファイル中のコメント, 空白, 順番を保持しません. =head1 CONFIGURATION FILE SYNTAX =begin original Files are the same format as for windows .ini files. For example: [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 C<"root section">, available at C<$Config-E{_}>. Lines starting with C<'#'> or C<';'> 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. =end original Windowsで使われる .iniファイルと同じ形式のファイルです. 例えば: [section] var1=value1 var2=value2 もしプロパティがファイルの先頭のセクションの外側にあれば, それはC<"root section">に割り当てられ, C<$Config-E{_}>で参照することができます. C<'#'>もしくは C<';'>で開始する行はコメントとし, 空行同様に無視します. コンフィグファイルを書き出す場合, すべてのコメント, 空白, コンフィグファイルの要素の順番は無視されます. もし書き出す場合にそれらの要素を保持する必要があるのであれば, このモジュールはふさわしくないので, より良いものを使ってください. =head1 METHODS =begin original =head2 new The constructor C creates and returns an empty C object. =head2 read $filename The C constructor reads a config file, and returns a new C object containing the properties in the file. Returns the object on success, or C on error. When C fails, C sets an error message internally you can recover via Cerrstr>. Although in B cases a failed C will also set the operating system error variable C<$!>, not all errors do and you should not rely on using the C<$!> variable. =head2 read_string $string; The C method takes as argument the contents of a config file as a string and returns the C object for it. =head2 write $filename The C method generates the file content for the properties, and writes it to disk to the filename specified. Returns true on success or C on error. =head2 write_string Generates the file content for the object and returns it as a string. =head2 errstr When an error occurs, you can retrieve the error message either from the C<$Config::Tiny::errstr> variable, or using the C method. =end original =head2 new Cコンストラクタは, 空の Cオブジェクトを返します. =head2 read $filename Cコンストラクタはコンフィグファイルの内容を読み取り, ファイルのプロパティの内容を保持する, 新しい Cオブジェクトを返します. 成功した場合はオブジェクトが, 失敗した場合は Cが返ります. Cに失敗した場合, Cはエラーメッセージを内部的に保存し, Cerrstr>から復帰できるようにします. Cの失敗のうちB<いくつか>については, OSエラー変数 C<$!>にもエラー内容がセットされますが, すべてのエラーについてではないので, C<$!>変数に依存すべきではありません. =head2 read_string $string; Cメソッドは, コンフィグファイルの内容を文字列として受け取り, それをCオブジェクトにしたものを返します. =head2 write $filename Cメソッドはプロパティからファイル内容を生成し, 指定されたファイルに書き出します. 成功した場合は真, 失敗した場合は Cが返ります. =head2 write_string オブジェクトからファイル内容を生成し, 文字列として返します. =head2 errstr エラーが発生した場合, エラーメッセージを C<$Config::Tiny::errstr>変数か, Cメソッドを利用することで取得することができます. =head1 CAVEATS =begin original =head2 Unsupported Section Headers Some edge cases in section headers are not support, and additionally may not be detected when writing the config file. 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. =end original =head2 未サポートのセクションヘッダ セクションヘッダのエッジケースでサポートされないものがあり, それらはコンフィグファイルの書き出しの場合に検知することができません. 特に, セクションヘッダが空白で始まっている, 末尾に空白がある, 改行が含まれるという場合は, ファイルに正しく書き出せず, ファイル内容を破壊する原因となってしまいます. =head1 SUPPORT =begin original Bugs should be reported via the CPAN bug tracker at L For other issues, or commercial enhancement or support, contact the author. =end original バグは以下の CPANバグトラッカを使ってレポートしてください. L 他の問題, 商用での促進, サポートについては作者に連絡を取ってください. =head1 AUTHOR Adam Kennedy Eadamk@cpan.orgE =head1 ACKNOWLEGEMENTS Thanks to Sherzod Ruzmetov Esherzodr@cpan.orgE for L, which inspired this module by being not quite "simple" enough for me :) =head1 SEE ALSO L, L, L =head1 COPYRIGHT Copyright 2002 - 2011 Adam Kennedy. 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. =cut