- bless REF,CLASSNAME
- bless REF
-
blesstells Perl to mark the item referred to byREFas an object in a package. The two-argument version ofblessis always preferable unless there is a specific reason to not use it.blessは Perl に、REFで参照しているアイテムを パッケージのオブジェクトとしてマークします。 それを 使わない 明確な理由がないかぎり、 2 引数版のblessが好ましいです。Bless the referred-to item into a specific package (recommended form):
bless $ref, $package;The two-argument form adds the object to the package specified as the second argument.
2 引数形式では、2 番目の引数として指定されたパッケージへの オブジェクトを追加します。
Bless the referred-to item into package
main:bless $ref, "";If the second argument is an empty string,
blessadds the object to packagemain.2 番目の引数が空文字列の場合、
blessはパッケージmainへの オブジェクトを追加します。Bless the referred-to item into the current package (not inheritable):
bless $ref;If
blessis used without its second argument, the object is created in the current package. The second argument should always be supplied if a derived class might inherit a method executingbless. Because it is a potential source of bugs, one-argumentblessis discouraged.2 番目の引数なしで
blessを使うと、オブジェクトは 現在のパッケージ内に作成されます。 派生クラスがblessを実行するメソッドを継承する可能性がある場合は、 2 番目の引数を常に指定する必要があります。 これは潜在的なバグの元なので、引数が一つのblessは 推奨されません。
See perlobj for more about the blessing (and blessings) of objects.
オブジェクトの bless についてのさらなる情報については perlobj を参照してください。
blessreturns its first argument, the supplied reference, as the value of the function; sinceblessis commonly the last thing executed in constructors, this means that the reference to the object is returned as the constructor's value and allows the caller to immediately use this returned object in method calls.blessは、最初の引数である指定された 参照を関数の値として返します。blessは通常、コンストラクタで最後に実行されるため、 オブジェクトへの参照がコンストラクタの値として返され、 呼び出し側はこの返されたオブジェクトをメソッド呼び出しで すぐに使用できます。CLASSNAMEshould always be a mixed-case name, as all-uppercase and all-lowercase names are meant to be used only for Perl builtin types and pragmas, respectively. Avoid creating all-uppercase or all-lowercase package names to prevent confusion.すべて大文字の名前とすべて小文字の名前は、それぞれ Perl の 組み込み型とプラグマにのみ使われるため、
CLASSNAMEは 常に大文字と小文字が混在した名前にする必要があります。 混乱を避けるために、すべて大文字またはすべて小文字の パッケージ名は作成しないでください。Also avoid
blessing things into the class name0; this will cause code which (erroneously) checks the result ofrefto see if a reference isblessed to fail, as "0", a false value, is returned.また、クラス名
0に何かをblessすることも避けてください; これにより、 参照がblessされているかどうかを確認するために(誤って)refの結果をチェックするコードが失敗する原因となります; 偽の値である「0」が返されるためです。See "Perl Modules" in perlmod for more details.
さらなる詳細については "Perl Modules" in perlmod を参照してください。