=encoding euc-jp =head1 NAME =begin original AutoLoader - load subroutines only on demand =end original AutoLoader - 要求に応じてのみサブルーチンを読み込む =head1 SYNOPSIS =begin original package Foo; use AutoLoader 'AUTOLOAD'; # import the default AUTOLOAD subroutine =end original package Foo; use AutoLoader 'AUTOLOAD'; # デフォルトの AUTOLOAD サブルーチンを読み込む =begin original package Bar; use AutoLoader; # don't import AUTOLOAD, define our own sub AUTOLOAD { ... $AutoLoader::AUTOLOAD = "..."; goto &AutoLoader::AUTOLOAD; } =end original package Bar; use AutoLoader; # AUTOLOAD をインポートせずに自身のものを定義する sub AUTOLOAD { ... $AutoLoader::AUTOLOAD = "..."; goto &AutoLoader::AUTOLOAD; } =head1 DESCRIPTION =begin original The B module works with the B module and the C<__END__> token to defer the loading of some subroutines until they are used rather than loading them all at once. =end original B モジュールは、B モジュールと C<__END__> トークンと ともに動作し、サブルーチンすべてを一度に読み込むのではなくて、 使われるまでサブルーチンの読み込みを延期します。 =begin original To use B, the author of a module has to place the definitions of subroutines to be autoloaded after an C<__END__> token. (See L.) The B module can then be run manually to extract the definitions into individual files F. =end original B を使うために、モジュールの作者は、自動的に読み込む サブルーチンの定義を C<__END__> トークンの後に置く必要があります。 (L を見てください。) B モジュールを手動で走らせると、定義を個々の F ファイルに抜きだします。 =begin original B implements an AUTOLOAD subroutine. When an undefined subroutine in is called in a client module of B, B's AUTOLOAD subroutine attempts to locate the subroutine in a file with a name related to the location of the file from which the client module was read. As an example, if F is located in F, B will look for perl subroutines B in F, where the C<.al> file has the same name as the subroutine, sans package. If such a file exists, AUTOLOAD will read and evaluate it, thus (presumably) defining the needed subroutine. AUTOLOAD will then C the newly defined subroutine. =end original B は、AUTOLOAD サブルーチンを実装します。 未定義のサブルーチンが、B のクライアントモジュールで 呼び出されると、B の AUTOLOAD サブルーチンは、 クライアントモジュールが読まれたそのファイルの位置に関係する名前で、 ファイル中のサブルーチンを見つけようとします。 例えば、F が F にあると、 B は perl の B のサブルーチンを F から探します; C<.al> ファイルは、パッケージ名なしのサブルーチンと同じ名前です。 そのようなファイルがあれば、AUTOLOAD はそれを読んで評価します; このようにして、(おそらく)必要とされるサブルーチンを定義します。 それから、AUTOLOAD は新たに定義されたサブルーチンへ C します。 =begin original Once this process completes for a given function, it is defined, so future calls to the subroutine will bypass the AUTOLOAD mechanism. =end original その関数のためにこの処理が一旦実行されると、これは定義され、 以後のサブルーチンの呼び出しは AUTOLOAD の機構を飛ばします。 =head2 Subroutine Stubs (サブルーチンスタブ) =begin original In order for object method lookup and/or prototype checking to operate correctly even when methods have not yet been defined it is necessary to "forward declare" each subroutine (as in C). See L. Such forward declaration creates "subroutine stubs", which are place holders with no code. =end original メソッドがまだ定義されていないときにでもオブジェクトメソッドの調査や プロトタイプチェックを正確に行うために、 それぞれのサブルーチンを(C のように)、 「前方宣言」する必要があります。 L を見てください。 このような前方宣言は、「サブルーチンスタブ」を作ります; これは、コード無しのプレースホルダです。 =begin original The AutoSplit and B modules automate the creation of forward declarations. The AutoSplit module creates an 'index' file containing forward declarations of all the AutoSplit subroutines. When the AutoLoader module is 'use'd it loads these declarations into its callers package. =end original AutoSplit と、B モジュールは前方宣言の作成を自動化します。 AutoSplit モジュールは、'index' ファイルを作り、そこに AutoSplit が分割したすべてのサブルーチンの前方宣言を置きます。 AutoLoader モジュールが 'use' されると、その呼び出し元パッケージに それらの定義を読み込みます。 =begin original Because of this mechanism it is important that B is always Cd and not Cd. =end original この機構のため、B は常に C され、 C されないということが重要です。 =head2 Using B's AUTOLOAD Subroutine (B の AUTOLOAD サブルーチンを使う) =begin original In order to use B's AUTOLOAD subroutine you I explicitly import it: =end original B の AUTOLOAD サブルーチンを使うに、 明示的にそれをインポート I<しなければなりません>。 use AutoLoader 'AUTOLOAD'; =head2 Overriding B's AUTOLOAD Subroutine (B's AUTOLOAD サブルーチンをオーバーロードする) =begin original Some modules, mainly extensions, provide their own AUTOLOAD subroutines. They typically need to check for some special cases (such as constants) and then fallback to B's AUTOLOAD for the rest. =end original いくつかのモジュール、主にエクステンションは、自分自身の AUTOLOAD サブルーチンをもっています。 それらは典型的に、(定数のような)いくつかの特別な場合のために チェックする必要があり、 それから、残りの作業のために B の AUTOLOAD に フォールバックする必要があります。 =begin original Such modules should I import B's AUTOLOAD subroutine. Instead, they should define their own AUTOLOAD subroutines along these lines: =end original このようなモジュールは B の AUTOLOAD サブルーチンを インポートすべきでは I<ありません>。 そのかわりに、そのようなモジュールは、次のように、自分自身の AUTOLOAD サブルーチンを定義すべきです; use AutoLoader; use Carp; sub AUTOLOAD { my $sub = $AUTOLOAD; (my $constname = $sub) =~ s/.*:://; my $val = constant($constname, @_ ? $_[0] : 0); if ($! != 0) { if ($! =~ /Invalid/ || $!{EINVAL}) { $AutoLoader::AUTOLOAD = $sub; goto &AutoLoader::AUTOLOAD; } else { croak "Your vendor has not defined constant $constname"; } } *$sub = sub { $val }; # same as: eval "sub $sub { $val }"; goto &$sub; } =begin original If any module's own AUTOLOAD subroutine has no need to fallback to the AutoLoader's AUTOLOAD subroutine (because it doesn't have any AutoSplit subroutines), then that module should not use B at all. =end original (AutoSplit するサブルーチンを全くもっていないために)、モジュールの AUTOLOAD サブルーチンが、 AutoLoader の AUTOLOAD サブルーチンにフォールバックする必要がなければ、 そのモジュールは B を、全く使わないべきです。 =head2 Package Lexicals (パッケージレキシカル) =begin original Package lexicals declared with C in the main block of a package using B will not be visible to auto-loaded subroutines, due to the fact that the given scope ends at the C<__END__> marker. A module using such variables as package globals will not work properly under the B. =end original B を使っているパッケージの main ブロックで、 C で宣言されたパッケージレキシカルの変数は、自動的に読み込まれた サブルーチンには見えません; これは、与えられたスコープが C<__END__> マーカーで終るという事実によります。 そのような変数をパッケージのグローバル変数のように使っているモジュールは、 B のもとでは、うまく動きません。 =begin original The C pragma (see L) may be used in such situations as an alternative to explicitly qualifying all globals with the package namespace. Variables pre-declared with this pragma will be visible to any autoloaded routines (but will not be invisible outside the package, unfortunately). =end original C プラグマ(L を見てください)が、こういった状況で、 パッケージの名前空間で明示的に完全修飾したグローバル変数に変わるものとして、 使えます。 このプラグマで先に宣言された変数は、どのような、自動的に 読み込まれるルーチンにも見えます (しかし、残念ながら、パッケージの外側からは見えません。) =head2 Not Using AutoLoader (AutoLoaderを使わない) =begin original You can stop using AutoLoader by simply =end original AutoLoader を使わなくするには、単純に次のようにします: no AutoLoader; =head2 B vs. B =begin original The B is similar in purpose to B: both delay the loading of subroutines. =end original B は、B の目的と類似性があります: 両方ともサブルーチンの読み込みを遅らせるものです。 =begin original B uses the C<__DATA__> marker rather than C<__END__>. While this avoids the use of a hierarchy of disk files and the associated open/close for each routine loaded, B suffers a startup speed disadvantage in the one-time parsing of the lines after C<__DATA__>, after which routines are cached. B can also handle multiple packages in a file. =end original B は、C<__END__> ではなくて、C<__DATA__> マーカーを使います。 このことにより、それぞれのルーチンを読み込むために、 ディスクファイルの階層を使い、関連する open/close を避ける一方で、 B は、ルーチンがキャッシュされた後、C<__DATA__> を一度 パースするので、起動速度の不利を被ります。 また、B は一つのファイルで複数のパッケージを取り扱えます。 =begin original B only reads code as it is requested, and in many cases should be faster, but requires a mechanism like B be used to create the individual files. L will invoke B automatically if B is used in a module source file. =end original B は、要求されたときにだけコードを読みます; 多く場合、これはより高速です; しかし、独立したファイルを作成するのに使われる B のような機構を必要とします。 B がモジュールのソースファイルで使われると、 L は B を自動的に呼び出します。 =head1 CAVEATS =begin original AutoLoaders prior to Perl 5.002 had a slightly different interface. Any old modules which use B should be changed to the new calling style. Typically this just means changing a require to a use, adding the explicit C<'AUTOLOAD'> import if needed, and removing B from C<@ISA>. =end original Perl 5.002 より前の AutoLoader は、少し違ったインターフェースでした。 B を使っている古いモジュールは、 新しいスタイルの呼び出しに変更するべきです。 一般に、このことは、次のことを意味します; require を use に変えること、必要なら明示的な C<'AUTOLOAD'> のインポートを 加えること、@ISA から B を削除することです。 =begin original On systems with restrictions on file name length, the file corresponding to a subroutine may have a shorter name that the routine itself. This can lead to conflicting file names. The I package warns of these potential conflicts when used to split a module. =end original システムに、ファイル名の長さに関する制限があると、 ファイルとサブルーチンの一致のために、ルーチン自身より より短い名前になるかもしれません。 このことは、ファイル名の衝突を引き起こすかも知れません。 I パッケージは、モジュールを分割するときに、 こういった潜在的な衝突を警告します。 =begin original AutoLoader may fail to find the autosplit files (or even find the wrong ones) in cases where C<@INC> contains relative paths, B the program does C. =end original C<@INC> の中に相対パスがあり、B<かつ> プログラムが C した場合、 AutoLoader は、自動的に分割されたファイルを見付けるのに失敗するかも知れません (または、間違ったファイルを見つけるかも知れません)。 =head1 SEE ALSO L - 外部ファイルを使わないオートローダー =head1 AUTHOR C is maintained by the perl5-porters. Please direct any questions to the canonical mailing list. Anything that is applicable to the CPAN release can be sent to its maintainer, though. Author and Maintainer: The Perl5-Porters Maintainer of the CPAN release: Steffen Mueller =head1 COPYRIGHT AND LICENSE This package has been part of the perl core since the first release of perl5. It has been released separately to CPAN so older installations can benefit from bug fixes. This package has the same copyright and license as the perl core: Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" which comes with this Kit. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details. You should have received a copy of the Artistic License with this Kit, in the file named "Artistic". If not, I'll be glad to provide one. You should also have received a copy of the GNU General Public License along with this program in the file named "Copying". If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA or visit their web page on the internet at http://www.gnu.org/copyleft/gpl.html. For those of you that choose to use the GNU General Public License, my interpretation of the GNU General Public License is that no Perl script falls under the terms of the GPL unless you explicitly put said script under the terms of the GPL yourself. Furthermore, any object code linked with perl does not automatically fall under the terms of the GPL, provided such object code only adds definitions of subroutines and variables, and does not otherwise impair the resulting interpreter from executing any standard Perl script. I consider linking in C subroutines in this manner to be the moral equivalent of defining subroutines in the Perl language itself. You may sell such an object file as proprietary provided that you provide or offer to provide the Perl source, as specified by the GNU General Public License. (This is merely an alternate way of specifying input to the program.) You may also sell a binary produced by the dumping of a running Perl script that belongs to you, provided that you provide or offer to provide the Perl source as specified by the GPL. (The fact that a Perl interpreter and your code are in the same binary file is, in this case, a form of mere aggregation.) This is my interpretation of the GPL. If you still have concerns or difficulties understanding my intent, feel free to contact me. Of course, the Artistic License spells all this out for your protection, so you may prefer to use that. =begin meta Update: Kentaro Shirakata (5.68) =end meta =cut