=head1 NAME 名前 UNIVERSAL - base class for ALL classes (blessed references) UNIVERSAL - 全てのクラス(ブレスされたリファレンス)の基底クラス =head1 SYNOPSIS 概要 $is_io = $fd->isa("IO::Handle"); $is_io = Class->isa("IO::Handle"); $does_log = $obj->DOES("Logger"); $does_log = Class->DOES("Logger"); $sub = $obj->can("print"); $sub = Class->can("print"); $sub = eval { $ref->can("fandango") }; $ver = $obj->VERSION; # but never do this! $is_io = UNIVERSAL::isa($fd, "IO::Handle"); $sub = UNIVERSAL::can($obj, "print"); =head1 DESCRIPTION 説明 C is the base class from which all blessed references inherit. See L. C は全てのブレスされたリファレンスが継承する基底クラスです, L も参照してください. C provides the following methods: C は以下のメソッドを提供しています: =over 4 =item C<< $obj->isa( TYPE ) >> =item C<< CLASS->isa( TYPE ) >> =item C<< eval { VAL->isa( TYPE ) } >> Where ここで =over 4 =item C is a package name はパッケージ名 =item C<$obj> is a blessed reference or a string containing a package name はブレスされたリファレンスかパッケージ名を含んだ文字列 =item C is a package name はパッケージ名 =item C is any of the above or an unblessed reference 上のいずれかかブレスされていないリファレンス =back When used as an instance or class method (C<< $obj->isa( TYPE ) >>), C returns I if $obj is blessed into package C or inherits from package C. インスタンス若しくはクラスメソッド (C<< $obj->isa( TYPE ) >>)として 使うときは $obj がパッケージ C 若しくはパッケージ C の派生にブレスされているときに I<真> を返します. When used as a class method (C<< CLASS->isa( TYPE ) >>, sometimes referred to as a static method), C returns I if C inherits from (or is itself) the name of the package C or inherits from package C. クラスメソッド (C<< CLASS->isa( TYPE ) >>: スタティックメソッドとして 参照されることもあります)として使う時は C がパッケージ名 C 若しくはパッケージ C の派生から派生している(若しくは そのもの)の時に I<真> を返します. If you're not sure what you have (the C case), wrap the method call in an C block to catch the exception if C is undefined. もし調べたい対象が何であるのかはっきりしていないとき(Cのケース)では, C が未定義のときの例外を捕捉するために, メソッド呼び出しを C で包む必要があります. If you want to be sure that you're calling C as a method, not a class, check the invocant with C from L first: C をクラスではなくメソッド呼び出しであることを保証したいのであれば 最初に L の C で呼び出しを確認します: use Scalar::Util 'blessed'; if ( blessed( $obj ) && $obj->isa("Some::Class") { ... } =item C<< $obj->DOES( ROLE ) >> =item C<< CLASS->DOES( ROLE ) >> C checks if the object or class performs the role C. A role is a named group of specific behavior (often methods of particular names and signatures), similar to a class, but not necessarily a complete class by itself. For example, logging or serialization may be roles. C はオブジェクト若しくはクラスが役割 C として機能するかどうかを 調べます. 役割(role)とは特定の振る舞いに名前を付けたグループです( しばしば特定の名前やシグニチャを持ったメソッドです), クラスと似て いますが, それ自体が完全なクラスである必要はありません. 例えば, logging や serialization は役割になるでしょう. C and C are similar, in that if either is true, you know that the object or class on which you call the method can perform specific behavior. However, C is different from C in that it does not care I the invocant performs the operations, merely that it does. (C of course mandates an inheritance relationship. Other relationships include aggregation, delegation, and mocking.) C と C はどちらも, 真であればメソッドを呼び出したオブジェクト 若しくはクラスが特定の振る舞いを行えるかどうかを知ることが 出来るという点で似ています. しかしながら, C は 呼び出し先が操作を どのように処理するかには気にしないで, 単にそれを行うということを調べるに すぎないという点で C とは異なります. (C はもちろん 関連の継承を委任しています. 他の関連には集約(aggregation), 委譲(delegation), mock が含まれます.) By default, classes in Perl only perform the C role. To mark that your own classes perform other roles, override C appropriately. デフォルトでは, Perl のクラスは C ロールとして機能するだけです. 自分のクラスで他のロールの機能をマークするには, C を適切に オーバーライドします. There is a relationship between roles and classes, as each class implies the existence of a role of the same name. There is also a relationship between inheritance and roles, in that a subclass that inherits from an ancestor class implicitly performs any roles its parent performs. Thus you can use C in place of C safely, as it will return true in all places where C will return true (provided that any overridden C I C methods behave appropriately). ロールとクラスの間には, 各クラスは暗にその同じ名前のロールが存在するという 関連があります. 継承トロールには, 基底クラスから派生したサブクラスは 暗黙にその親の機能する任意のロールは機能するという点も関連があります. それ故に C が真を返す全ての場所で C は真を返すので(オーバー ライドされた C I<及び> C メソッドは適切に振る舞うため), 安全に C の代わりに C を使うことが出来ます, =item C<< $obj->can( METHOD ) >> =item C<< CLASS->can( METHOD ) >> =item C<< eval { VAL->can( METHOD ) } >> C checks if the object or class has a method called C. If it does, then it returns a reference to the sub. If it does not, then it returns I. This includes methods inherited or imported by C<$obj>, C, or C. C はオブジェクト若しくはクラスが C というメソッドを 持っているかを調べます. もし持っていれば関数リファレンスが返されます. もし持っていなければ I が返されます. これには C<$obj>, C, 若しくは C で継承されている若しくはインポートされている メソッドが含まれます. C cannot know whether an object will be able to provide a method through AUTOLOAD (unless the object's class has overriden C appropriately), so a return value of I does not necessarily mean the object will not be able to handle the method call. To get around this some module authors use a forward declaration (see L) for methods they will handle via AUTOLOAD. For such 'dummy' subs, C will still return a code reference, which, when called, will fall through to the AUTOLOAD. If no suitable AUTOLOAD is provided, calling the coderef will cause an error. C はオブジェクトが(オブジェクトのクラスが C を適切にオーバー ライドしていないのであれば) AUTOLOAD を通してメソッドを提供可能かどうかは 知ることができません, そのため I が返ってきてもオブジェクトが そのメソッド呼び出しを処理することができないとは限りません. これを 回避するにはモジュールの作者が AUTOLOAD を使って処理するメソッドに対して 前方宣言を使うことです(L参照). そのような'ダミー'の関数は C はコードリファレンスを返しますが, それが呼び出された時には AUTOLOAD へとフォールスルーされます. もし適切な AUTOLOAD が提供されて いなければ, コードリファレンスの呼び出しはエラーになるでしょう. You may call C as a class (static) method or an object method. C はクラス(スタティック)メソッド, オブジェクトメソッドとして 呼び出すことができます. Again, the same rule about having a valid invocant applies -- use an C block or C if you need to be extra paranoid. 繰り返しますが, 有効な呼び出しのためには同じルールがつかわれます -- C ブロックかよりこだわるのであれば C を使う必要が あります. =item C C will return the value of the variable C<$VERSION> in the package the object is blessed into. If C is given then it will do a comparison and die if the package version is not greater than or equal to C. C はオブジェクトがブレスされているパッケージの変数 C<$VERSION> の値を返します. もし C が与えられていた 場合には比較をおコアってパッケージのバージョンが C 以上でなかった場合には die します. C can be called as either a class (static) method or an object method. C はクラス(スタティック)メソッド若しくはオブジェクトメソッド として呼び出すことができます. =back =head1 EXPORTS エクスポート None by default. デフォルトでは何もエクスポートされません. You may request the import of three functions (C, C, and C), however it is usually harmful to do so. Please don't do this in new code. 3つの関数(C, C, そして C)をインポートしたいかも しれませんが, それを行うことはたいてい有害なことです. 新しいコードでは それは行わないでください. For example, previous versions of this documentation suggested using C as a function to determine the type of a reference: 例えば, このドキュメントの以前のバージョンではリファレンスの 種類を調べるのに C を関数として使うことを提案していました: use UNIVERSAL 'isa'; $yes = isa $h, "HASH"; $yes = isa "Foo", "Bar"; The problem is that this code will I call an overridden C method in any class. Instead, use C from L for the first case: この時, このコードは他のクラスでオーバーライドされた C メソッドを呼び出すI<ことがない>という問題があります. 1つめのケースについては代わりに L の C を 使うようにしてください. use Scalar::Util 'reftype'; $yes = reftype( $h ) eq "HASH"; and the method form of C for the second: そして2番目のケースについてはメソッド形式の C を使うように してください. $yes = Foo->isa("Bar"); =head1 TRANSALTE TO JAPANESE 和訳 山科 氷魚 (YAMASHINA Hio) Origlnal distribution is perl VERSION 5.9.4. Translated at 2007-03-19. 原典: perl VERSION 5.9.4. 翻訳日: 2007-03-19.