perllexwarn > 5.10.1 との差分

perllexwarn 5.10.1 と 5.26.1 の差分

11
22=encoding euc-jp
33
44=head1 NAME
5X<warning, lexical> X<warnings> X<warning>
65
76=begin original
87
98perllexwarn - Perl Lexical Warnings
109
1110=end original
1211
1312perllexwarn - Perl のレキシカルな警告
1413
1514=head1 DESCRIPTION
1615
1716=begin original
1817
19The C<use warnings> pragma enables to control precisely what warnings are
18Perl v5.6.0 introduced lexical control over the handling of warnings by
20to be enabled in which parts of a Perl program. It's a more flexible
19category. The C<warnings> pragma generally replaces the command line flag
21alternative for both the command line flag B<-w> and the equivalent Perl
20B<-w>. Documentation on the use of lexical warnings, once partly found in
22variable, C<$^W>.
21this document, is now found in the L<warnings> documentation.
2322
2423=end original
2524
26C<use warnings> プラグマは、Perl プログラムのある部分に対してどの警告を
25Perl v5.6.0 ではカテゴリ単位で警告の扱いレキシカルに
27有効にするかを精密に制御できるように
26制御できるようになりした
28これはコマンドラインオプション B<-w> および等価な Perl 変数 C<$^W> よりも
27C<warnings> プラグマ一般的にコマンドラインオプション B<-w> を置き換えます。
29より柔軟な代替案で
28レキシカル警告の使用に関る文書は、一時期は部分的にこの文書にありましたが、
29今は L<warnings> 文書にあります。
3030
31=begin original
32
33This pragma works just like the C<strict> pragma.
34This means that the scope of the warning pragma is limited to the
35enclosing block. It also means that the pragma setting will not
36leak across files (via C<use>, C<require> or C<do>). This allows
37authors to independently define the degree of warning checks that will
38be applied to their module.
39
40=end original
41
42このプラグマはちょうど C<strict> プラグマと同様に動作します。
43つまり、警告プラグマのスコープは閉じたブロック内に限定されます。
44また、プラグマ設定は (C<use>, C<require>, C<do> を通して)ファイルを超えて
45漏洩することはありません。
46これにより、モジュール作者は警告チェックの度合いを独立に
47設定できるようになります。
48
49=begin original
50
51By default, optional warnings are disabled, so any legacy code that
52doesn't attempt to control the warnings will work unchanged.
53
54=end original
55
56デフォルトでは、オプションの警告は無効なので、警告を制御しようとしない
57レガシーコードは変更なしで動作します。
58
59=begin original
60
61All warnings are enabled in a block by either of these:
62
63=end original
64
65あるブロック内で全ての警告を有効にするには以下のどちらかのようにします:
66
67 use warnings;
68 use warnings 'all';
69
70=begin original
71
72Similarly all warnings are disabled in a block by either of these:
73
74=end original
75
76同様に、あるブロック内で全ての警告を無効にするには以下のどちらかのように
77します:
78
79 no warnings;
80 no warnings 'all';
81
82=begin original
83
84For example, consider the code below:
85
86=end original
87
88例えば、以下のコードを考えます:
89
90 use warnings;
91 my @a;
92 {
93 no warnings;
94 my $b = @a[0];
95 }
96 my $c = @a[0];
97
98=begin original
99
100The code in the enclosing block has warnings enabled, but the inner
101block has them disabled. In this case that means the assignment to the
102scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]">
103warning, but the assignment to the scalar C<$b> will not.
104
105=end original
106
107外側のブロックでは警告は有効ですが、内側のブロックでは無効です。
108この場合、スカラ C<$c> への代入では
109C<"Scalar value @a[0] better written as $a[0]"> 警告が出ますが、
110スカラ C<$b> への代入では出ません。
111
112=head2 Default Warnings and Optional Warnings
113
114(デフォルトの警告とオプションの警告)
115
116=begin original
117
118Before the introduction of lexical warnings, Perl had two classes of
119warnings: mandatory and optional.
120
121=end original
122
123レキシカル警告の説明の前に、Perl は二つの警告クラスがあります:
124強制的(mandatory)とオプション(optional)です。
125
126=begin original
127
128As its name suggests, if your code tripped a mandatory warning, you
129would get a warning whether you wanted it or not.
130For example, the code below would always produce an C<"isn't numeric">
131warning about the "2:".
132
133=end original
134
135名前が示しているように、コードが強制的な警告に引っかかると、望むと
136望まな意図にかかわらず警告を出力します。
137例えば、以下のコードは "2:" の部分に対して常に C<"isn't numeric"> 警告を
138出力します。
139
140 my $a = "2:" + 3;
141
142=begin original
143
144With the introduction of lexical warnings, mandatory warnings now become
145I<default> warnings. The difference is that although the previously
146mandatory warnings are still enabled by default, they can then be
147subsequently enabled or disabled with the lexical warning pragma. For
148example, in the code below, an C<"isn't numeric"> warning will only
149be reported for the C<$a> variable.
150
151=end original
152
153レキシカルな警告の導入によって、強制的な警告は I<デフォルトの> 警告と
154なりました。
155違いは、以前の強制的な警告は今でもデフォルトで有効ですが、引き続く
156レキシカルな警告プラグマで有効/無効にに出来ることです。
157例えば、以下のコードでは、C<"isn't numeric"> 警告は C<$a> 変数に対してだけ
158報告されます。
159
160 my $a = "2:" + 3;
161 no warnings;
162 my $b = "2:" + 3;
163
164=begin original
165
166Note that neither the B<-w> flag or the C<$^W> can be used to
167disable/enable default warnings. They are still mandatory in this case.
168
169=end original
170
171B<-w> オプションや C<$^W> はデフォルトの警告を無効/有効にするのには
172使えないことに注意してください。
173この場合は強制的なままです。
174
175=head2 What's wrong with B<-w> and C<$^W>
176
177(B<-w> や C<$^W> の何が悪いの?)
178
179=begin original
180
181Although very useful, the big problem with using B<-w> on the command
182line to enable warnings is that it is all or nothing. Take the typical
183scenario when you are writing a Perl program. Parts of the code you
184will write yourself, but it's very likely that you will make use of
185pre-written Perl modules. If you use the B<-w> flag in this case, you
186end up enabling warnings in pieces of code that you haven't written.
187
188=end original
189
190警告を有効にするのにコマンドラインで B<-w> を使うというのはとても
191便利ですが、オールオアナッシングであるという問題があります。
192Perl のプログラムを書いているときのよくある状況を考えます。
193コードの一部はあなた自身が書きますが、かなり確実に既に書かれている
194Perl モジュールを利用します。
195このような場合に B<-w> フラグを使うと、あなたが書いていないコードに
196対しても警告を有効にすることになります。
197
198=begin original
199
200Similarly, using C<$^W> to either disable or enable blocks of code is
201fundamentally flawed. For a start, say you want to disable warnings in
202a block of code. You might expect this to be enough to do the trick:
203
204=end original
205
206同様に、コードブロックで有効または無効にするために C<$^W> を使うことにも
207本質的な欠点があります。
208まず、コードブロックで警告を無効にしたいとします。
209以下のようにすれば十分だと考えるかもしれません:
210
211 {
212 local ($^W) = 0;
213 my $a =+ 2;
214 my $b; chop $b;
215 }
216
217=begin original
218
219When this code is run with the B<-w> flag, a warning will be produced
220for the C<$a> line -- C<"Reversed += operator">.
221
222=end original
223
224このコードが B<-w> フラグ付きで実行されると、C<$a> の行で警告が
225出ます -- C<"Reversed += operator">。
226
227=begin original
228
229The problem is that Perl has both compile-time and run-time warnings. To
230disable compile-time warnings you need to rewrite the code like this:
231
232=end original
233
234問題は、Perl にはコンパイル時警告と実行時警告があると言うことです。
235コンパイル時警告を無効にするには、以下のようにコードを書き直す必要が
236あります:
237
238 {
239 BEGIN { $^W = 0 }
240 my $a =+ 2;
241 my $b; chop $b;
242 }
243
244=begin original
245
246The other big problem with C<$^W> is the way you can inadvertently
247change the warning setting in unexpected places in your code. For example,
248when the code below is run (without the B<-w> flag), the second call
249to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas
250the first will not.
251
252=end original
253
254C<$^W> に関するもう一つの問題は、コード中の予想外の位置の設定で不用意に
255警告設定が変わるということです。
256例えば、以下のコードが(B<-w> フラグなしで)実行されると、C<doit> の
2572 回目の呼び出しで C<"Use of uninitialized value"> 警告が出ますが、
2581 回目では出ません。
259
260 sub doit
261 {
262 my $b; chop $b;
263 }
264
265 doit();
266
267 {
268 local ($^W) = 1;
269 doit()
270 }
271
272=begin original
273
274This is a side-effect of C<$^W> being dynamically scoped.
275
276=end original
277
278これは C<$^W> が動的スコープを持つことの副作用です。
279
280=begin original
281
282Lexical warnings get around these limitations by allowing finer control
283over where warnings can or can't be tripped.
284
285=end original
286
287レキシカルな警告は、どこで警告に引っかかるか引っかからないかに関して
288より精度の高い制御をすることで、これらの制限を回避します。
289
290=head2 Controlling Warnings from the Command Line
291
292(コマンドラインから警告を制御する)
293
294=begin original
295
296There are three Command Line flags that can be used to control when
297warnings are (or aren't) produced:
298
299=end original
300
301いつ警告が発生する(あるいは発生しない)かを制御するために使われる
302三つのコマンドラインフラグがあります:
303
304=over 5
305
306=item B<-w>
307X<-w>
308
309=begin original
310
311This is the existing flag. If the lexical warnings pragma is B<not>
312used in any of you code, or any of the modules that you use, this flag
313will enable warnings everywhere. See L<Backward Compatibility> for
314details of how this flag interacts with lexical warnings.
315
316=end original
317
318これは既存のフラグです。
319レキシカル警告プラグマがあなたのコードやあなたが使っているモジュールの
320どこでも B<使われていない> なら、このフラグは全ての場所で警告を
321有効にします。
322このフラグがレキシカル警告とどのように相互作用するかに関する詳細については
323L<Backward Compatibility> を参照してください。
324
325=item B<-W>
326X<-W>
327
328=begin original
329
330If the B<-W> flag is used on the command line, it will enable all warnings
331throughout the program regardless of whether warnings were disabled
332locally using C<no warnings> or C<$^W =0>. This includes all files that get
333included via C<use>, C<require> or C<do>.
334Think of it as the Perl equivalent of the "lint" command.
335
336=end original
337
338コマンドラインで B<-W> フラグが使われると、プログラム中で
339C<no warnings> や C<$^W =0> を使って警告を無効にしていても無視して、全ての
340警告を有効にします。
341これは C<use>, C<require>, C<do> 経由で読み込まれる全てのファイルにも
342適用されます。
343Perl 用の "lint" コマンドの等価物と考えられます。
344
345=item B<-X>
346X<-X>
347
348=begin original
349
350Does the exact opposite to the B<-W> flag, i.e. it disables all warnings.
351
352=end original
353
354正確に B<-W> フラグの逆を行います; つまり、全ての警告を無効にします。
355
356=back
357
358=head2 Backward Compatibility
359
360(後方互換性)
361
362=begin original
363
364If you are used with working with a version of Perl prior to the
365introduction of lexically scoped warnings, or have code that uses both
366lexical warnings and C<$^W>, this section will describe how they interact.
367
368=end original
369
370レキシカルスコープ警告が導入される前のバージョンの Perl で動作させていたり、
371レキシカル警告と C<$^W> の両方のコードがある場合、この節はこれらが
372どのように相互作用するかを記述しています。
373
374=begin original
375
376How Lexical Warnings interact with B<-w>/C<$^W>:
377
378=end original
379
380レキシカル警告と B<-w>/C<$^W> の相互作用:
381
382=over 5
383
384=item 1.
385
386=begin original
387
388If none of the three command line flags (B<-w>, B<-W> or B<-X>) that
389control warnings is used and neither C<$^W> or the C<warnings> pragma
390are used, then default warnings will be enabled and optional warnings
391disabled.
392This means that legacy code that doesn't attempt to control the warnings
393will work unchanged.
394
395=end original
396
397警告を制御する三つのコマンドラインフラグ (B<-w>, B<-W> or B<-X>) の
398どれも使われておらず、C<$^W> や the C<warnings> プラグマも使われていない
399場合、デフォルトの警告が有効になり、オプションの警告は無効になります。
400これにより、警告を制御しようとしないレガシーコードは無変更で動作します。
401
402=item 2.
403
404=begin original
405
406The B<-w> flag just sets the global C<$^W> variable as in 5.005 -- this
407means that any legacy code that currently relies on manipulating C<$^W>
408to control warning behavior will still work as is.
409
410=end original
411
4125.005 から B<-w> フラグはグローバルな C<$^W> 変数を設定します -- これにより、
413警告の振る舞いを制御するために C<$^W> を操作することに依存している
414レガシーコードはそのままで動作します。
415
416=item 3.
417
418=begin original
419
420Apart from now being a boolean, the C<$^W> variable operates in exactly
421the same horrible uncontrolled global way, except that it cannot
422disable/enable default warnings.
423
424=end original
425
426真偽値になったことは別として、C<$^W> 変数は正確に同じ恐ろしく
427制御不能なグローバルな方法で操作しますが、デフォルトの警告を有効化/
428無効化することは出来ません。
429
430=item 4.
431
432=begin original
433
434If a piece of code is under the control of the C<warnings> pragma,
435both the C<$^W> variable and the B<-w> flag will be ignored for the
436scope of the lexical warning.
437
438=end original
439
440コード片が C<warnings> プラグマの制御下にある場合、C<$^W> 変数と
441B<-w> フラグの両方はレキシカル警告のスコープで無視されます。
442
443=item 5.
444
445=begin original
446
447The only way to override a lexical warnings setting is with the B<-W>
448or B<-X> command line flags.
449
450=end original
451
452レキシカル警告設定を上書きする唯一の方法は B<-W> または B<-X>
453コマンドラインフラグを使うことです。
454
455=back
456
457=begin original
458
459The combined effect of 3 & 4 is that it will allow code which uses
460the C<warnings> pragma to control the warning behavior of $^W-type
461code (using a C<local $^W=0>) if it really wants to, but not vice-versa.
462
463=end original
464
4653 & 4 の組み合わせの効果により、本当に警告したいときに $^W 型のコードの
466警告の振る舞いを (C<local $^W=0> を使って) 制御するために
467C<warnings> プラグマを使えますが、逆はできません。
468
469=head2 Category Hierarchy
470X<warning, categories>
471
472(カテゴリ階層)
473
474=begin original
475
476A hierarchy of "categories" have been defined to allow groups of warnings
477to be enabled/disabled in isolation.
478
479=end original
480
481「カテゴリ」の階層は、警告のグループを分離して警告を有効/無効にできるように
482するために定義されています。
483
484=begin original
485
486The current hierarchy is:
487
488=end original
489
490現在の階層は:
491
492 all -+
493 |
494 +- closure
495 |
496 +- deprecated
497 |
498 +- exiting
499 |
500 +- glob
501 |
502 +- io -----------+
503 | |
504 | +- closed
505 | |
506 | +- exec
507 | |
508 | +- layer
509 | |
510 | +- newline
511 | |
512 | +- pipe
513 | |
514 | +- unopened
515 |
516 +- misc
517 |
518 +- numeric
519 |
520 +- once
521 |
522 +- overflow
523 |
524 +- pack
525 |
526 +- portable
527 |
528 +- recursion
529 |
530 +- redefine
531 |
532 +- regexp
533 |
534 +- severe -------+
535 | |
536 | +- debugging
537 | |
538 | +- inplace
539 | |
540 | +- internal
541 | |
542 | +- malloc
543 |
544 +- signal
545 |
546 +- substr
547 |
548 +- syntax -------+
549 | |
550 | +- ambiguous
551 | |
552 | +- bareword
553 | |
554 | +- digit
555 | |
556 | +- parenthesis
557 | |
558 | +- precedence
559 | |
560 | +- printf
561 | |
562 | +- prototype
563 | |
564 | +- qw
565 | |
566 | +- reserved
567 | |
568 | +- semicolon
569 |
570 +- taint
571 |
572 +- threads
573 |
574 +- uninitialized
575 |
576 +- unpack
577 |
578 +- untie
579 |
580 +- utf8
581 |
582 +- void
583
584=begin original
585
586Just like the "strict" pragma any of these categories can be combined
587
588=end original
589
590"strict" プラグマと同様、これらのカテゴリは組み合わせることができます
591
592 use warnings qw(void redefine);
593 no warnings qw(io syntax untie);
594
595=begin original
596
597Also like the "strict" pragma, if there is more than one instance of the
598C<warnings> pragma in a given scope the cumulative effect is additive.
599
600=end original
601
602これも "strict" プラグマと同様、現在のスコープに複数の
603C<warnings> プラグマの実体があるときは、効果は加算されます。
604
605 use warnings qw(void); # only "void" warnings enabled
606 ...
607 use warnings qw(io); # only "void" & "io" warnings enabled
608 ...
609 no warnings qw(void); # only "io" warnings enabled
610
611=begin original
612
613To determine which category a specific warning has been assigned to see
614L<perldiag>.
615
616=end original
617
618ある特定の警告がどのカテゴリに割り当てられているかを知るには
619L<perldiag> を参照してください。
620
621=begin original
622
623Note: In Perl 5.6.1, the lexical warnings category "deprecated" was a
624sub-category of the "syntax" category. It is now a top-level category
625in its own right.
626
627=end original
628
629注意: Perl 5.6.1 では、レキシカル警告カテゴリ "deprecated" は "syntax"
630カテゴリの副カテゴリでした。
631今ではそれ自体でトップレベルカテゴリです。
632
633=head2 Fatal Warnings
634X<warning, fatal>
635
636(致命的警告)
637
638=begin original
639
640The presence of the word "FATAL" in the category list will escalate any
641warnings detected from the categories specified in the lexical scope
642into fatal errors. In the code below, the use of C<time>, C<length>
643and C<join> can all produce a C<"Useless use of xxx in void context">
644warning.
645
646=end original
647
648カテゴリ一覧中に "FATAL" の文字があると、レキシカルスコープで
649指定されたカテゴリで検出された全ての警告を致命的エラーに昇格させます。
650以下のコードでは、C<time>, C<length>, C<join> の使用は全て
651C<"Useless use of xxx in void context"> 警告を出力します。
652
653 use warnings;
654
655 time;
656
657 {
658 use warnings FATAL => qw(void);
659 length "abc";
660 }
661
662 join "", 1,2,3;
663
664 print "done\n";
665
666=begin original
667
668When run it produces this output
669
670=end original
671
672実行すると、以下の出力を生成します
673
674 Useless use of time in void context at fatal line 3.
675 Useless use of length in void context at fatal line 7.
676
677=begin original
678
679The scope where C<length> is used has escalated the C<void> warnings
680category into a fatal error, so the program terminates immediately it
681encounters the warning.
682
683=end original
684
685C<length> が使われているスコープでは C<void> 警告カテゴリを致命的エラーに
686昇格させるので、この警告に出会うとプログラムは直ちに終了します。
687
688=begin original
689
690To explicitly turn off a "FATAL" warning you just disable the warning
691it is associated with. So, for example, to disable the "void" warning
692in the example above, either of these will do the trick:
693
694=end original
695
696明示的に "FATAL" 警告をオフにするには、単に関連する警告を無効にします。
697それで、例えば、上述の例で "void" 警告を無効にするには、以下の二つの
698技のどちらかを使います:
699
700 no warnings qw(void);
701 no warnings FATAL => qw(void);
702
703=begin original
704
705If you want to downgrade a warning that has been escalated into a fatal
706error back to a normal warning, you can use the "NONFATAL" keyword. For
707example, the code below will promote all warnings into fatal errors,
708except for those in the "syntax" category.
709
710=end original
711
712致命的エラーに昇格した警告を通常の警告に降格させたい場合、
713"NONFATAL" きーわーどが使えます。
714例えば、以下のコードは "syntax" カテゴリ以外の全ての警告を致命的エラーに
715昇格させます。
716
717 use warnings FATAL => 'all', NONFATAL => 'syntax';
718
719=head2 Reporting Warnings from a Module
720X<warning, reporting> X<warning, registering>
721
722(モジュールから警告を報告する)
723
724=begin original
725
726The C<warnings> pragma provides a number of functions that are useful for
727module authors. These are used when you want to report a module-specific
728warning to a calling module has enabled warnings via the C<warnings>
729pragma.
730
731=end original
732
733C<warnings> プラグマはモジュール作者にとって有用ないくつかの関数を
734提供します。
735C<warnings> プラグマ経由で有効になったモジュール固有の警告を呼び出し元に
736報告するときに使われます。
737
738=begin original
739
740Consider the module C<MyMod::Abc> below.
741
742=end original
743
744以下の C<MyMod::Abc> モジュールを考えます。
745
746 package MyMod::Abc;
747
748 use warnings::register;
749
750 sub open {
751 my $path = shift;
752 if ($path !~ m#^/#) {
753 warnings::warn("changing relative path to /var/abc")
754 if warnings::enabled();
755 $path = "/var/abc/$path";
756 }
757 }
758
759 1;
760
761=begin original
762
763The call to C<warnings::register> will create a new warnings category
764called "MyMod::abc", i.e. the new category name matches the current
765package name. The C<open> function in the module will display a warning
766message if it gets given a relative path as a parameter. This warnings
767will only be displayed if the code that uses C<MyMod::Abc> has actually
768enabled them with the C<warnings> pragma like below.
769
770=end original
771
772C<warnings::register> の呼び出しにより、"MyMod::abc" という名前の新しい
773警告カテゴリを作成します; つまり、新しいカテゴリ名は現在のパッケージ名に
774一致します。
775このモジュールの C<open> 関数は、引数として相対パスが与えられると
776警告メッセージを出力します。
777この警告は、C<MyMod::Abc> を使うコードが 以下のようにして
778C<warnings> によって有効にされた場合にのみ出力されます。
779
780 use MyMod::Abc;
781 use warnings 'MyMod::Abc';
782 ...
783 abc::open("../fred.txt");
784
785=begin original
786
787It is also possible to test whether the pre-defined warnings categories are
788set in the calling module with the C<warnings::enabled> function. Consider
789this snippet of code:
790
791=end original
792
793また、C<warnings::enabled> 関数を使って、既に定義されているカテゴリが
794呼び出しモジュールで設定されているかどうかをテストすることも可能です。
795以下のコード片を考えます:
796
797 package MyMod::Abc;
798
799 sub open {
800 warnings::warnif("deprecated",
801 "open is deprecated, use new instead");
802 new(@_);
803 }
804
805 sub new
806 ...
807 1;
808
809=begin original
810
811The function C<open> has been deprecated, so code has been included to
812display a warning message whenever the calling module has (at least) the
813"deprecated" warnings category enabled. Something like this, say.
814
815=end original
816
817C<open> 関数は非推奨なので、呼び出しモジュールで (少なくとも)
818"deprecated" 警告カテゴリが有効のとき警告を出力するコードが含まれています。
819つまりこんな感じです。
820
821 use warnings 'deprecated';
822 use MyMod::Abc;
823 ...
824 MyMod::Abc::open($filename);
825
826=begin original
827
828Either the C<warnings::warn> or C<warnings::warnif> function should be
829used to actually display the warnings message. This is because they can
830make use of the feature that allows warnings to be escalated into fatal
831errors. So in this case
832
833=end original
834
835実際に警告メッセージを出力するには、C<warnings::warn> 関数と
836C<warnings::warnif> 関数のどちらかを使うべきです。
837これは、警告を致命的エラーに昇格させる機能を使えるようにするためです。
838それで、このような場合:
839
840 use MyMod::Abc;
841 use warnings FATAL => 'MyMod::Abc';
842 ...
843 MyMod::Abc::open('../fred.txt');
844
845=begin original
846
847the C<warnings::warnif> function will detect this and die after
848displaying the warning message.
849
850=end original
851
852C<warnings::warnif> 関数はこれを検出して、警告を出力した後 die します。
853
854=begin original
855
856The three warnings functions, C<warnings::warn>, C<warnings::warnif>
857and C<warnings::enabled> can optionally take an object reference in place
858of a category name. In this case the functions will use the class name
859of the object as the warnings category.
860
861=end original
862
863三つの警告関数 C<warnings::warn>, C<warnings::warnif>,
864C<warnings::enabled> は、オプションとしてカテゴリ名の代わりにオブジェクトの
865リファレンスをとることができます。
866この場合関数は警告カテゴリとしてオブジェクトのクラス名を使います。
867
868=begin original
869
870Consider this example:
871
872=end original
873
874この例を考えます:
875
876 package Original;
877
878 no warnings;
879 use warnings::register;
880
881 sub new
882 {
883 my $class = shift;
884 bless [], $class;
885 }
886
887 sub check
888 {
889 my $self = shift;
890 my $value = shift;
891
892 if ($value % 2 && warnings::enabled($self))
893 { warnings::warn($self, "Odd numbers are unsafe") }
894 }
895
896 sub doit
897 {
898 my $self = shift;
899 my $value = shift;
900 $self->check($value);
901 # ...
902 }
903
904 1;
905
906 package Derived;
907
908 use warnings::register;
909 use Original;
910 our @ISA = qw( Original );
911 sub new
912 {
913 my $class = shift;
914 bless [], $class;
915 }
916
917
918 1;
919
920=begin original
921
922The code below makes use of both modules, but it only enables warnings from
923C<Derived>.
924
925=end original
926
927以下のコードは両方のモジュールを使っていますが、C<Derived> からの警告だけを
928有効にしています。
929
930 use Original;
931 use Derived;
932 use warnings 'Derived';
933 my $a = Original->new();
934 $a->doit(1);
935 my $b = Derived->new();
936 $a->doit(1);
937
938=begin original
939
940When this code is run only the C<Derived> object, C<$b>, will generate
941a warning.
942
943=end original
944
945このコードが C<Derived> オブジェクトからのみ実行されているとき、
946C<$b> は警告を出力します。
947
948 Odd numbers are unsafe at main.pl line 7
949
950=begin original
951
952Notice also that the warning is reported at the line where the object is first
953used.
954
955=end original
956
957オブジェクトが最初に使われた行で警告が報告されることにも注意してください。
958
959=head1 SEE ALSO
960
961=begin original
962
963L<warnings>, L<perldiag>.
964
965=end original
966
967L<warnings>, L<perldiag>
968
969=head1 AUTHOR
970
971Paul Marquess
972
97331=begin meta
97432
975Translate: Kentaro Shirakata <argrath@ub32.org>
33Translate: SHIRAKATA Kentaro <argrath@ub32.org>
97634Status: completed
97735
97836=end meta