Carp-1.01 > =begin
Carp-1.01

名前

carp - warn of errors (from perspective of caller)

carp - エラーの警告 (呼び出し元の観点から)

cluck - warn of errors with stack backtrace (not exported by default)

cluck - スタックバックトレースを伴うエラーの警告 (デフォルトではエクスポートされません)

croak - die of errors (from perspective of caller)

croak - エラーを出してdieします (呼び出し元の観点から)

confess - die of errors with stack backtrace

confess - スタックバックトレースを伴ってdieします

shortmess - return the message that carp and croak produce

shortmess - carpとcroakが生成するメッセージを返します

longmess - return the message that cluck and confess produce

longmess - cluckとconfessが生成するメッセージを返します

概要

    use Carp;
    croak "We're outta here!";

    use Carp qw(cluck);
    cluck "This is how we got here!";

    print FH Carp::shortmess("This will have caller's details added");
    print FH Carp::longmess("This will have stack backtrace added");

説明

The Carp routines are useful in your own modules because they act like die() or warn(), but with a message which is more likely to be useful to a user of your module. In the case of cluck, confess, and longmess that context is a summary of every call in the call-stack. For a shorter message you can use carp, croak or shortmess which report the error as being from where your module was called. There is no guarantee that that is where the error was, but it is a good educated guess.

Carpルーチンはdie()やwarn()のように振る舞うため、モジュールで用いる際に 便利です。しかし、それに伴うメッセージはあなたのモジュールにおける ユーザーにとってより便利なものとなりそうです。cluck、confess及び logmessではその背景にコールスタック内の全ての呼び出しに関する要約が 存在します。より短いメッセージを排出するためにはcarp、croakもしくは shortmessを使うことによって、モジュールが呼び出された位置から エラーをリポートすることが可能です。本ルーチンはエラーメッセージが どこで発生したかを保証するものではありませんが、優れた推測機能を提供します。

Here is a more complete description of how shortmess works. What it does is search the call-stack for a function call stack where it hasn't been told that there shouldn't be an error. If every call is marked safe, it then gives up and gives a full stack backtrace instead. In other words it presumes that the first likely looking potential suspect is guilty. Its rules for telling whether a call shouldn't generate errors work as follows:

ここにはshortmessにおける動作原理についての完全な説明があります。行われるのは エラーが存在しないことを伝えていない関数コールスタックの検索です。もし全ての 呼び出しが安全であるとマークされているならば、その動作をやめ、代わりにフルス タックバックトレースを提供します。言い替えれば真っ先にエラーが起きそうだと 疑うことは罪なことであると考えるのです。呼び出しがエラーを生成するべきでない と判断するルールの内容を下記に示します:

  1. Any call from a package to itself is safe.

    いかなるパッケージからもそれ自身に対しては安全とします。

  2. Packages claim that there won't be errors on calls to or from packages explicitly marked as safe by inclusion in @CARP_NOT, or (if that array is empty) @ISA. The ability to override what @ISA says is new in 5.8.

    パッケージはその呼び出し上で、あるいはパッケージが@CARP_NOT又は (もしその配列が空ならば)@ISAに含まれ、明らかに安全なものとしてマークされて いるパッケージ上でエラーが存在しないであろうことを主張します。 5.8では@ISAによってオーバーライドする機能が新しくなっています。

  3. The trust in item 2 is transitive. If A trusts B, and B trusts C, then A trusts C. So if you do not override @ISA with @CARP_NOT, then this trust relationship is identical to, "inherits from".

    アイテム2における信頼は推移的です。もしAがBを信頼し、BがCを信頼するならば、 AはCを信頼するのです。よってもしあなたが@CARP_NOTとともに@ISAをオーバーライド しなければ、この信頼関係が"継承された"と言えるのです。

  4. Any call from an internal Perl module is safe. (Nothing keeps user modules from marking themselves as internal to Perl, but this practice is discouraged.)

    いかなる内部のPerlモジュールからの呼び出しも安全です。(ユーザーモジュールに Perl内部のものであるとして自分自身をマークしないようにすることはしません。 この事実はがっかりさせるものであります。)

  5. Any call to Carp is safe. (This rule is what keeps it from reporting the error where you call carp/croak/shortmess.)

    Carpに対するどんな呼び出しも安全です。(これはcarp/croak/shortmessを 呼び出した箇所のエラーをリポートさせないようにするルールです。)

スタックトレースの強制

As a debugging aid, you can force Carp to treat a croak as a confess and a carp as a cluck across all modules. In other words, force a detailed stack trace to be given. This can be very helpful when trying to understand why, or from where, a warning or error is being generated.

デバッグを行う目的で、あなたは全てのモジュールに渡ってCarpに croakをconfessとして、carpをcluckとして扱うよう強制することが 可能です。言い替えれば、より詳細なスタックトレースを提供するよう 強制するのです。これは何故、あるいはどこから警告又はエラーが 生成されるのかを知ろうとする際大きな助けとなり得るのです。

This feature is enabled by 'importing' the non-existent symbol 'verbose'. You would typically enable it by saying

この特色はシンボル'verbose'を'インポート'することで使用可能となります。 一般的には次のように宣言することで可能になります。

    perl -MCarp=verbose script.pl

or by including the string MCarp=verbose in the PERL5OPT environment variable.

あるいは環境変数PERL50PTにMCarp=verboseを含めることでも可能になります。

バグ

The Carp routines don't handle exception objects currently. If called with a first argument that is a reference, they simply call die() or warn(), as appropriate.

Carpルーチンは今のところexceptionオブジェクトをハンドルしていません。 もし最初の引数がリファレンスであれば、単純にdie()あるいはwarn()を 適切に呼び出します。

翻訳者

三浦真磁 <snj@users.sourceforge.jp>