=encoding euc-jp =head1 NAME =begin original autodie - Replace functions with ones that succeed or die with lexical scope =end original autodie - レキシカルスコープ内の関数を、成功しなければ die するものに置き換える =head1 SYNOPSIS use autodie; # Recommended: implies 'use autodie qw(:default)' use autodie qw(:all); # Recommended more: defaults and system/exec. use autodie qw(open close); # open/close succeed or die open(my $fh, "<", $filename); # No need to check! { no autodie qw(open); # open failures won't die open(my $fh, "<", $filename); # Could fail silently! no autodie; # disable all autodies } =head1 DESCRIPTION bIlujDI' yIchegh()Qo'; yIHegh()! =begin original It is better to die() than to return() in failure. =end original 失敗して return() するより die() した方がましだ。 =begin original -- Klingon programming proverb. =end original -- クリンゴンのプログラミングことわざ。 =begin original The C pragma provides a convenient way to replace functions that normally return false on failure with equivalents that throw an exception on failure. =end original C プラグマは、通常失敗時に偽を返す関数を、失敗時に例外を投げる 等価な関数に置き換える便利な手段を提供します。 =begin original The C pragma has I, meaning that functions and subroutines altered with C will only change their behaviour until the end of the enclosing block, file, or C. =end original C プラグマは I<レキシカルスコープ> を持ちます; つまり、 C で置き換えられる関数とサブルーチンは、ブロック、ファイル、 C の最後までだけ振る舞いを変えます。 =begin original If C is specified as an argument to C, then it uses L to do the heavy lifting. See the description of that module for more information. =end original C の引数に C が指定されると、重い作業をするために L を使います。 さらなる情報についてはこのモジュールの説明を参照してください。 =head1 EXCEPTIONS (例外) =begin original Exceptions produced by the C pragma are members of the L class. The preferred way to work with these exceptions under Perl 5.10 is as follows: =end original C プラグマによって生成される例外は、 L クラスのメンバーです。 Perl 5.10 でこれらの例外を扱うのに適した方法は次のようなものです: use feature qw(switch); eval { use autodie; open(my $fh, '<', $some_file); my @records = <$fh>; # Do things with @records... close($fh); }; given ($@) { when (undef) { say "No error"; } when ('open') { say "Error from open"; } when (':io') { say "Non-open, IO error."; } when (':all') { say "All other autodie errors." } default { say "Not an autodie error at all." } } =begin original Under Perl 5.8, the C structure is not available, so the following structure may be used: =end original Perl 5.8 では、C 構文は利用できないので、次のような 構文が使われます: eval { use autodie; open(my $fh, '<', $some_file); my @records = <$fh>; # Do things with @records... close($fh); }; if ($@ and $@->isa('autodie::exception')) { if ($@->matches('open')) { print "Error from open\n"; } if ($@->matches(':io' )) { print "Non-open, IO error."; } } elsif ($@) { # A non-autodie exception. } =begin original See L for further information on interrogating exceptions. =end original 例外の問い合わせに関するさらなる情報については L を 参照してください。 =head1 CATEGORIES (カテゴリ) =begin original Autodie uses a simple set of categories to group together similar built-ins. Requesting a category type (starting with a colon) will enable autodie for all built-ins beneath that category. For example, requesting C<:file> will enable autodie for C, C, C, C and C. =end original autodie は、似たような組み込み関数をまとめるために単純なカテゴリの集合を 使います。 (コロンで始まる)カテゴリ型を要求すると、そのカテゴリに属する全ての 組み込み関数に関して autodie を有効にします。 例えば、C<:file> を要求すると、C, C, C, C and C の autodie を有効にします。 =begin original The categories are currently: =end original 現在のカテゴリは: :all :default :io read seek sysread sysseek syswrite :dbm dbmclose dbmopen :file binmode close fcntl fileno flock ioctl open sysopen truncate :filesys chdir closedir opendir link mkdir readlink rename rmdir symlink unlink :ipc pipe :msg msgctl msgget msgrcv msgsnd :semaphore semctl semget semop :shm shmctl shmget shmread :socket accept bind connect getsockopt listen recv send setsockopt shutdown socketpair :threads fork :system system exec =begin original Note that while the above category system is presently a strict hierarchy, this should not be assumed. =end original 前述のカテゴリシステムは今のところ厳密な階層になっていますが、 これを仮定するべきではないことに注意してください。 =begin original A plain C implies C. Note that C and C are not enabled by default. C requires the optional L module to be installed, and enabling C or C will invalidate their exotic forms. See L below for more details. =end original 単なる C は C を示します。 C と C はデフォルトでは有効にならないことに注意してください。 C はオプションの L モジュールが インストールされる必要があり、 C と C を有効にすると、その非標準的な形式は無効になります。 さらなる詳細については後述する L を参照してください。 =begin original The syntax: =end original この文法は: use autodie qw(:1.994); =begin original allows the C<:default> list from a particular version to be used. This provides the convenience of using the default methods, but the surety that no behavorial changes will occur if the C module is upgraded. =end original 特定のバージョンの C<:default> リストが使われるようにします。 これは、デフォルト手法を使う便利さを提供しますが、 C モジュールがアップグレードされても振る舞いの変更が起こらないことを 保証します。 =begin original C can be enabled for all of Perl's built-ins, including C and C with: =end original C は、次のようにすることで C と C を含む 全ての Perl 組み込み関数に関して有効になります: use autodie qw(:all); =head1 FUNCTION SPECIFIC NOTES (関数固有の注意) =head2 flock =begin original It is not considered an error for C to return false if it fails to an C (or equivalent) condition. This means one can still use the common convention of testing the return value of C when called with the C option: =end original C が C (または等価な)条件で失敗したことで 偽を返した場合はエラーとはみなしません。 これは、C を C オプション付きで呼び出したときの 返り値をテストするためのよくある観衆を使っていることを意味します: use autodie; if ( flock($fh, LOCK_EX | LOCK_NB) ) { # We have a lock } =begin original Autodying C will generate an exception if C returns false with any other error. =end original C がその他のエラーで偽を返したときは autodie 下の C は 例外を生成します。 =head2 system/exec =begin original The C built-in is considered to have failed in the following circumstances: =end original C 組み込み関数は、次の条件のときに失敗したとして扱われます: =over 4 =item * =begin original The command does not start. =end original コマンドが開始しない。 =item * =begin original The command is killed by a signal. =end original コマンドがシグナルで kill された。 =item * =begin original The command returns a non-zero exit value (but see below). =end original コマンドが非 0 終了コードを返した (しかし後述)。 =back =begin original On success, the autodying form of C returns the I rather than the contents of C<$?>. =end original 成功時、autodie 形式の C は C<$?> ではなく I<終了コード> を 返します。 =begin original Additional allowable exit values can be supplied as an optional first argument to autodying C: =end original autodie 形式の C のオプションの最初の引数として、 追加の受け入れ可能な終了コードを指定できます: system( [ 0, 1, 2 ], $cmd, @args); # 0,1,2 are good exit values =begin original C uses the L module to change C. See its documentation for further information. =end original C は C を変更するのに L モジュールを 使います。 さらなる情報についてはその文書を参照してください。 =begin original Applying C to C or C causes the exotic forms C or C to be considered a syntax error until the end of the lexical scope. If you really need to use the exotic form, you can call C or C instead, or use C before calling the exotic form. =end original C や C に C を適用すると、レキシカルスコープの 終わりまで、非標準の C や C 形式は文法エラーとして扱われます。 もし本当に非標準形式を使う必要がある場合は、 代わりに C や C を呼び出すか、 非標準形式の呼び出し前に C を使ってください。 =head1 GOTCHAS (コツ) =begin original Functions called in list context are assumed to have failed if they return an empty list, or a list consisting only of a single undef element. =end original リストコンテキストで呼び出された関数は、空リストを返したり、 一つの undef 要素だけからなるリストを返した場合、失敗したと仮定されます。 =head1 DIAGNOSTICS (診断) =over 4 =item :void cannot be used with lexical scope =begin original The C<:void> option is supported in L, but not C. To workaround this, C may be explicitly disabled until the end of the current block with C. To disable autodie for only a single function (eg, open) use C. =end original C<:void> オプションは L では対応していますが、 C では対応していません。 これを回避するために、C は C を使って ブロックの終わりまで明示的に無効にできます。 単一の関数(例: open)だけに対して autodie を無効にするには、 C を使ってください。 =item No user hints defined for %s =begin original You've insisted on hints for user-subroutines, either by pre-pending a C to the subroutine name itself, or earlier in the list of arguments to C. However the subroutine in question does not have any hints available. =end original サブルーチン名自身の前か、C の引数の一覧に C を付けることで、 ユーザーサブルーチンのヒントを主張しました。 しかし問題のサブルーチンは何のヒントも利用できません。 =back =begin original See also L. =end original L も参照してください。 =head1 BUGS =begin original "Used only once" warnings can be generated when C or C is used with package filehandles (eg, C). Scalar filehandles are strongly recommended instead. =end original C や C がパッケージファイルハンドル (例: C) で 使われると "Used only once" 警告が発生することがあります。 代わりにスカラファイルハンドルを強く勧めます。 =begin original When using C or C with user subroutines, the declaration of those subroutines must appear before the first use of C or C, or have been exported from a module. Attempting to use C or C on other user subroutines will result in a compile-time error. =end original ユーザーサブルーチンに対して C や C を使うとき、 これらのサブルーチンの宣言は、 C や C が最初に使われるか、モジュールから エクスポートされる前に行われなければなりません。 その他のユーザーラブルーチンに対して C や C を使おうとすると、 コンパイル時エラーになります。 =begin original Due to a bug in Perl, C may "lose" any format which has the same name as an autodying built-in or function. =end original Perl のバグにより、C は autodie する関数と同じ名前のフォーマットを 「失う」ことがあります。 =begin original C may not work correctly if used inside a file with a name that looks like a string eval, such as F. =end original C は、F のような、文字列 eval のように見える名前の ファイルの内側で使われると正しく動作しないかもしれません。 =head2 autodie and string eval (autodie と文字列 eval) =begin original Due to the current implementation of C, unexpected results may be seen when used near or with the string version of eval. I. =end original C の現在の実装の都合により、文字列版の eval やその近くでは、 想定外の結果が表れることがあります。 I<これらのバグはブロック eval を使うと起こりません>。 =begin original Under Perl 5.8 only, C I propagate into string C statements, although it can be explicitly enabled inside a string C. =end original Perl 5.8 の基だけでは、C は文字列 C 文の中には 伝搬 I<しません>; しかし文字列 C の中で明示的に有効にすることはできます。 =begin original Under Perl 5.10 only, using a string eval when C is in effect can cause the autodie behaviour to leak into the surrounding scope. This can be worked around by using a C at the end of the scope to explicitly remove autodie's effects, or by avoiding the use of string eval. =end original Perl 5.10 の基だけでは、C が有効のときに文字列 eval を使うと、 autodie の振る舞いを周りのスコープに漏らすことがあります。 これは、スコープの末尾で C を使うことで 明示的に autodie の効果を取り除くか、 文字列 eval の使用を避けることで回避できます。 =begin original I. The use of C with block eval is considered good practice. =end original I<これらのバグはブロック eval には存在しません>。 ブロック eval で C を使うのは良い習慣と考えられます。 =head2 REPORTING BUGS (バグ報告) =begin original Please report bugs via the CPAN Request Tracker at L. =end original どうか L の CPAN Request Tracker 経由でバグを報告してください。 =head1 FEEDBACK (フィードバック) =begin original If you find this module useful, please consider rating it on the CPAN Ratings service at L . =end original このモジュールが有用だと感じたら、 L の CPAN Ratings service で評価することを検討してください。 =begin original The module author loves to hear how C has made your life better (or worse). Feedback can be sent to Epjf@perltraining.com.auE. =end original モジュール作者は C があなたの生活をどのように良くした (あるいは悪くした)かを聞くのが好きです。 フィードバックは Epjf@perltraining.com.auE に送ることができます。 =head1 AUTHOR Copyright 2008-2009, Paul Fenwick Epjf@perltraining.com.auE =head1 LICENSE This module is free software. You may distribute it under the same terms as Perl itself. =head1 SEE ALSO L, L, L, L I at L =head1 ACKNOWLEDGEMENTS Mark Reed and Roland Giersig -- Klingon translators. See the F file for full credits. The latest version of this file can be found at L . =begin meta Translate: SHIRAKATA Kentaro Status: completed =end meta =cut