<?xml version='1.0' encoding='utf-8'?>
<pod xmlns="http://axkit.org/ns/2000/pod2xml">
<head>
	<title>名前</title>
</head>
<sect1>
<title>名前</title>
<para>
open - perl pragma to set default PerlIO layers for input and output
</para>
<para>
open - 入出力のためにデフォルトのPerlIOレイヤセットするためのPerlのプラグマ
</para>
</sect1>
<sect1>
<title>概要</title>
<verbatim><![CDATA[
use open IN  => ":crlf", OUT => ":bytes";
use open OUT => ':utf8';
use open IO  => ":encoding(iso-8859-7)";
]]></verbatim>
<verbatim><![CDATA[
use open IO  => ':locale';
]]></verbatim>
<verbatim><![CDATA[
use open ':utf8';
use open ':locale';
use open ':encoding(iso-8859-7)';
]]></verbatim>
<verbatim><![CDATA[
use open ':std';
]]></verbatim>
</sect1>
<sect1>
<title>説明</title>
<para>
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).
</para>
<para>
I/Oレイヤの徹底したサポートが現在実装され、提供されています。
PerlはそのIOシステムとしてPerlIOを使っています(現在、PerlIOはデフォルトです)。
</para>
<para>
The <code>open</code> pragma serves as one of the interfaces to declare default
&quot;layers&quot; (also known as &quot;disciplines&quot;) 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.
Three-argument opens are not affected by this pragma since there you
(can) explicitly specify the layers and are supposed to know what you
are doing.
</para>
<para>
<code>open</code>プラグマは全てのI/Oのデフォルトの&quot;レイヤ&quot;(&quot;disciplines&quot;としても知られています)
へのインターフェースの一つとしての役目をします。
このプラグマのレキシカルコープ内の、全ての二つの引数を取る、open()、 readpipe()(qx// としても知られる)、
それらと類似のオペレータは、宣言されたデフォルトを使うようになります。
三つの引数を取るopenなどは、明示的にレイヤを指定する(ことができる)ため、
自分がすることをわかっていると仮定するので、このプラグマは影響しません。
</para>
<para>
With the <code>IN</code> subpragma you can declare the default layers
of input streams, and with the <code>OUT</code> subpragma you can declare
the default layers of output streams.  With the <code>IO</code>  subpragma
you can control both input and output streams simultaneously.
</para>
<para>
<code>IN</code>サブプラグマで入力ストリームのデフォルトのレイヤを宣言できます。
<code>OUT</code>サブプラグマで出力ストリームのデフォルトのレイヤを宣言できます。
<code>IO</code>サブプラグマで入出力ストリームの両方を同時に制御できます。
</para>
<para>
If you have a legacy encoding, you can use the <code>:encoding(...)</code> tag.
</para>
<para>
レガシーのエンコーディングの場合、<code>:encoding(...)</code>タグが使えます。
</para>
<para>
if you want to set your encoding layers based on your
locale environment variables, you can use the <code>:locale</code> tag.
For example:
</para>
<para>
ロケールの環境変数でエンコーディングレイヤをセットするならば、<code>:locale</code>タグを使えます。
例:
</para>
<verbatim><![CDATA[
$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, "<koi8");
printf "%#x\n", ord(<I>), "\n"; # this should print 0xc1
close I;
]]></verbatim>
<para>
These are equivalent
</para>
<para>
次のものは同じです。
</para>
<verbatim><![CDATA[
use open ':utf8';
use open IO => ':utf8';
]]></verbatim>
<para>
as are these
</para>
<para>
これも同じです。
</para>
<verbatim><![CDATA[
use open ':locale';
use open IO => ':locale';
]]></verbatim>
<para>
and these
</para>
<para>
こちらも同じです。
</para>
<verbatim><![CDATA[
use open ':encoding(iso-8859-7)';
use open IO => ':encoding(iso-8859-7)';
]]></verbatim>
<para>
The matching of encoding names is loose: case does not matter, and
many encodings have several aliases.  See <link xref='Encode::Supported'>Encode::Supported</link> for
details and the list of supported locales.
</para>
<para>
エンコーディング名のマッチングはゆるいです:大文字小文字は問題になりませんし、
多くのエンコーディングに複数のエイリアスがあります。
詳細とサポートされているロケールのリストは、<link xref='Encode::Supported'>Encode::Supported</link>にあります。
</para>
<para>
Note that <code>:utf8</code> PerlIO layer must always be specified exactly like
that, it is not subject to the loose matching of encoding names.
</para>
<para>
次のことに注意して下さい。
<code>:utf8</code> PerlIOレイヤは、常に厳密に指定されなければいけません。
これについてはエンコーディング名のゆるいマッチングの対象になっていません。
</para>
<para>
When open() is given an explicit list of layers they are appended to
the list declared using this pragma.
</para>
<para>
open()に明示的なレイヤのリストが与えられた場合、
それらはこのプラグマを使って宣言されたリストに加えられます。
</para>
<para>
The <code>:std</code> subpragma on its own has no effect, but if combined with
the <code>:utf8</code> or <code>:encoding</code> 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 <code>:utf8</code>, a <code>:std</code> will mean that STDIN, STDOUT, and
STDERR are also in <code>:utf8</code>.  On the other hand, if only output is
chosen to be in <code>:encoding(koi8r)</code>, a <code>:std</code> will cause only the
STDOUT and STDERR to be in <code>koi8r</code>.  The <code>:locale</code> subpragma
implicitly turns on <code>:std</code>.
</para>
<para>
<code>:std</code>サブプラグマはそれ自身は何もしません。
ですが、<code>:utf8</code>か<code>:encoding</code>サブプラグマと組み合わせた場合、
それは、標準のファイルハンドル(STDIN, STDOUT, STDERR)を
input/output ハンドルで選ばれたエンコーディングに従うように変換します。
一方で、出力だけ<code>:encoding(koi8r)</code>であるように選ばれたなら、
<code>:std</code>は、STDOUTとSTDERRだけが<code>koi8r</code>になるようになります。
<code>:locale</code>サブプラグマは暗に<code>:std</code>をつけています。
(訳注:組み合わせるというのは、use open &quot;:utf8&quot;; などの後に、 use open &quot;:std&quot; するということです)
</para>
<para>
The logic of <code>:locale</code> is as follows:
</para>
<para>
<code>:locale</code>のロジックは下記のようになっています:
</para>
<list>
<item><itemtext>1.</itemtext>
<para>
If the platform supports the langinfo(CODESET) interface, the codeset
returned is used as the default encoding for the open pragma.
</para>
<para>
プラットフォームがlanginfo(CODESET)インターフェースをサポートするなら、
コードセットは、open プラグマのデフォルトのエンコーディングとして使われます。
</para>
</item>
<item><itemtext>2.</itemtext>
<para>
If 1. didn't work but we are under the locale pragma, the environment
variables LC_ALL and LANG (in that order) are matched for encodings
(the part after <code>.</code>, if any), and if any found, that is used 
as the default encoding for the open pragma.
</para>
<para>
1. がうまくいかないないが、localeプラグマのもとで、
環境変数LC_ALLとLANGが(この順番で)エンコーディング(the part after <code>.</code>, if any)にマッチし、
見つかったなら、open プラグマのデフォルトのエンコーディングとして使われます。
</para>
</item>
<item><itemtext>3.</itemtext>
<para>
If 1. and 2. didn't work, the environment variables LC_ALL and LANG
(in that order) are matched for anything looking like UTF-8, and if
any found, <code>:utf8</code> is used as the default encoding for the open
pragma.
</para>
<para>
1. と 2. がうまくいかず、環境変数LC_ALLとLANG(がこの順で)UTF-8にみえるものにマッチし、
見つかったなら、<code>:utf8</code>がopen プラグマのでふぉるｔのエンコーディングとして使われます。
</para>
</item>
</list>
<para>
If your locale environment variables (LC_ALL, LC_CTYPE, LANG)
contain the strings 'UTF-8' or 'UTF8' (case-insensitive matching),
the default encoding of your STDIN, STDOUT, and STDERR, and of
<strong>any subsequent file open</strong>, is UTF-8.
</para>
<para>
ロケール環境変数(LC_ALL, LC_CTYPE, LANG)が、'UTF-8' か 'UTF8'(大文字小文字問わず) を
含むなら、STDIN、STDOUT、STDERR、どんなファイルのopenのデフォルトのエンコーディングは、
UTF-8になります。
</para>
<para>
Directory handles may also support PerlIO layers in the future.
</para>
<para>
将来は、ディレクトリハンドルも、PerlIOレイヤがサポートされるかもしれません。
</para>
</sect1>
<sect1>
<title>非NPERLIO 機能</title>
<para>
If Perl is not built to use PerlIO as its IO system then only the two
pseudo-layers <code>:bytes</code> and <code>:crlf</code> are available.
</para>
<para>
PerlがIOシステムとしてPerlIOを使うようにビルドされていなくても、
二つの仮のレイヤ<code>:bytes</code>と<code>:crlf</code>が利用可能です。
</para>
<para>
The <code>:bytes</code> layer corresponds to &quot;binary mode&quot; and the <code>:crlf</code>
layer corresponds to &quot;text mode&quot; 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.
</para>
<para>
&quot;バイナリモード&quot;と&quot;テキストモード&quot;の二つのモードを区別するプラットフォーム(多くのDOSのような(Windowsを含む)プラットフォーム)上で、
ファイルを開くときに、<code>:bytes</code> レイヤは、&quot;バイナリモード&quot;に対応し、<code>:crlf</code>レイヤは、&quot;テキストモード&quot;に対応します。
binmode()が操作不能なプラットフォームでは、これらの二つのレイヤは操作不能です。
ですが、PerlIOが有効ならば、この機能はどこでも動きます。
</para>
</sect1>
<sect1>
<title>実装の詳細</title>
<para>
There is a class method in <code>PerlIO::Layer</code> <code>find</code> which is
implemented as XS code.  It is called by <code>import</code> to validate the
layers:
</para>
<para>
<code>PerlIO::Layer</code> に クラスメソッドがあります。
<code>find</code> は、XS のコードで実装されています。
<code>find</code>は、<code>import</code>で呼ばれて、レイヤが有効か確認します。
</para>
<verbatim><![CDATA[
PerlIO::Layer::->find("perlio")
]]></verbatim>
<para>
The return value (if defined) is a Perl object, of class
<code>PerlIO::Layer</code> which is created by the C code in <filename>perlio.c</filename>.  As
yet there is nothing useful you can do with the object at the perl
level.
</para>
<para>
返値は(定義されていれば)Perl オブジェクトです。
<filename>perlio.c</filename>のCのコードで作られたクラス <code>PerlIO::Layer</code>のものです。
今のところ、perl レベルのオブジェクトでできる有益なことは何もありません。
</para>
</sect1>
<sect1>
<title>SEE ALSO</title>
<para>
<link xref='perlfunc#binmode'>perlfunc/&quot;binmode&quot;</link>, <link xref='perlfunc#open'>perlfunc/&quot;open&quot;</link>, <link xref='perlunicode'>perlunicode</link>, <link xref='PerlIO'>PerlIO</link>,
<link xref='encoding'>encoding</link>
</para>
</sect1>
<sect1>
<title>翻訳について</title>
<para>
翻訳者：加藤敦 (ktat.is@gmail.com)
</para>
<para>
Perlドキュメント日本語訳 Project にて、
Perlモジュール、ドキュメントの翻訳を行っております。
</para>
<verbatim><![CDATA[
http://perldocjp.sourceforge.jp
http://sourceforge.jp/projects/perldocjp/
http://www.freeml.com/ctrl/html/MLInfoForm/perldocjp@freeml.com
http://www.perldoc.jp
]]></verbatim>
</sect1>
</pod>
