=encoding euc-jp =head1 NAME =begin original open - perl pragma to set default PerlIO layers for input and output =end original open - 入出力のためのデフォルトの PerlIO 層をセットするための perl プラグマ =head1 SYNOPSIS use open IN => ":crlf", OUT => ":bytes"; use open OUT => ':utf8'; use open IO => ":encoding(iso-8859-7)"; use open IO => ':locale'; use open ':encoding(utf8)'; use open ':locale'; use open ':encoding(iso-8859-7)'; use open ':std'; =head1 DESCRIPTION =begin original Full-fledged support for I/O layers is now implemented provided Perl is configured to use PerlIO as its IO system (which is now the default). =end original Perl が IO システム(現在のデフォルト)として PerlIO を 使うように設定されている場合、I/O 層としての本格的な対応が 実装されています。 =begin original The C pragma serves as one of the interfaces to declare default "layers" (also known as "disciplines") for all I/O. Any two-argument open(), readpipe() (aka qx//) and similar operators found within the lexical scope of this pragma will use the declared defaults. Even three-argument opens may be affected by this pragma when they don't specify IO layers in MODE. =end original C プラグマはすべての I/O のデフォルトの「層」("layer") (「ディシプリン」"disciplines"とも呼ばれます)を宣言するための インターフェースの一つとして働きます。 2 つの引数を取る open()、readpipe()(または qx//) と同様の演算子は、 そのレキシカルスコープでこのプラグマを見つけると、宣言されたデフォルトを 使用します。 3 つの引数を取る open でさえ、MODE に IO 層が指定されていない場合、 このプラグマの影響を受けます。 =begin original With the C subpragma you can declare the default layers of input streams, and with the C subpragma you can declare the default layers of output streams. With the C subpragma you can control both input and output streams simultaneously. =end original C サブプラグマを使って入力ストリームのデフォルト層を宣言でき、 C サブプラグマを使って出力ストリームのデフォルト層を 宣言できます。 C サブプラグマを使って入出力の両方を同時に制御できます。 =begin original If you have a legacy encoding, you can use the C<:encoding(...)> tag. =end original レガシーエンコーディングを使っているのなら、C<:encoding(...)> タグが 使えます。 =begin original If you want to set your encoding layers based on your locale environment variables, you can use the C<:locale> tag. For example: =end original ロケールに関する環境変数に基づいてエンコーディング層を設定したい場合、 C<:locale> タグが使えます。 例えば: $ENV{LANG} = 'ru_RU.KOI8-R'; # the :locale will probe the locale environment variables like LANG use open OUT => ':locale'; open(O, ">koi8"); print O chr(0x430); # Unicode CYRILLIC SMALL LETTER A = KOI8-R 0xc1 close O; open(I, "), "\n"; # this should print 0xc1 close I; =begin original These are equivalent =end original 以下の2行は等価です: use open ':encoding(utf8)'; use open IO => ':encoding(utf8)'; =begin original as are these =end original 同様に、以下の2行 use open ':locale'; use open IO => ':locale'; =begin original and these =end original や以下の2行 use open ':encoding(iso-8859-7)'; use open IO => ':encoding(iso-8859-7)'; も等価です。 =begin original The matching of encoding names is loose: case does not matter, and many encodings have several aliases. See L for details and the list of supported locales. =end original エンコーディング名のマッチングは緩やかなものです: 大小文字の違いは 無視され、多くのエンコーディングはいくつかの別名を持っています。 対応しているロケールのリストと詳細は L を 参照してください。 =begin original When open() is given an explicit list of layers (with the three-arg syntax), they override the list declared using this pragma. =end original open() に層のリストが(3 引数文法で)与えられた場合、それらは このプラグマを使って宣言されたリストを上書きします。 =begin original The C<:std> subpragma on its own has no effect, but if combined with the C<:utf8> or C<:encoding> subpragmas, it converts the standard filehandles (STDIN, STDOUT, STDERR) to comply with encoding selected for input/output handles. For example, if both input and out are chosen to be C<:encoding(utf8)>, a C<:std> will mean that STDIN, STDOUT, and STDERR are also in C<:encoding(utf8)>. On the other hand, if only output is chosen to be in C<< :encoding(koi8r) >>, a C<:std> will cause only the STDOUT and STDERR to be in C. The C<:locale> subpragma implicitly turns on C<:std>. =end original C<:std> サブプラグマそれ自身は何の効果ももちませんが、C<:utf8> や C<:encoding> といったサブプラグマと組み合わせた場合には、 標準ファイルハンドル(STDIN, STDOUT, STDERR)を、選択された入出力ハンドルの エンコーディングに変換します。 たとえば、入力と出力の両方で C<:encoding(utf8)> を選択した場合、 C<:std> は STDIN, STDOUT, STDERR もまた C<:encoding(utf8)> となることを意味します。 一方、出力だけを C<< :encoding(koi8r) >> と選択した場合には、 C<:std> は STDOUT と STDERR だけを C にします。 C<:locale> サブプラグマは暗黙のうちに C<:std> を有効にします。 =begin original The logic of C<:locale> is described in full in L, but in short it is first trying nl_langinfo(CODESET) and then guessing from the LC_ALL and LANG locale environment variables. =end original C<:locale> のロジックは L に完全に記述されていますが、 短く言うと、まず nl_langinfo(CODESET) を試して、その後 LC_ALL と LANG のロケール環境変数から推測します。 =begin original Directory handles may also support PerlIO layers in the future. =end original ディレクトリハンドルも将来 PerlIO 層をサポートするでしょう。 =head1 NONPERLIO FUNCTIONALITY (非 PerlIO 機能) =begin original If Perl is not built to use PerlIO as its IO system then only the two pseudo-layers C<:bytes> and C<:crlf> are available. =end original Perl がその IO システムとして PerlIO を使うように構築されていなかった場合、 C<:bytes> と C<:crlf> の二つの擬似層だけが使用可能です。 =begin original The C<:bytes> layer corresponds to "binary mode" and the C<:crlf> layer corresponds to "text mode" on platforms that distinguish between the two modes when opening files (which is many DOS-like platforms, including Windows). These two layers are no-ops on platforms where binmode() is a no-op, but perform their functions everywhere if PerlIO is enabled. =end original C<:bytes> 層は「バイナリモード」を、C<:crlf> 層は「テキストモード」を、 ファイルをオープンするときにこれら二つのモードを区別する(Windows を 含めた多くの DOS に似たシステム) プラットフォームにおいて表します。 これら二つの層は binmode() が何も行わないプラットフォームでは何も 行いませんが、PerlIO が有効である場合にはこれらの関数はすべての場所で 動作します。 =head1 IMPLEMENTATION DETAILS (実装の詳細) =begin original There is a class method in C C which is implemented as XS code. It is called by C to validate the layers: =end original C に、XS コードで実装された C という クラスメソッドがあります。 これは層の確認のために C によって呼び出されます: PerlIO::Layer::->find("perlio") =begin original The return value (if defined) is a Perl object, of class C which is created by the C code in F. As yet there is nothing useful you can do with the object at the perl level. =end original 返り値は、(もし定義されていれば) F の C プログラムによって 作成された C クラスの Perl オブジェクトです。 perl レベルでは現在のところこれを使って何か便利なことが できるわけではありません。 =head1 SEE ALSO L, L, L, L, L =begin meta Translate: KIMURA Koichi (1.03) Update: Kentaro Shirakata (1.06) =end meta =cut