=pod =head1 NAME UNIVERSAL::require - require() modules from a variable UNIVERSAL::require - 変数からのrequire()モジュール =head1 SYNOPSIS # This only needs to be said once in your program. # あなたのプログラム中に唯一一度だけ宣言する必要があります。 require UNIVERSAL::require; # Same as "require Some::Module" # "require Some::Module"と同じことです。 my $module = 'Some::Module'; $module->require or die $@; # Same as "use Some::Module" # "use Some::Module"と同じことです。 BEGIN { $module->use or die $@ } =head1 DESCRIPTION If you've ever had to do this... あなたが今までこのようなことをしなければならなかったのならば・・・ eval "require $module"; to get around the bareword caveats on require(), this module is for you. It creates a universal require() class method that will work with every Perl module and its secure. So instead of doing some arcane eval() work, you can do this: このモジュールはあなたの為に、require()のbareword警告を逃れるようにします それは全てのPerlモジュールで利用できるrequire()クラスメソッドを作成し、そしてそれは安全です。 そして、理解しにくいeval()を使う代わりに、あなたはこのようにすることができます: $module->require; It doesn't save you much typing, but it'll make alot more sense to someone who's not a ninth level Perl acolyte. これはより少ない入力ですませることはないですが、しかしそれは ある誰かにより多くの意味を持たせることができます、その誰かは第9レベルのPerl使用者ではないのですから。 =head1 Methods =head3 require my $return_val = $module->require or die $@; my $return_val = $module->require($version) or die $@; This works exactly like Perl's require, except without the bareword restriction, and it doesn't die. Since require() is placed in the UNIVERSAL namespace, it will work on B module. You just have to use UNIVERSAL::require somewhere in your code. barewordの制限が無い事を除いて、この例はまさにPerlのrequireと同じように動作します、そしてそれはdieしません。 require()がUNIVERSALの名前空間に配置されるので、それはBモジュールに働きかけるでしょう。 あなたはコードのどこかでUNIVERSAL::requireを使用しなければなりません。 Should the module require fail, or not be a high enough $version, it will simply return false and B. The error will be in $@ as well as $UNIVERSAL::require::ERROR. モジュールのrequireの失敗、または$versionよりも十分高いバージョンで無い場合はただ単純にBfalseを返すべきです。 エラーは$UNIVERSAL::require::ERRORと同じものが$@にも格納されています。 $module->require or die $@; =head3 use my $require_return = $module->use or die $@; my $require_return = $module->use(@imports) or die $@; Like C, this allows you to C a $module without having to eval to work around the bareword requirement. It returns the same as require. Cと同じように、これはあなたが$moduleをbarewordを必要とするevalを使用せずにCすることを可能にします。 これはrequireと同じようにリターンします。 Should either the require or the import fail it will return false. The error will be in $@. requireかimportのどちらかが失敗するとそれはfalseをリターンするでしょう。 エラーは$@に格納されます。 If possible, call this inside a BEGIN block to emulate a normal C as closely as possible. できれば、BEGINブロックの中でできるだけきっちり標準Cをまねて呼び出してください。 BEGIN { $module->use } =head1 SECURITY NOTES UNIVERSAL::require makes use of C. In previous versions of UNIVERSAL::require it was discovered that one could craft a class name which would result in code being executed. This hole has been closed. The only variables now exposed to C are the caller's package, filename and line which are not tainted. UNIVERSAL::requireはCを利用します。 旧バージョンのUNIVERSAL::requireでは、コードが実行されるクラス名を作ることができると発見されました。 この穴は閉じられました。 現在、Cにさらされる唯一の変数は汚染されていない呼び出し元のパッケージとファイル名と線です。 UNIVERSAL::require is taint clean. UNIVERSAL::requireは汚染されておらずクリーンです。 =head1 COPYRIGHT Copyright 2001, 2005 by Michael G Schwern Eschwern@pobox.comE. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F =head1 AUTHOR Michael G Schwern =head1 SEE ALSO L, L, L