perl-5.38.0
package NAMESPACE
package NAMESPACE VERSION
package NAMESPACE BLOCK
package NAMESPACE VERSION BLOCK

Declares the BLOCK or the rest of the compilation unit as being in the given namespace. The scope of the package declaration is either the supplied code BLOCK or, in the absence of a BLOCK, from the declaration itself through the end of current scope (the enclosing block, file, or eval). That is, the forms without a BLOCK are operative through the end of the current scope, just like the my, state, and our operators. All unqualified dynamic identifiers in this scope will be in the given namespace, except where overridden by another package declaration or when they're one of the special identifiers that qualify into main::, like STDOUT, ARGV, ENV, and the punctuation variables.

BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。 パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から 現在のスコープの末尾 (閉じたブロック、ファイル、eval) です。 つまり、BLOCK なしの形式は、my, state, our 演算子と同様に現在のスコープの末尾にまで作用します。 このスコープ内の、全ての完全修飾されていない動的識別子は、他の package 宣言によって上書きされるか、 STDOUT, ARGV, ENV や句読点変数のように main:: に 割り当てられる特殊変数でない限り、指定された 名前空間になります。

A package statement affects dynamic variables only, including those you've used local on, but not lexically-scoped variables, which are created with my, state, or our. Typically it would be the first declaration in a file included by require or use. You can switch into a package in more than one place, since this only determines which default symbol table the compiler uses for the rest of that block. You can refer to identifiers in other packages than the current one by prefixing the identifier with the package name and a double colon, as in $SomePack::var or ThatPack::INPUT_HANDLE. If package name is omitted, the main package is assumed. That is, $::sail is equivalent to $main::sail (as well as to $main'sail, still seen in ancient code, mostly from Perl 4).

package 文は動的変数にのみ影響します(local で使ったものも 含みます)が、my, state, our のいずれかで作成された レキシカルなスコープの変数には 影響しません。 典型的にはこれは requireuse 演算子でインクルードされるファイルの 最初に宣言されます。 パッケージを複数の場所で切り替えることができます; なぜならこれは単にコンパイラがこのブロックの残りに対してどの シンボルテーブルを使うかにのみ影響するからです。 他のパッケージの識別子は、$SomePack::varThatPack::INPUT_HANDLE のように、識別子にパッケージ名と コロン二つをつけることで参照できます。 パッケージ名が省略された場合、main パッケージが仮定されます。 つまり、$::sail$main::sail と等価です(ほとんどは Perl 4 からの、 古いコードでは $main'sail もまだ見られます)。

If VERSION is provided, package sets the $VERSION variable in the given namespace to a version object with the VERSION provided. VERSION must be a "strict" style version number as defined by the version module: a positive decimal number (integer or decimal-fraction) without exponentiation or else a dotted-decimal v-string with a leading 'v' character and at least three components. You should set $VERSION only once per package.

VERSION が指定されると、package は与えられた 名前空間の $VERSION 変数に、 指定された VERSION の version オブジェクトをセットします。 VERSION は version で定義されている「厳密な」形式のバージョン番号で なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、 さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から 構成されるドット付き 10 進v-文字列です。 $VERSION はパッケージ毎に 1 回だけセットするべきです。

See "Packages" in perlmod for more information about packages, modules, and classes. See perlsub for other scoping issues.

パッケージ、モジュール、クラスに関するさらなる情報については "Packages" in perlmod を参照してください。 その他のスコープに関する話題については perlsub を参照してください。