=encoding euc-jp =head1 NAME =begin original feature - Perl pragma to enable new features =end original feature - 新しい機能を有効にするプラグマ =head1 SYNOPSIS use feature qw(say switch); given ($foo) { when (1) { say "\$foo == 1" } when ([2,3]) { say "\$foo == 2 || \$foo == 3" } when (/^a[bc]d$/) { say "\$foo eq 'abd' || \$foo eq 'acd'" } when ($_ > 100) { say "\$foo > 100" } default { say "None of the above" } } use feature ':5.10'; # loads all features available in perl 5.10 use v5.10; # implicitly loads :5.10 feature bundle =head1 DESCRIPTION =begin original It is usually impossible to add new syntax to Perl without breaking some existing programs. This pragma provides a way to minimize that risk. New syntactic constructs, or new semantic meanings to older constructs, can be enabled by C, and will be parsed only when the appropriate feature pragma is in scope. (Nevertheless, the C prefix provides access to all Perl keywords, regardless of this pragma.) =end original 既に存在しているプログラムを壊すことなく、Perl に新しい文法を追加することは、 普通は不可能です。 このプラグマは、リスクを最小化する方法を提供します。 新しい文法構造や、古い構造の新しい意味は、C で有効化され、 適切な feature プラグマがスコープ内にある場合にのみパースされます。 (それでも、このプラグマに関わらず、C 接頭辞は全ての Perl キーワードへのアクセスを提供します。) =head2 Lexical effect (レキシカルな効果) =begin original Like other pragmas (C, for example), features have a lexical effect. C will only make the feature "foo" available from that point to the end of the enclosing block. =end original (例えば C のような) その他のプラグマと同様、feature は レキシカルな効果を持ちます。 C は、この地点からブロックの終わりまでの間だけ、 "foo" 機能を利用可能にします。 { use feature 'say'; say "say is available here"; } print "But not here.\n"; =head2 C =begin original Features can also be turned off by using C. This too has lexical effect. =end original 機能は C を使うことで無効にすることも出来ます。 これもまたレキシカルな効果を持ちます。 use feature 'say'; say "say is available here"; { no feature 'say'; print "But not here.\n"; } say "Yet it is here."; =begin original C with no features specified will reset to the default group. To disable I features (an unusual request!) use C. =end original C と、機能を指定せずに使うと、デフォルトグループにリセットします。 I<全ての> 機能を無効にする(普通でない要求!)には、C を 使ってください。 =head1 AVAILABLE FEATURES (利用可能な機能) =head2 The 'say' feature ('say' 機能) =begin original C tells the compiler to enable the Perl 6 style C function. =end original C は、コンパイラに Perl 6 形式の C 関数を 有効にするように伝えます。 =begin original See L for details. =end original 詳しくは L を参照してください。 =begin original This feature is available starting with Perl 5.10. =end original この機能は Perl 5.10 から利用可能です。 =head2 The 'state' feature ('state' 機能) =begin original C tells the compiler to enable C variables. =end original C は、コンパイラに C 変数を有効にするように 伝えます。 =begin original See L for details. =end original 詳しくは L を参照してください。 =begin original This feature is available starting with Perl 5.10. =end original この機能は Perl 5.10 から利用可能です。 =head2 The 'switch' feature ('switch' 機能) =begin original B: Because the L is experimental, Perl will warn when you use this feature, unless you have explicitly disabled the warning: =end original B: L<スマートマッチング演算子|perlop/"Smartmatch Operator"> は 実験的なので、この機能を使うと、明示的に無効にしない限り警告が発生します: no warnings "experimental::smartmatch"; =begin original C tells the compiler to enable the Perl 6 given/when construct. =end original C は、コンパイラに Perl 6 given/when 構文を 有効にするように伝えます。 =begin original See L for details. =end original 詳しくは L を参照してください。 =begin original This feature is available starting with Perl 5.10. =end original この機能は Perl 5.10 から利用可能です。 =head2 The 'unicode_strings' feature ('unicode_strings' 機能) =begin original C tells the compiler to use Unicode rules in all string operations executed within its scope (unless they are also within the scope of either C or C). The same applies to all regular expressions compiled within the scope, even if executed outside it. It does not change the internal representation of strings, but only how they are interpreted. =end original C は、(C か C の スコープないでない限り) そのスコープ内で実行される全ての文字列操作に Unicode の規則を使うようにコンパイラに伝えます。 これは文字列の内部表現は変更しません; それをどう解釈するかだけです。 =begin original C tells the compiler to use the traditional Perl rules wherein the native character set rules is used unless it is clear to Perl that Unicode is desired. This can lead to some surprises when the behavior suddenly changes. (See L for details.) For this reason, if you are potentially using Unicode in your program, the C subpragma is B recommended. =end original C は、Unicode が求められているのが Perl にとって明らかでない限り、ネイティブな文字集合規則が使われるところで 伝統的な Perl の規則を使うようにコンパイラに伝えます。 これは、振る舞いが突然変更されたときに驚きを引き起こすかもしれません。 (詳しくは L を参照してください。) この理由により、もしプログラムで Unicode を扱う可能性があるなら、 C 副プラグマを B<強く> 勧めます。 =begin original This feature is available starting with Perl 5.12; was almost fully implemented in Perl 5.14; and extended in Perl 5.16 to cover C. =end original この機能は Perl 5.12 から利用可能になりました; Perl 5.14 でほぼ完全に 実装されました; Perl 5.16 で C に対応するように拡張されました。 =head2 The 'unicode_eval' and 'evalbytes' features ('unicode_eval' と 'evalbytes' 機能) =begin original Under the C feature, Perl's C function, when passed a string, will evaluate it as a string of characters, ignoring any C declarations. C exists to declare the encoding of the script, which only makes sense for a stream of bytes, not a string of characters. Source filters are forbidden, as they also really only make sense on strings of bytes. Any attempt to activate a source filter will result in an error. =end original C 機能の基では、Perl の C 関数に文字列が渡されると、 文字の文字列として評価し、C 宣言を無視します。 C はスクリプトのエンコーディングを宣言するために存在し、 バイトの並びにのみ意味があり、文字の文字列では意味がありません。 ソースフィルタは禁止されます; これらもバイトの文字列に対してのみ 意味があるからです。 ソースフィルタを有効にしようとするあらゆる試みはエラーとなります。 =begin original The C feature enables the C keyword, which evaluates the argument passed to it as a string of bytes. It dies if the string contains any characters outside the 8-bit range. Source filters work within C: they apply to the contents of the string being evaluated. =end original C 機能は C キーワードを有効にします; これは引数として渡されたものをバイトの文字列として評価します。 文字列に 8 ビットの範囲の外側の文字が含まれていると die します。 ソースフィルタは C の中では動作します: これらは 評価される文字列の中身に対して適用されます。 =begin original Together, these two features are intended to replace the historical C function, which has (at least) two bugs in it, that cannot easily be fixed without breaking existing programs: =end original これら二つの機能は共に、歴史的な C 関数を置き換えることを 目的としています; これには(少なくとも)二つのバグがあり、既存のプログラムを 壊すことなく簡単に修正することができません: =over =item * =begin original C behaves differently depending on the internal encoding of the string, sometimes treating its argument as a string of bytes, and sometimes as a string of characters. =end original C は文字列音内部エンコーディングに依存して異なる振る舞いを行い、 時には引数をバイトの文字列として扱い、時には文字の文字列として扱います。 =item * =begin original Source filters activated within C leak out into whichever I scope is currently being compiled. To give an example with the CPAN module L: =end original C の中で有効にされたソースフィルタは、どの I スコープが コンパイルされているかについてリークします。 CPAN モジュールである L を例にします: BEGIN { eval "use Semi::Semicolons; # not filtered here " } # filtered here! =begin original C fixes that to work the way one would expect: =end original C は、想定通りに動作するように修正します: use feature "evalbytes"; BEGIN { evalbytes "use Semi::Semicolons; # filtered " } # not filtered =back =begin original These two features are available starting with Perl 5.16. =end original これら二つの機能は Perl 5.16 から利用可能です。 =head2 The 'current_sub' feature ('current_sub' 機能) =begin original This provides the C<__SUB__> token that returns a reference to the current subroutine or C outside of a subroutine. =end original これは C<__SUB__> トークンを提供します; これは現在のサブルーチンへの リファレンスか、サブルーチンの外側では C を返します。 =begin original This feature is available starting with Perl 5.16. =end original この機能は Perl 5.16 から利用可能です。 =head2 The 'array_base' feature ('array_base' 機能) =begin original This feature supports the legacy C<$[> variable. See L and L. It is on by default but disabled under C (see L, below). =end original この機能はレガシーな C<$[> 変数に対応します。 L と L を参照してください。 これはデフォルトではオンですが C (後述の L 参照) の基では無効になります。 =begin original This feature is available under this name starting with Perl 5.16. In previous versions, it was simply on all the time, and this pragma knew nothing about it. =end original この機能は Perl 5.16 からこの名前で利用可能です。 以前のバージョンでは、単に常時適用されていて、このプラグマはこれについて 何も知りませんでした。 =head2 The 'fc' feature ('fc' 機能) =begin original C tells the compiler to enable the C function, which implements Unicode casefolding. =end original C は、Unicode 畳み込みを実装した C 関数を 有効にするようにコンパイラに伝えます。 =begin original See L for details. =end original 詳しくは L を参照してください。 =begin original This feature is available from Perl 5.16 onwards. =end original この機能は Perl 5.16 から利用可能です。 =head2 The 'lexical_subs' feature ('lexical_subs' 機能) =begin original B: This feature is still experimental and the implementation may change in future versions of Perl. For this reason, Perl will warn when you use the feature, unless you have explicitly disabled the warning: =end original B<警告>: この機能はまだ実験的で、実装は将来のバージョンの Perl で 変わるかもしれません。 このため、この機能を使うと、明示的に無効にしない限り警告が発生します: no warnings "experimental::lexical_subs"; =begin original This enables declaration of subroutines via C, C and C syntax. See L for details. =end original これは、C, C, C 文法による サブルーチンの定義を有効にします。 詳しくは L を参照してください。 =begin original This feature is available from Perl 5.18 onwards. =end original この機能は Perl 5.18 から利用可能です。 =head2 The 'postderef' and 'postderef_qq' features ('postderef' と 'postderef_qq' 機能) =begin original The 'postderef_qq' feature extends the applicability of L so that postfix array and scalar dereference are available in double-quotish interpolations. For example, it makes the following two statements equivalent: =end original 'postderef_qq' 機能は、 L<後置デリファレンス文法|perlref/Postfix Dereference Syntax> の機能を、 後置配列と後置スカラのデリファレンスがダブルクォート風変数展開で 利用可能になるように拡張します。 例えば、次の二つの文が等価になります: my $s = "[@{ $h->{a} }]"; my $s = "[$h->{a}->@*]"; =begin original This feature is available from Perl 5.20 onwards. In Perl 5.20 and 5.22, it was classed as experimental, and Perl emitted a warning for its usage, except when explicitly disabled: =end original この機能は Perl 5.20 から利用可能です。 Perl 5.20 と 5.22 では、これは実験的と位置づけられていて、 明示的に無効にしない限り Perl は警告を出力していました: no warnings "experimental::postderef"; =begin original As of Perl 5.24, use of this feature no longer triggers a warning, though the C warning category still exists (for compatibility with code that disables it). =end original Perl 5.24 から、この機能の使用はもはや警告を出力しなくなりましたが、 C 警告カテゴリは(これを無効にするコードとの 互換性のために)存在するままです。 =begin original The 'postderef' feature was used in Perl 5.20 and Perl 5.22 to enable postfix dereference syntax outside double-quotish interpolations. In those versions, using it triggered the C warning in the same way as the 'postderef_qq' feature did. As of Perl 5.24, this syntax is not only no longer experimental, but it is enabled for all Perl code, regardless of what feature declarations are in scope. =end original 'postderef' 機能は、ダブルクォート風変数展開の外側での 後置デリファレンス文法を有効にするために Perl 5.20 から Perl 5.22 で 使われていました。 これらのバージョンでは、'postderef_qq' 機能と同様に、これを使うと C 警告を引き起こします。 Perl 5.24 から、この文法はもはや実験的ではなくなっただけではなく、 スコープ中でどんな機能が宣言されているかに関わらず、全ての Perl コードで 有効になりました。 =head2 The 'signatures' feature ('signatures' 機能) =begin original B: This feature is still experimental and the implementation may change in future versions of Perl. For this reason, Perl will warn when you use the feature, unless you have explicitly disabled the warning: =end original B<警告>: この機能はまだ実験的で、実装は将来のバージョンの Perl で 変わるかもしれません。 このため、この機能を使うと、明示的に無効にしない限り警告が発生します: no warnings "experimental::signatures"; =begin original This enables unpacking of subroutine arguments into lexical variables by syntax such as =end original これは、次のような文法によってサブルーチンの引数をレキシカル変数に 展開できるようにします: sub foo ($left, $right) { return $left + $right; } =begin original See L for details. =end original 詳しくは L を参照してください。 =begin original This feature is available from Perl 5.20 onwards. =end original この機能は Perl 5.20 から利用可能です。 =head2 The 'refaliasing' feature ('refaliasing' 機能) =begin original B: This feature is still experimental and the implementation may change in future versions of Perl. For this reason, Perl will warn when you use the feature, unless you have explicitly disabled the warning: =end original B<警告>: この機能はまだ実験的で、実装は将来のバージョンの Perl で 変わるかもしれません。 このため、この機能を使うと、明示的に無効にしない限り警告が発生します: no warnings "experimental::refaliasing"; =begin original This enables aliasing via assignment to references: =end original これはリファレンスへの代入による別名化を有効にします: \$a = \$b; # $a and $b now point to the same scalar \@a = \@b; # to the same array \%a = \%b; \&a = \&b; foreach \%hash (@array_of_hash_refs) { ... } =begin original See L for details. =end original 詳しくは L を参照してください。 =begin original This feature is available from Perl 5.22 onwards. =end original この機能は Perl 5.22 から利用可能です。 =head2 The 'bitwise' feature ('bitwise' 機能) =begin original B: This feature is still experimental and the implementation may change in future versions of Perl. For this reason, Perl will warn when you use the feature, unless you have explicitly disabled the warning: =end original B<警告>: この機能はまだ実験的で、実装は将来のバージョンの Perl で 変わるかもしれません。 このため、この機能を使うと、明示的に無効にしない限り警告が発生します: no warnings "experimental::bitwise"; =begin original This makes the four standard bitwise operators (C<& | ^ ~>) treat their operands consistently as numbers, and introduces four new dotted operators (C<&. |. ^. ~.>) that treat their operands consistently as strings. The same applies to the assignment variants (C<&= |= ^= &.= |.= ^.=>). =end original これは四つの標準ビット単位演算子 (C<& | ^ ~>) がそのオペランドを 数値として一貫して扱うようになり、 オペランドを一貫して文字列として扱う新しいドット付き演算子 (C<&. |. ^. ~.>) を導入します。 同じものは代入の亜種 (C<&= |= ^= &.= |.= ^.=>) にも適用されます。 =begin original See L for details. =end original 詳しくは L を参照してください。 =begin original This feature is available from Perl 5.22 onwards. =end original この機能は Perl 5.22 から利用可能です。 =head1 FEATURE BUNDLES (機能の束) =begin original It's possible to load multiple features together, using a I. The name of a feature bundle is prefixed with a colon, to distinguish it from an actual feature. =end original 複数の機能のまとめて読み込むためには、I<機能の束> (feature bundle) が 使えます。 機能の束の名前には、実際の機能と区別するためにコロンが前置されます。 use feature ":5.10"; =begin original The following feature bundles are available: =end original 以下の機能の束が利用可能です: bundle features included --------- ----------------- :default array_base :5.10 say state switch array_base :5.12 say state switch unicode_strings array_base :5.14 say state switch unicode_strings array_base :5.16 say state switch unicode_strings unicode_eval evalbytes current_sub fc :5.18 say state switch unicode_strings unicode_eval evalbytes current_sub fc :5.20 say state switch unicode_strings unicode_eval evalbytes current_sub fc :5.22 say state switch unicode_strings unicode_eval evalbytes current_sub fc :5.24 say state switch unicode_strings unicode_eval evalbytes current_sub fc postderef_qq =begin original The C<:default> bundle represents the feature set that is enabled before any C or C declaration. =end original C<:default> 束は、C や C 宣言が有効になる前の 機能集合を表現しています。 =begin original Specifying sub-versions such as the C<0> in C<5.14.0> in feature bundles has no effect. Feature bundles are guaranteed to be the same for all sub-versions. =end original 機能の束での C<5.14.0> の C<0> のような副バージョンを指定しても効果は ありません。 機能の束は全ての副バージョンに関して同じ事が保証されています。 use feature ":5.14.0"; # same as ":5.14" use feature ":5.14.1"; # same as ":5.14" =head1 IMPLICIT LOADING (暗黙の読み込み) =begin original Instead of loading feature bundles by name, it is easier to let Perl do implicit loading of a feature bundle for you. =end original 機能の束を名前で読み込むより、Perl に機能の束を暗黙に読み込ませるように した方が簡単です。 =begin original There are two ways to load the C pragma implicitly: =end original C プラグマを暗黙に読み込むには二つの方法があります: =over 4 =item * =begin original By using the C<-E> switch on the Perl command-line instead of C<-e>. That will enable the feature bundle for that version of Perl in the main compilation unit (that is, the one-liner that follows C<-E>). =end original Perl のコマンドラインで C<-e> オプションの代わりに C<-E> オプションを 使用した場合。 これにより、main コンパイル単位(つまり、C<-E> に引き続く 1 行野郎)で そのバージョンの Perl の機能の束が有効になります。 =item * =begin original By explicitly requiring a minimum Perl version number for your program, with the C construct. That is, =end original C 構文を使ってプログラムが必要とする最低限の Perl バージョン 番号を明示的に指定した場合。 つまり、以下のようにすると: use v5.10.0; =begin original will do an implicit =end original 暗黙のうちに以下のように: no feature ':all'; use feature ':5.10'; =begin original and so on. Note how the trailing sub-version is automatically stripped from the version. =end original なるということです。 末尾の副バージョンは自動的にバージョンから取り除かれるようになったことに 注意してください。 =begin original But to avoid portability warnings (see L), you may prefer: =end original しかし移植性の警告(L を参照してください)を避けるために、 以下のようにするのを好むかもしれません: use 5.010; =begin original with the same effect. =end original これでも同じ効果が得られます。 =begin original If the required version is older than Perl 5.10, the ":default" feature bundle is automatically loaded instead. =end original 要求したバージョンが Perl 5.10 より前の場合、代わりに機能の束 ":default" が 自動的に読み込まれます。 =back =cut =begin meta Translate: SHIRAKATA Kentaro Status: completed =end meta