perl-5.38.0
use Module VERSION LIST
use Module VERSION
use Module LIST
use Module

Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to

指定したモジュールから、現在のパッケージにさまざまな内容をインポートします; 多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、 実現されています。 これは、以下は等価ですが:

    BEGIN { require Module; Module->import( LIST ); }

except that Module must be a bareword. The importation can be made conditional by using the if module.

Module が 裸の単語でなければならない ことを除けば、です。 インポートは、if を使って条件付きで行うことができます。

The BEGIN forces the require and import to happen at compile time. The require makes sure the module is loaded into memory if it hasn't been yet. The import is not a builtin; it's just an ordinary static method call into the Module package to tell the module to import the list of features back into the current package. The module can implement its import method any way it likes, though most modules just choose to derive their import method via inheritance from the Exporter class that is defined in the Exporter module. See Exporter. If no import method can be found, then the call is skipped, even if there is an AUTOLOAD method.

BEGIN によって、requireimport は、コンパイル時に 実行されることになります。 require は、モジュールがまだメモリに ロードされていなければ、ロードします。 import は、組込みの関数ではありません; さまざまな機能を 現在のパッケージにインポートするように Module パッケージに伝えるために 呼ばれる、通常の静的メソッドです。 モジュール側では、import メソッドをどのようにでも 実装することができますが、多くのモジュールでは、 Exporter モジュールで定義された、 Exporter クラスからの継承によって、import メソッドを 行なうようにしています。 Exporterモジュールを参照してください。 importメソッドが見つからなかった場合、AUTOLOAD メソッドが あったとしても呼び出しはスキップされます。

If you do not want to call the package's import method (for instance, to stop your namespace from being altered), explicitly supply the empty list:

パッケージの import メソッドを呼び出したくない場合(例えば、 名前空間を変更したくない場合など)は、明示的に空リストを指定してください:

    use Module ();

That is exactly equivalent to

これは以下と完全に等価です:

    BEGIN { require Module }

If the VERSION argument is present between Module and LIST, then the use will call the VERSION method in class Module with the given version as an argument:

Module と LIST の間に VERSION 引数がある場合、 use は Module クラスの VERSION メソッドを、与えられたバージョンを引数として呼び出します:

    use Module 12.34;

is equivalent to:

は以下と等価です:

    BEGIN { require Module; Module->VERSION(12.34) }

The default VERSION method, inherited from the UNIVERSAL class, croaks if the given version is larger than the value of the variable $Module::VERSION.

デフォルトの default VERSION メソッド は、 UNIVERSAL クラスから継承したもので、 与えられたバージョンが 変数 $Module::VERSION の値より大きい場合に 警告を出します。

The VERSION argument cannot be an arbitrary expression. It only counts as a VERSION argument if it is a version number literal, starting with either a digit or v followed by a digit. Anything that doesn't look like a version literal will be parsed as the start of the LIST. Nevertheless, many attempts to use an arbitrary expression as a VERSION argument will appear to work, because Exporter's import method handles numeric arguments specially, performing version checks rather than treating them as things to export.

VERSION 引数は任意の式ではありません。 VERSION 引数が数値または v に引き続いて数値であるバージョン番号リテラルの 場合にのみ扱われます。 バージョンリテラルのように見えないものは LIST の開始としてパースされます。 それにも関わらず、VERSION 引数として任意の式を使おうとする 多くの試みは動作しているように見えます; なぜなら Exporterimport メソッドは数値引数を特別に扱い、 それらをエクスポートするべきものと扱わずにバージョンチェックを 実行するからです。

Again, there is a distinction between omitting LIST (import called with no arguments) and an explicit empty LIST () (import not called). Note that there is no comma after VERSION!

繰り返すと、LIST を省略する(import が引数なしで 呼び出される)ことと明示的に空の LIST () を指定する (import は呼び出されない)ことは違います。 VERSION の後ろにカンマが不要なことに注意してください!

Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. Some of the currently implemented pragmas are:

これは、広く公開されているインタフェースですので、 プラグマ (コンパイラディレクティブ) も、この方法で実装されています。 現在実装されているプラグマには、以下のようなものがあります:

    use constant;
    use diagnostics;
    use integer;
    use sigtrap  qw(SEGV BUS);
    use strict   qw(subs vars refs);
    use subs     qw(afunc blurfl);
    use warnings qw(all);
    use sort     qw(stable);

