- bless REF,CLASSNAME
- bless REF
-
This function tells the thingy referenced by REF that it is now an object in the CLASSNAME package. If CLASSNAME is an empty string, it is interpreted as referring to the
main
package. If CLASSNAME is omitted, the current package is used. Because a bless is often the last thing in a constructor, it returns the reference for convenience. Always use the two-argument version if a derived class might inherit the method doing the blessing. See perlobj for more about the blessing (and blessings) of objects.この関数は、REF で渡された オブジェクトに対し、 CLASSNAME 内のオブジェクトとなったことを伝えます。 CLASSNAME が空文字列の場合、
main
パッケージを参照しているものと 解釈されます。 CLASSNAME が省略された場合には、その時点のパッケージとなります。 bless は通常、コンストラクタの最後に 置かれますので、簡便のためにそのリファレンスを返します。 派生クラスが bless されるメソッドを継承する場合は、 常に 2 引数版を使ってください。 オブジェクトの bless (や再 bless) について、詳しくは と perlobj を 参照してください。Consider always blessing objects in CLASSNAMEs that are mixed case. Namespaces with all lowercase names are considered reserved for Perl pragmas. Builtin types have all uppercase names. To prevent confusion, you may wish to avoid such package names as well. It is advised to avoid the class name
0
, because much code erroneously uses the result of ref as a truth value.大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを 考慮してください。 全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。 組み込みの型は全て大文字の名前を持ちます。 混乱を避けるために、 パッケージ名としてこのような名前は避けるべきです。 CLASSNAME は真の値を持つようにしてください; クラス名として
0
は避けてください; 多くのコードが誤って ref の結果を真の値として使っているからです。"Perl Modules" in perlmod を参照してください。