Some of these pseudo-modules import semantics into the current block scope (like strict or integer, unlike ordinary modules, which import symbols into the current package (which are effective through the end of the file).

通常のモジュールが、現在のパッケージにシンボルをインポートする (これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの 一部(strictinteger など)は、現在の ブロックスコープにインポートを行ないます。

Because use takes effect at compile time, it doesn't respect the ordinary flow control of the code being compiled. In particular, putting a use inside the false branch of a conditional doesn't prevent it from being processed. If a module or pragma only needs to be loaded conditionally, this can be done using the if pragma:

use はコンパイル時に有効なので、コードが コンパイルされる際の通常の流れ制御には従いません。 特に、条件文のうち成立しない側の中に use を 書いても、処理を妨げられません。 モジュールやプラグマを条件付きでのみ読み込みたい場合、 if プラグマを使って実現できます:

    use if $] < 5.008, "utf8";
    use if WANT_WARNINGS, warnings => qw(all);

There's a corresponding no declaration that unimports meanings imported by use, i.e., it calls Module->unimport(LIST) instead of import. It behaves just as import does with VERSION, an omitted or empty LIST, or no unimport method being found.

これに対して、no 宣言という、 use によってインポートされたものを、 インポートされていないことにするものがあります; つまり、 import の代わりに Module->unimport(LIST) を呼び出します。 これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない 場合などの観点では、import と同様に振る舞います。

    no integer;
    no strict 'refs';
    no warnings;

See perlmodlib for a list of standard modules and pragmas. See perlrun for the -M and -m command-line options to Perl that give use functionality from the command-line.

標準モジュールやプラグマの一覧は、perlmodlib を参照してください。 コマンドラインから use 機能を 指定するための -M-m の コマンドラインオプションについては perlrun を参照してください。

use VERSION

Lexically enables all features available in the requested version as defined by the feature pragma, disabling any features not in the requested version's feature bundle. See feature.

feature プラグマで定義された、指定されたバージョンで利用可能な 全ての機能を有効にし、指定されたバージョンの機能の束で要求されていない 全ての機能を無効にします。 feature を参照してください。

VERSION may be either a v-string such as v5.24.1, which will be compared to $^V (aka $PERL_VERSION), or a numeric argument of the form 5.024001, which will be compared to $]. An exception is raised if VERSION is greater than the version of the current Perl interpreter; Perl will not attempt to parse the rest of the file. Compare with require, which can do a similar check at run time.

VERSION は v5.24.1 のような v-文字列 ($^V (またの名を $PERL_VERSION) と比較されます) か、5.024001 の形の数値形式 ($] と比較されます) で 指定します。 VERSION が Perl の現在のバージョンより大きいと、例外が発生します; Perl はファイルの残りを読み込みません。 require と似ていますが、これは実行時に チェックされます。

If the specified Perl version is 5.12 or higher, strictures are enabled lexically as with use strict. Similarly, if the specified Perl version is 5.35.0 or higher, warnings are enabled. Later use of use VERSION will override all behavior of a previous use VERSION, possibly removing the strict, warnings, and feature added by it. use VERSION does not load the feature.pm, strict.pm, or warnings.pm files.

指定された Perl のバージョンが 5.12 以上の場合、 use strict と同様に、strict 機能がレキシカルに有効になります。 同様に、指定された Perl のバージョンが 5.35.0 以上の場合、 warnings が有効になります。 後から使った use VERSION は先の use VERSION の全ての振る舞いを上書きするので、 それによって追加された strict, feature, feature を 削除することがあります。 use VERSIONfeature.pm, strict.pm, warnings.pm ファイルは 読み込みません。

In the current implementation, any explicit use of use strict or no strict overrides use VERSION, even if it comes before it. However, this may be subject to change in a future release of Perl, so new code should not rely on this fact. It is recommended that a use VERSION declaration be the first significant statement within a file (possibly after a package statement or any amount of whitespace or comment), so that its effects happen first, and other pragmata are applied after it.

現在の実装では、明示的に use strictno strict を使うと、例え先に 指定されていたとしても、use VERSION を上書きします。 しかし、これは将来のリリースの Perl で変更されるかもしれないので、 新しいコードはこの事実に依存するべきではありません。 (場合によっては package 文や任意の量の空白やコメントの後の)ファイルの 最初の有効な文として use VERSION 宣言することを勧めます; この機能が最初に怒り、その他のプラグマはその後に適用されるからです。

Specifying VERSION as a numeric argument of the form 5.024001 should generally be avoided as older less readable syntax compared to v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric form was the only supported syntax, which is why you might see it in older code.

VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです; v5.24.1 に比べてより古く読みにくい文法だからです。 (2002 年にリリースされた) perl 5.8.0 より前では、より冗長な 数値形式が唯一対応している文法でした; これが古いコードでこれを 見るかも知れない理由です。

    use v5.24.1;    # compile time version check
    use 5.24.1;     # ditto
    use 5.024_001;  # ditto; older syntax compatible with perl 5.6
    use v5.24.1;    # 実行時バージョンチェック
    use 5.24.1;     # 同様
    use 5.024_001;  # 同様; perl 5.6 と互換性のある古い文法

This is often useful if you need to check the current Perl version before useing library modules that won't work with older versions of Perl. (We try not to do this more than we have to.)

これは古いバージョンの Perl で動かなくなったライブラリモジュールを use する前に、現在の Perl のバージョンを 調べたい場合に有用です。 (我々は必要な場合以外にそのようなことがないように努力していますが。)

Symmetrically, no VERSION allows you to specify that you want a version of Perl older than the specified one. Historically this was added during early designs of the Raku language (formerly "Perl 6"), so that a Perl 5 program could begin

対称的に、no VERSION は指定されたバージョンより古いバージョンの Perl で 動作させたいことを意味します。 歴史的には、これは Raku 言語 (以前は "Perl 6") の初期仕様で加えられたので、 Perl 5 のプログラムは次のもので始めて:

    no 6;

to declare that it is not a Perl 6 program. As the two languages have different implementations, file naming conventions, and other infrastructure, this feature is now little used in practice and should be avoided in newly-written code.

Perl 6 プログラムでないことを宣言できました。 二つの言語は異なる実装、命名規則、およびその他のインフラを持つので、 今ではこの機能は実際にはほとんど使われておらず、新しいコードでは 避けるべきです。

Care should be taken when using the no VERSION form, as it is only meant to be used to assert that the running Perl is of a earlier version than its argument and not to undo the feature-enabling side effects of use VERSION.

no VERSION 形式を使うときには注意を払うべきです; これは引数で指定されたバージョンよりも前の Perl で実行されたときに アサートされることを意味する だけ で、use VERSION によって 有効にされた副作用をなかったことにするもの ではありません