warnings-1.23 >
1.06
との差分
warnings 1.06 と 1.23 の差分
1 | 1 | |
2 | 2 | =encoding euc-jp |
3 | 3 | |
4 | 4 | =head1 NAME |
5 | 5 | |
6 | 6 | =begin original |
7 | 7 | |
8 | 8 | warnings - Perl pragma to control optional warnings |
9 | 9 | |
10 | 10 | =end original |
11 | 11 | |
12 | 12 | warnings - 選択的な警告を調整する Perl プラグマ |
13 | 13 | |
14 | 14 | =head1 SYNOPSIS |
15 | 15 | |
16 | 16 | use warnings; |
17 | 17 | no warnings; |
18 | 18 | |
19 | 19 | use warnings "all"; |
20 | 20 | no warnings "all"; |
21 | 21 | |
22 | 22 | use warnings::register; |
23 | 23 | if (warnings::enabled()) { |
24 | 24 | warnings::warn("some warning"); |
25 | 25 | } |
26 | 26 | |
27 | 27 | if (warnings::enabled("void")) { |
28 | 28 | warnings::warn("void", "some warning"); |
29 | 29 | } |
30 | 30 | |
31 | 31 | if (warnings::enabled($object)) { |
32 | 32 | warnings::warn($object, "some warning"); |
33 | 33 | } |
34 | 34 | |
35 | 35 | warnings::warnif("some warning"); |
36 | 36 | warnings::warnif("void", "some warning"); |
37 | 37 | warnings::warnif($object, "some warning"); |
38 | 38 | |
39 | 39 | =head1 DESCRIPTION |
40 | 40 | |
41 | 41 | =begin original |
42 | 42 | |
43 | The C<warnings> pragma is | |
43 | The C<warnings> pragma gives control over which warnings are enabled in | |
44 | ||
44 | which parts of a Perl program. It's a more flexible alternative for | |
45 | ||
45 | both the command line flag B<-w> and the equivalent Perl variable, | |
46 | C<$^W>. | |
46 | 47 | |
47 | 48 | =end original |
48 | 49 | |
49 | C<warnings> プラグマは、 | |
50 | C<use warnings> プラグマは、Perl プログラムのある部分に対してどの警告を | |
50 | ||
51 | 有効にするかを制御できるようにします。 | |
51 | ||
52 | これはコマンドラインオプション B<-w> および等価な Perl 変数 C<$^W> よりも | |
52 | ||
53 | より柔軟な代替案です。 | |
53 | 54 | |
54 | 55 | =begin original |
55 | 56 | |
56 | ||
57 | This pragma works just like the C<strict> pragma. | |
57 | or | |
58 | This means that the scope of the warning pragma is limited to the | |
59 | enclosing block. It also means that the pragma setting will not | |
60 | leak across files (via C<use>, C<require> or C<do>). This allows | |
61 | authors to independently define the degree of warning checks that will | |
62 | be applied to their module. | |
58 | 63 | |
59 | 64 | =end original |
60 | 65 | |
61 | ||
66 | このプラグマはちょうど C<strict> プラグマと同様に動作します。 | |
62 | ||
67 | つまり、警告プラグマのスコープは閉じたブロック内に限定されます。 | |
68 | また、プラグマ設定は (C<use>, C<require>, C<do> を通して)ファイルを超えて | |
69 | 漏洩することはありません。 | |
70 | これにより、モジュール作者は警告チェックの度合いを独立に | |
71 | 設定できるようになります。 | |
63 | 72 | |
64 | 73 | =begin original |
65 | 74 | |
66 | ||
75 | By default, optional warnings are disabled, so any legacy code that | |
76 | doesn't attempt to control the warnings will work unchanged. | |
67 | 77 | |
68 | 78 | =end original |
69 | 79 | |
70 | ||
80 | デフォルトでは、オプションの警告は無効なので、警告を制御しようとしない | |
81 | レガシーコードは変更なしで動作します。 | |
71 | 82 | |
83 | =begin original | |
84 | ||
85 | All warnings are enabled in a block by either of these: | |
86 | ||
87 | =end original | |
88 | ||
89 | あるブロック内で全ての警告を有効にするには以下のどちらかのようにします: | |
90 | ||
91 | use warnings; | |
92 | use warnings 'all'; | |
93 | ||
94 | =begin original | |
95 | ||
96 | Similarly all warnings are disabled in a block by either of these: | |
97 | ||
98 | =end original | |
99 | ||
100 | 同様に、あるブロック内で全ての警告を無効にするには以下のどちらかのように | |
101 | します: | |
102 | ||
103 | no warnings; | |
104 | no warnings 'all'; | |
105 | ||
106 | =begin original | |
107 | ||
108 | For example, consider the code below: | |
109 | ||
110 | =end original | |
111 | ||
112 | 例えば、以下のコードを考えます: | |
113 | ||
114 | use warnings; | |
115 | my @a; | |
116 | { | |
117 | no warnings; | |
118 | my $b = @a[0]; | |
119 | } | |
120 | my $c = @a[0]; | |
121 | ||
122 | =begin original | |
123 | ||
124 | The code in the enclosing block has warnings enabled, but the inner | |
125 | block has them disabled. In this case that means the assignment to the | |
126 | scalar C<$c> will trip the C<"Scalar value @a[0] better written as $a[0]"> | |
127 | warning, but the assignment to the scalar C<$b> will not. | |
128 | ||
129 | =end original | |
130 | ||
131 | 外側のブロックでは警告は有効ですが、内側のブロックでは無効です。 | |
132 | この場合、スカラ C<$c> への代入では | |
133 | C<"Scalar value @a[0] better written as $a[0]"> 警告が出ますが、 | |
134 | スカラ C<$b> への代入では出ません。 | |
135 | ||
136 | =head2 Default Warnings and Optional Warnings | |
137 | ||
138 | (デフォルトの警告とオプションの警告) | |
139 | ||
140 | =begin original | |
141 | ||
142 | Before the introduction of lexical warnings, Perl had two classes of | |
143 | warnings: mandatory and optional. | |
144 | ||
145 | =end original | |
146 | ||
147 | レキシカル警告の説明の前に、Perl は二つの警告クラスがあります: | |
148 | 強制的(mandatory)とオプション(optional)です。 | |
149 | ||
150 | =begin original | |
151 | ||
152 | As its name suggests, if your code tripped a mandatory warning, you | |
153 | would get a warning whether you wanted it or not. | |
154 | For example, the code below would always produce an C<"isn't numeric"> | |
155 | warning about the "2:". | |
156 | ||
157 | =end original | |
158 | ||
159 | 名前が示しているように、コードが強制的な警告に引っかかると、望むと | |
160 | 望まな意図にかかわらず警告を出力します。 | |
161 | 例えば、以下のコードは "2:" の部分に対して常に C<"isn't numeric"> 警告を | |
162 | 出力します。 | |
163 | ||
164 | my $a = "2:" + 3; | |
165 | ||
166 | =begin original | |
167 | ||
168 | With the introduction of lexical warnings, mandatory warnings now become | |
169 | I<default> warnings. The difference is that although the previously | |
170 | mandatory warnings are still enabled by default, they can then be | |
171 | subsequently enabled or disabled with the lexical warning pragma. For | |
172 | example, in the code below, an C<"isn't numeric"> warning will only | |
173 | be reported for the C<$a> variable. | |
174 | ||
175 | =end original | |
176 | ||
177 | レキシカルな警告の導入によって、強制的な警告は I<デフォルトの> 警告と | |
178 | なりました。 | |
179 | 違いは、以前の強制的な警告は今でもデフォルトで有効ですが、引き続く | |
180 | レキシカルな警告プラグマで有効/無効にに出来ることです。 | |
181 | 例えば、以下のコードでは、C<"isn't numeric"> 警告は C<$a> 変数に対してだけ | |
182 | 報告されます。 | |
183 | ||
184 | my $a = "2:" + 3; | |
185 | no warnings; | |
186 | my $b = "2:" + 3; | |
187 | ||
188 | =begin original | |
189 | ||
190 | Note that neither the B<-w> flag or the C<$^W> can be used to | |
191 | disable/enable default warnings. They are still mandatory in this case. | |
192 | ||
193 | =end original | |
194 | ||
195 | B<-w> オプションや C<$^W> はデフォルトの警告を無効/有効にするのには | |
196 | 使えないことに注意してください。 | |
197 | この場合は強制的なままです。 | |
198 | ||
199 | =head2 What's wrong with B<-w> and C<$^W> | |
200 | ||
201 | (B<-w> や C<$^W> の何が悪いの?) | |
202 | ||
203 | =begin original | |
204 | ||
205 | Although very useful, the big problem with using B<-w> on the command | |
206 | line to enable warnings is that it is all or nothing. Take the typical | |
207 | scenario when you are writing a Perl program. Parts of the code you | |
208 | will write yourself, but it's very likely that you will make use of | |
209 | pre-written Perl modules. If you use the B<-w> flag in this case, you | |
210 | end up enabling warnings in pieces of code that you haven't written. | |
211 | ||
212 | =end original | |
213 | ||
214 | 警告を有効にするのにコマンドラインで B<-w> を使うというのはとても | |
215 | 便利ですが、オールオアナッシングであるという問題があります。 | |
216 | Perl のプログラムを書いているときのよくある状況を考えます。 | |
217 | コードの一部はあなた自身が書きますが、かなり確実に既に書かれている | |
218 | Perl モジュールを利用します。 | |
219 | このような場合に B<-w> フラグを使うと、あなたが書いていないコードに | |
220 | 対しても警告を有効にすることになります。 | |
221 | ||
222 | =begin original | |
223 | ||
224 | Similarly, using C<$^W> to either disable or enable blocks of code is | |
225 | fundamentally flawed. For a start, say you want to disable warnings in | |
226 | a block of code. You might expect this to be enough to do the trick: | |
227 | ||
228 | =end original | |
229 | ||
230 | 同様に、コードブロックで有効または無効にするために C<$^W> を使うことにも | |
231 | 本質的な欠点があります。 | |
232 | まず、コードブロックで警告を無効にしたいとします。 | |
233 | 以下のようにすれば十分だと考えるかもしれません: | |
234 | ||
235 | { | |
236 | local ($^W) = 0; | |
237 | my $a =+ 2; | |
238 | my $b; chop $b; | |
239 | } | |
240 | ||
241 | =begin original | |
242 | ||
243 | When this code is run with the B<-w> flag, a warning will be produced | |
244 | for the C<$a> line: C<"Reversed += operator">. | |
245 | ||
246 | =end original | |
247 | ||
248 | このコードが B<-w> フラグ付きで実行されると、C<$a> の行で警告が | |
249 | 出ます: C<"Reversed += operator">。 | |
250 | ||
251 | =begin original | |
252 | ||
253 | The problem is that Perl has both compile-time and run-time warnings. To | |
254 | disable compile-time warnings you need to rewrite the code like this: | |
255 | ||
256 | =end original | |
257 | ||
258 | 問題は、Perl にはコンパイル時警告と実行時警告があると言うことです。 | |
259 | コンパイル時警告を無効にするには、以下のようにコードを書き直す必要が | |
260 | あります: | |
261 | ||
262 | { | |
263 | BEGIN { $^W = 0 } | |
264 | my $a =+ 2; | |
265 | my $b; chop $b; | |
266 | } | |
267 | ||
268 | =begin original | |
269 | ||
270 | The other big problem with C<$^W> is the way you can inadvertently | |
271 | change the warning setting in unexpected places in your code. For example, | |
272 | when the code below is run (without the B<-w> flag), the second call | |
273 | to C<doit> will trip a C<"Use of uninitialized value"> warning, whereas | |
274 | the first will not. | |
275 | ||
276 | =end original | |
277 | ||
278 | C<$^W> に関するもう一つの問題は、コード中の予想外の位置の設定で不用意に | |
279 | 警告設定が変わるということです。 | |
280 | 例えば、以下のコードが(B<-w> フラグなしで)実行されると、C<doit> の | |
281 | 2 回目の呼び出しで C<"Use of uninitialized value"> 警告が出ますが、 | |
282 | 1 回目では出ません。 | |
283 | ||
284 | sub doit | |
285 | { | |
286 | my $b; chop $b; | |
287 | } | |
288 | ||
289 | doit(); | |
290 | ||
291 | { | |
292 | local ($^W) = 1; | |
293 | doit() | |
294 | } | |
295 | ||
296 | =begin original | |
297 | ||
298 | This is a side-effect of C<$^W> being dynamically scoped. | |
299 | ||
300 | =end original | |
301 | ||
302 | これは C<$^W> が動的スコープを持つことの副作用です。 | |
303 | ||
304 | =begin original | |
305 | ||
306 | Lexical warnings get around these limitations by allowing finer control | |
307 | over where warnings can or can't be tripped. | |
308 | ||
309 | =end original | |
310 | ||
311 | レキシカルな警告は、どこで警告に引っかかるか引っかからないかに関して | |
312 | より精度の高い制御をすることで、これらの制限を回避します。 | |
313 | ||
314 | =head2 Controlling Warnings from the Command Line | |
315 | ||
316 | (コマンドラインから警告を制御する) | |
317 | ||
318 | =begin original | |
319 | ||
320 | There are three Command Line flags that can be used to control when | |
321 | warnings are (or aren't) produced: | |
322 | ||
323 | =end original | |
324 | ||
325 | いつ警告が発生する(あるいは発生しない)かを制御するために使われる | |
326 | 三つのコマンドラインフラグがあります: | |
327 | ||
328 | =over 5 | |
329 | ||
330 | =item B<-w> | |
331 | X<-w> | |
332 | ||
333 | =begin original | |
334 | ||
335 | This is the existing flag. If the lexical warnings pragma is B<not> | |
336 | used in any of you code, or any of the modules that you use, this flag | |
337 | will enable warnings everywhere. See L<Backward Compatibility> for | |
338 | details of how this flag interacts with lexical warnings. | |
339 | ||
340 | =end original | |
341 | ||
342 | これは既存のフラグです。 | |
343 | レキシカル警告プラグマがあなたのコードやあなたが使っているモジュールの | |
344 | どこでも B<使われていない> なら、このフラグは全ての場所で警告を | |
345 | 有効にします。 | |
346 | このフラグがレキシカル警告とどのように相互作用するかに関する詳細については | |
347 | L<Backward Compatibility> を参照してください。 | |
348 | ||
349 | =item B<-W> | |
350 | X<-W> | |
351 | ||
352 | =begin original | |
353 | ||
354 | If the B<-W> flag is used on the command line, it will enable all warnings | |
355 | throughout the program regardless of whether warnings were disabled | |
356 | locally using C<no warnings> or C<$^W =0>. | |
357 | This includes all files that get | |
358 | included via C<use>, C<require> or C<do>. | |
359 | Think of it as the Perl equivalent of the "lint" command. | |
360 | ||
361 | =end original | |
362 | ||
363 | コマンドラインで B<-W> フラグが使われると、プログラム中で | |
364 | C<no warnings> や C<$^W =0> を使って警告を無効にしていても無視して、全ての | |
365 | 警告を有効にします。 | |
366 | これは C<use>, C<require>, C<do> 経由で読み込まれる全てのファイルにも | |
367 | 適用されます。 | |
368 | Perl 用の "lint" コマンドの等価物と考えられます。 | |
369 | ||
370 | =item B<-X> | |
371 | X<-X> | |
372 | ||
373 | =begin original | |
374 | ||
375 | Does the exact opposite to the B<-W> flag, i.e. it disables all warnings. | |
376 | ||
377 | =end original | |
378 | ||
379 | 正確に B<-W> フラグの逆を行います; つまり、全ての警告を無効にします。 | |
380 | ||
381 | =back | |
382 | ||
383 | =head2 Backward Compatibility | |
384 | ||
385 | (後方互換性) | |
386 | ||
387 | =begin original | |
388 | ||
389 | If you are used to working with a version of Perl prior to the | |
390 | introduction of lexically scoped warnings, or have code that uses both | |
391 | lexical warnings and C<$^W>, this section will describe how they interact. | |
392 | ||
393 | =end original | |
394 | ||
395 | レキシカルスコープ警告が導入される前のバージョンの Perl で動作させていたり、 | |
396 | レキシカル警告と C<$^W> の両方のコードがある場合、この節はこれらが | |
397 | どのように相互作用するかを記述しています。 | |
398 | ||
399 | =begin original | |
400 | ||
401 | How Lexical Warnings interact with B<-w>/C<$^W>: | |
402 | ||
403 | =end original | |
404 | ||
405 | レキシカル警告と B<-w>/C<$^W> の相互作用: | |
406 | ||
407 | =over 5 | |
408 | ||
409 | =item 1. | |
410 | ||
411 | =begin original | |
412 | ||
413 | If none of the three command line flags (B<-w>, B<-W> or B<-X>) that | |
414 | control warnings is used and neither C<$^W> nor the C<warnings> pragma | |
415 | are used, then default warnings will be enabled and optional warnings | |
416 | disabled. | |
417 | This means that legacy code that doesn't attempt to control the warnings | |
418 | will work unchanged. | |
419 | ||
420 | =end original | |
421 | ||
422 | 警告を制御する三つのコマンドラインフラグ (B<-w>, B<-W> or B<-X>) の | |
423 | どれも使われておらず、C<$^W> や the C<warnings> プラグマも使われていない | |
424 | 場合、デフォルトの警告が有効になり、オプションの警告は無効になります。 | |
425 | これにより、警告を制御しようとしないレガシーコードは無変更で動作します。 | |
426 | ||
427 | =item 2. | |
428 | ||
429 | =begin original | |
430 | ||
431 | The B<-w> flag just sets the global C<$^W> variable as in 5.005. This | |
432 | means that any legacy code that currently relies on manipulating C<$^W> | |
433 | to control warning behavior will still work as is. | |
434 | ||
435 | =end original | |
436 | ||
437 | 5.005 から B<-w> フラグはグローバルな C<$^W> 変数を設定します。 | |
438 | これにより、警告の振る舞いを制御するために C<$^W> を操作することに | |
439 | 依存しているレガシーコードはそのままで動作します。 | |
440 | ||
441 | =item 3. | |
442 | ||
443 | =begin original | |
444 | ||
445 | Apart from now being a boolean, the C<$^W> variable operates in exactly | |
446 | the same horrible uncontrolled global way, except that it cannot | |
447 | disable/enable default warnings. | |
448 | ||
449 | =end original | |
450 | ||
451 | 真偽値になったことは別として、C<$^W> 変数は正確に同じ恐ろしく | |
452 | 制御不能なグローバルな方法で操作しますが、デフォルトの警告を有効化/ | |
453 | 無効化することは出来ません。 | |
454 | ||
455 | =item 4. | |
456 | ||
457 | =begin original | |
458 | ||
459 | If a piece of code is under the control of the C<warnings> pragma, | |
460 | both the C<$^W> variable and the B<-w> flag will be ignored for the | |
461 | scope of the lexical warning. | |
462 | ||
463 | =end original | |
464 | ||
465 | コード片が C<warnings> プラグマの制御下にある場合、C<$^W> 変数と | |
466 | B<-w> フラグの両方はレキシカル警告のスコープで無視されます。 | |
467 | ||
468 | =item 5. | |
469 | ||
470 | =begin original | |
471 | ||
472 | The only way to override a lexical warnings setting is with the B<-W> | |
473 | or B<-X> command line flags. | |
474 | ||
475 | =end original | |
476 | ||
477 | レキシカル警告設定を上書きする唯一の方法は B<-W> または B<-X> | |
478 | コマンドラインフラグを使うことです。 | |
479 | ||
480 | =back | |
481 | ||
482 | =begin original | |
483 | ||
484 | The combined effect of 3 & 4 is that it will allow code which uses | |
485 | the C<warnings> pragma to control the warning behavior of $^W-type | |
486 | code (using a C<local $^W=0>) if it really wants to, but not vice-versa. | |
487 | ||
488 | =end original | |
489 | ||
490 | 3 & 4 の組み合わせの効果により、本当に警告したいときに $^W 型のコードの | |
491 | 警告の振る舞いを (C<local $^W=0> を使って) 制御するために | |
492 | C<warnings> プラグマを使えますが、逆はできません。 | |
493 | ||
494 | =head2 Category Hierarchy | |
495 | X<warning, categories> | |
496 | ||
497 | (カテゴリ階層) | |
498 | ||
499 | =begin original | |
500 | ||
501 | A hierarchy of "categories" have been defined to allow groups of warnings | |
502 | to be enabled/disabled in isolation. | |
503 | ||
504 | =end original | |
505 | ||
506 | 「カテゴリ」の階層は、警告のグループを分離して警告を有効/無効にできるように | |
507 | するために定義されています。 | |
508 | ||
509 | =begin original | |
510 | ||
511 | The current hierarchy is: | |
512 | ||
513 | =end original | |
514 | ||
515 | 現在の階層は: | |
516 | ||
517 | all -+ | |
518 | | | |
519 | +- closure | |
520 | | | |
521 | +- deprecated | |
522 | | | |
523 | +- exiting | |
524 | | | |
525 | +- experimental --+ | |
526 | | | | |
527 | | +- experimental::autoderef | |
528 | | | | |
529 | | +- experimental::lexical_subs | |
530 | | | | |
531 | | +- experimental::lexical_topic | |
532 | | | | |
533 | | +- experimental::postderef | |
534 | | | | |
535 | | +- experimental::regex_sets | |
536 | | | | |
537 | | +- experimental::signatures | |
538 | | | | |
539 | | +- experimental::smartmatch | |
540 | | | |
541 | +- glob | |
542 | | | |
543 | +- imprecision | |
544 | | | |
545 | +- io ------------+ | |
546 | | | | |
547 | | +- closed | |
548 | | | | |
549 | | +- exec | |
550 | | | | |
551 | | +- layer | |
552 | | | | |
553 | | +- newline | |
554 | | | | |
555 | | +- pipe | |
556 | | | | |
557 | | +- syscalls | |
558 | | | | |
559 | | +- unopened | |
560 | | | |
561 | +- misc | |
562 | | | |
563 | +- numeric | |
564 | | | |
565 | +- once | |
566 | | | |
567 | +- overflow | |
568 | | | |
569 | +- pack | |
570 | | | |
571 | +- portable | |
572 | | | |
573 | +- recursion | |
574 | | | |
575 | +- redefine | |
576 | | | |
577 | +- regexp | |
578 | | | |
579 | +- severe --------+ | |
580 | | | | |
581 | | +- debugging | |
582 | | | | |
583 | | +- inplace | |
584 | | | | |
585 | | +- internal | |
586 | | | | |
587 | | +- malloc | |
588 | | | |
589 | +- signal | |
590 | | | |
591 | +- substr | |
592 | | | |
593 | +- syntax --------+ | |
594 | | | | |
595 | | +- ambiguous | |
596 | | | | |
597 | | +- bareword | |
598 | | | | |
599 | | +- digit | |
600 | | | | |
601 | | +- illegalproto | |
602 | | | | |
603 | | +- parenthesis | |
604 | | | | |
605 | | +- precedence | |
606 | | | | |
607 | | +- printf | |
608 | | | | |
609 | | +- prototype | |
610 | | | | |
611 | | +- qw | |
612 | | | | |
613 | | +- reserved | |
614 | | | | |
615 | | +- semicolon | |
616 | | | |
617 | +- taint | |
618 | | | |
619 | +- threads | |
620 | | | |
621 | +- uninitialized | |
622 | | | |
623 | +- unpack | |
624 | | | |
625 | +- untie | |
626 | | | |
627 | +- utf8 ----------+ | |
628 | | | | |
629 | | +- non_unicode | |
630 | | | | |
631 | | +- nonchar | |
632 | | | | |
633 | | +- surrogate | |
634 | | | |
635 | +- void | |
636 | ||
637 | =begin original | |
638 | ||
639 | Just like the "strict" pragma any of these categories can be combined | |
640 | ||
641 | =end original | |
642 | ||
643 | "strict" プラグマと同様、これらのカテゴリは組み合わせることができます | |
644 | ||
645 | use warnings qw(void redefine); | |
646 | no warnings qw(io syntax untie); | |
647 | ||
648 | =begin original | |
649 | ||
650 | Also like the "strict" pragma, if there is more than one instance of the | |
651 | C<warnings> pragma in a given scope the cumulative effect is additive. | |
652 | ||
653 | =end original | |
654 | ||
655 | これも "strict" プラグマと同様、現在のスコープに複数の | |
656 | C<warnings> プラグマの実体があるときは、効果は加算されます。 | |
657 | ||
658 | use warnings qw(void); # only "void" warnings enabled | |
659 | ... | |
660 | use warnings qw(io); # only "void" & "io" warnings enabled | |
661 | ... | |
662 | no warnings qw(void); # only "io" warnings enabled | |
663 | ||
664 | =begin original | |
665 | ||
666 | To determine which category a specific warning has been assigned to see | |
667 | L<perldiag>. | |
668 | ||
669 | =end original | |
670 | ||
671 | ある特定の警告がどのカテゴリに割り当てられているかを知るには | |
672 | L<perldiag> を参照してください。 | |
673 | ||
674 | =begin original | |
675 | ||
676 | Note: Before Perl 5.8.0, the lexical warnings category "deprecated" was a | |
677 | sub-category of the "syntax" category. It is now a top-level category | |
678 | in its own right. | |
679 | ||
680 | =end original | |
681 | ||
682 | 注意: Perl 5.8.0 以前では、レキシカル警告カテゴリ "deprecated" は "syntax" | |
683 | カテゴリの副カテゴリでした。 | |
684 | 今ではそれ自体でトップレベルカテゴリです。 | |
685 | ||
686 | =head2 Fatal Warnings | |
687 | X<warning, fatal> | |
688 | ||
689 | (致命的警告) | |
690 | ||
691 | =begin original | |
692 | ||
693 | The presence of the word "FATAL" in the category list will escalate any | |
694 | warnings detected from the categories specified in the lexical scope | |
695 | into fatal errors. In the code below, the use of C<time>, C<length> | |
696 | and C<join> can all produce a C<"Useless use of xxx in void context"> | |
697 | warning. | |
698 | ||
699 | =end original | |
700 | ||
701 | カテゴリ一覧中に "FATAL" の文字があると、レキシカルスコープで | |
702 | 指定されたカテゴリで検出された全ての警告を致命的エラーに昇格させます。 | |
703 | 以下のコードでは、C<time>, C<length>, C<join> の使用は全て | |
704 | C<"Useless use of xxx in void context"> 警告を出力します。 | |
705 | ||
706 | use warnings; | |
707 | ||
708 | time; | |
709 | ||
710 | { | |
711 | use warnings FATAL => qw(void); | |
712 | length "abc"; | |
713 | } | |
714 | ||
715 | join "", 1,2,3; | |
716 | ||
717 | print "done\n"; | |
718 | ||
719 | =begin original | |
720 | ||
721 | When run it produces this output | |
722 | ||
723 | =end original | |
724 | ||
725 | 実行すると、以下の出力を生成します | |
726 | ||
727 | Useless use of time in void context at fatal line 3. | |
728 | Useless use of length in void context at fatal line 7. | |
729 | ||
730 | =begin original | |
731 | ||
732 | The scope where C<length> is used has escalated the C<void> warnings | |
733 | category into a fatal error, so the program terminates immediately when it | |
734 | encounters the warning. | |
735 | ||
736 | =end original | |
737 | ||
738 | C<length> が使われているスコープでは C<void> 警告カテゴリを致命的エラーに | |
739 | 昇格させるので、この警告に出会うとプログラムは直ちに終了します。 | |
740 | ||
741 | =begin original | |
742 | ||
743 | To explicitly turn off a "FATAL" warning you just disable the warning | |
744 | it is associated with. So, for example, to disable the "void" warning | |
745 | in the example above, either of these will do the trick: | |
746 | ||
747 | =end original | |
748 | ||
749 | 明示的に "FATAL" 警告をオフにするには、単に関連する警告を無効にします。 | |
750 | それで、例えば、上述の例で "void" 警告を無効にするには、以下の二つの | |
751 | 技のどちらかを使います: | |
752 | ||
753 | no warnings qw(void); | |
754 | no warnings FATAL => qw(void); | |
755 | ||
756 | =begin original | |
757 | ||
758 | If you want to downgrade a warning that has been escalated into a fatal | |
759 | error back to a normal warning, you can use the "NONFATAL" keyword. For | |
760 | example, the code below will promote all warnings into fatal errors, | |
761 | except for those in the "syntax" category. | |
762 | ||
763 | =end original | |
764 | ||
765 | 致命的エラーに昇格した警告を通常の警告に降格させたい場合、 | |
766 | "NONFATAL" きーわーどが使えます。 | |
767 | 例えば、以下のコードは "syntax" カテゴリ以外の全ての警告を致命的エラーに | |
768 | 昇格させます。 | |
769 | ||
770 | use warnings FATAL => 'all', NONFATAL => 'syntax'; | |
771 | ||
772 | =begin original | |
773 | ||
774 | As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can | |
775 | use: | |
776 | ||
777 | =end original | |
778 | ||
779 | Perl 5.20 から、C<< use warnings FATAL => 'all'; >> の代わりに以下のものが | |
780 | 使えます: | |
781 | ||
782 | use v5.20; # Perl 5.20 or greater is required for the following | |
783 | use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';" | |
784 | ||
785 | =begin original | |
786 | ||
787 | If you want your program to be compatible with versions of Perl before | |
788 | 5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In | |
789 | previous versions of Perl, the behavior of the statements | |
790 | C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and | |
791 | C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if | |
792 | they included the C<< => 'all' >> portion. As of 5.20, they do.) | |
793 | ||
794 | =end original | |
795 | ||
796 | 5.20 以前の Perl との互換性が必要なら、代わりに | |
797 | C<< use warnings FATAL => 'all'; >> を使わなければなりません。 | |
798 | (以前のバージョンの Perl では C<< use warnings 'FATAL'; >>, | |
799 | C<< use warnings 'NONFATAL'; >>, C<< no warnings 'FATAL'; >> という文の | |
800 | 振る舞いは未定義です; C<< => 'all' >> 部を含むようには振る舞いません。 | |
801 | 5.20 からはそうなります。) | |
802 | ||
803 | =begin original | |
804 | ||
805 | B<NOTE:> Users of FATAL warnings, especially | |
806 | those using C<< FATAL => 'all' >> | |
807 | should be fully aware that they are risking future portability of their | |
808 | programs by doing so. Perl makes absolutely no commitments to not | |
809 | introduce new warnings, or warnings categories in the future, and indeed | |
810 | we explicitly reserve the right to do so. Code that may not warn now may | |
811 | warn in a future release of Perl if the Perl5 development team deems it | |
812 | in the best interests of the community to do so. Should code using FATAL | |
813 | warnings break due to the introduction of a new warning we will NOT | |
814 | consider it an incompatible change. Users of FATAL warnings should take | |
815 | special caution during upgrades to check to see if their code triggers | |
816 | any new warnings and should pay particular attention to the fine print of | |
817 | the documentation of the features they use to ensure they do not exploit | |
818 | features that are documented as risky, deprecated, or unspecified, or where | |
819 | the documentation says "so don't do that", or anything with the same sense | |
820 | and spirit. Use of such features in combination with FATAL warnings is | |
821 | ENTIRELY AT THE USER'S RISK. | |
822 | ||
823 | =end original | |
824 | ||
825 | B<注意:> FATAL 警告の使用、特に C<< FATAL => 'all' >> の使用は、 | |
826 | そうすることによる将来の移植性のリスクによく注意する必要があります。 | |
827 | Perl は将来新しい警告や警告カテゴリを導入しないという保証は全くなく、 | |
828 | 明示的にそうする権利を保留します。 | |
829 | そうするのがコミュニティにとって最良であると Perl5 開発チームが判断すれば、 | |
830 | 現在警告されていないコードが将来警告されるかもしれません。 | |
831 | 新しい警告の導入によって FATAL 警告を使っているコードが壊れても、これは | |
832 | 互換性のない変更とは考えません。 | |
833 | FATAL 警告を使う場合は、コードが新しい警告を引き起こさないかを調べて、 | |
834 | 特に、文書に、リスクがある、廃止予定、未定義、「しないでください」と | |
835 | 書いてある、あるいは同じような意味と精神の機能を乱用しないように、機能の文書に | |
836 | 特に注意を払うべきです。 | |
837 | これらの機能を FATAL 警告と組み合わせるのは自身のリスクで行ってください。 | |
838 | ||
839 | =head2 Reporting Warnings from a Module | |
840 | X<warning, reporting> X<warning, registering> | |
841 | ||
842 | (モジュールから警告を報告する) | |
843 | ||
844 | =begin original | |
845 | ||
846 | The C<warnings> pragma provides a number of functions that are useful for | |
847 | module authors. These are used when you want to report a module-specific | |
848 | warning to a calling module has enabled warnings via the C<warnings> | |
849 | pragma. | |
850 | ||
851 | =end original | |
852 | ||
853 | C<warnings> プラグマはモジュール作者にとって有用ないくつかの関数を | |
854 | 提供します。 | |
855 | C<warnings> プラグマ経由で有効になったモジュール固有の警告を呼び出し元に | |
856 | 報告するときに使われます。 | |
857 | ||
858 | =begin original | |
859 | ||
860 | Consider the module C<MyMod::Abc> below. | |
861 | ||
862 | =end original | |
863 | ||
864 | 以下の C<MyMod::Abc> モジュールを考えます。 | |
865 | ||
866 | package MyMod::Abc; | |
867 | ||
868 | use warnings::register; | |
869 | ||
870 | sub open { | |
871 | my $path = shift; | |
872 | if ($path !~ m#^/#) { | |
873 | warnings::warn("changing relative path to /var/abc") | |
874 | if warnings::enabled(); | |
875 | $path = "/var/abc/$path"; | |
876 | } | |
877 | } | |
878 | ||
879 | 1; | |
880 | ||
881 | =begin original | |
882 | ||
883 | The call to C<warnings::register> will create a new warnings category | |
884 | called "MyMod::Abc", i.e. the new category name matches the current | |
885 | package name. The C<open> function in the module will display a warning | |
886 | message if it gets given a relative path as a parameter. This warnings | |
887 | will only be displayed if the code that uses C<MyMod::Abc> has actually | |
888 | enabled them with the C<warnings> pragma like below. | |
889 | ||
890 | =end original | |
891 | ||
892 | C<warnings::register> の呼び出しにより、"MyMod::Abc" という名前の新しい | |
893 | 警告カテゴリを作成します; つまり、新しいカテゴリ名は現在のパッケージ名に | |
894 | 一致します。 | |
895 | このモジュールの C<open> 関数は、引数として相対パスが与えられると | |
896 | 警告メッセージを出力します。 | |
897 | この警告は、C<MyMod::Abc> を使うコードが 以下のようにして | |
898 | C<warnings> によって有効にされた場合にのみ出力されます。 | |
899 | ||
900 | use MyMod::Abc; | |
901 | use warnings 'MyMod::Abc'; | |
902 | ... | |
903 | abc::open("../fred.txt"); | |
904 | ||
905 | =begin original | |
906 | ||
907 | It is also possible to test whether the pre-defined warnings categories are | |
908 | set in the calling module with the C<warnings::enabled> function. Consider | |
909 | this snippet of code: | |
910 | ||
911 | =end original | |
912 | ||
913 | また、C<warnings::enabled> 関数を使って、既に定義されているカテゴリが | |
914 | 呼び出しモジュールで設定されているかどうかをテストすることも可能です。 | |
915 | 以下のコード片を考えます: | |
916 | ||
917 | package MyMod::Abc; | |
918 | ||
919 | sub open { | |
920 | warnings::warnif("deprecated", | |
921 | "open is deprecated, use new instead"); | |
922 | new(@_); | |
923 | } | |
924 | ||
925 | sub new | |
926 | ... | |
927 | 1; | |
928 | ||
929 | =begin original | |
930 | ||
931 | The function C<open> has been deprecated, so code has been included to | |
932 | display a warning message whenever the calling module has (at least) the | |
933 | "deprecated" warnings category enabled. Something like this, say. | |
934 | ||
935 | =end original | |
936 | ||
937 | C<open> 関数は非推奨なので、呼び出しモジュールで (少なくとも) | |
938 | "deprecated" 警告カテゴリが有効のとき警告を出力するコードが含まれています。 | |
939 | つまりこんな感じです。 | |
940 | ||
941 | use warnings 'deprecated'; | |
942 | use MyMod::Abc; | |
943 | ... | |
944 | MyMod::Abc::open($filename); | |
945 | ||
946 | =begin original | |
947 | ||
948 | Either the C<warnings::warn> or C<warnings::warnif> function should be | |
949 | used to actually display the warnings message. This is because they can | |
950 | make use of the feature that allows warnings to be escalated into fatal | |
951 | errors. So in this case | |
952 | ||
953 | =end original | |
954 | ||
955 | 実際に警告メッセージを出力するには、C<warnings::warn> 関数と | |
956 | C<warnings::warnif> 関数のどちらかを使うべきです。 | |
957 | これは、警告を致命的エラーに昇格させる機能を使えるようにするためです。 | |
958 | それで、このような場合: | |
959 | ||
960 | use MyMod::Abc; | |
961 | use warnings FATAL => 'MyMod::Abc'; | |
962 | ... | |
963 | MyMod::Abc::open('../fred.txt'); | |
964 | ||
965 | =begin original | |
966 | ||
967 | the C<warnings::warnif> function will detect this and die after | |
968 | displaying the warning message. | |
969 | ||
970 | =end original | |
971 | ||
972 | C<warnings::warnif> 関数はこれを検出して、警告を出力した後 die します。 | |
973 | ||
974 | =begin original | |
975 | ||
976 | The three warnings functions, C<warnings::warn>, C<warnings::warnif> | |
977 | and C<warnings::enabled> can optionally take an object reference in place | |
978 | of a category name. In this case the functions will use the class name | |
979 | of the object as the warnings category. | |
980 | ||
981 | =end original | |
982 | ||
983 | 三つの警告関数 C<warnings::warn>, C<warnings::warnif>, | |
984 | C<warnings::enabled> は、オプションとしてカテゴリ名の代わりにオブジェクトの | |
985 | リファレンスをとることができます。 | |
986 | この場合関数は警告カテゴリとしてオブジェクトのクラス名を使います。 | |
987 | ||
988 | =begin original | |
989 | ||
990 | Consider this example: | |
991 | ||
992 | =end original | |
993 | ||
994 | この例を考えます: | |
995 | ||
996 | package Original; | |
997 | ||
998 | no warnings; | |
999 | use warnings::register; | |
1000 | ||
1001 | sub new | |
1002 | { | |
1003 | my $class = shift; | |
1004 | bless [], $class; | |
1005 | } | |
1006 | ||
1007 | sub check | |
1008 | { | |
1009 | my $self = shift; | |
1010 | my $value = shift; | |
1011 | ||
1012 | if ($value % 2 && warnings::enabled($self)) | |
1013 | { warnings::warn($self, "Odd numbers are unsafe") } | |
1014 | } | |
1015 | ||
1016 | sub doit | |
1017 | { | |
1018 | my $self = shift; | |
1019 | my $value = shift; | |
1020 | $self->check($value); | |
1021 | # ... | |
1022 | } | |
1023 | ||
1024 | 1; | |
1025 | ||
1026 | package Derived; | |
1027 | ||
1028 | use warnings::register; | |
1029 | use Original; | |
1030 | our @ISA = qw( Original ); | |
1031 | sub new | |
1032 | { | |
1033 | my $class = shift; | |
1034 | bless [], $class; | |
1035 | } | |
1036 | ||
1037 | 1; | |
1038 | ||
1039 | =begin original | |
1040 | ||
1041 | The code below makes use of both modules, but it only enables warnings from | |
1042 | C<Derived>. | |
1043 | ||
1044 | =end original | |
1045 | ||
1046 | 以下のコードは両方のモジュールを使っていますが、C<Derived> からの警告だけを | |
1047 | 有効にしています。 | |
1048 | ||
1049 | use Original; | |
1050 | use Derived; | |
1051 | use warnings 'Derived'; | |
1052 | my $a = Original->new(); | |
1053 | $a->doit(1); | |
1054 | my $b = Derived->new(); | |
1055 | $a->doit(1); | |
1056 | ||
1057 | =begin original | |
1058 | ||
1059 | When this code is run only the C<Derived> object, C<$b>, will generate | |
1060 | a warning. | |
1061 | ||
1062 | =end original | |
1063 | ||
1064 | このコードが C<Derived> オブジェクトからのみ実行されているとき、 | |
1065 | C<$b> は警告を出力します。 | |
1066 | ||
1067 | Odd numbers are unsafe at main.pl line 7 | |
1068 | ||
1069 | =begin original | |
1070 | ||
1071 | Notice also that the warning is reported at the line where the object is first | |
1072 | used. | |
1073 | ||
1074 | =end original | |
1075 | ||
1076 | オブジェクトが最初に使われた行で警告が報告されることにも注意してください。 | |
1077 | ||
1078 | =begin original | |
1079 | ||
1080 | When registering new categories of warning, you can supply more names to | |
1081 | warnings::register like this: | |
1082 | ||
1083 | =end original | |
1084 | ||
1085 | 警告の新しいカテゴリを登録するとき、以下のようにして warnings::register に | |
1086 | さらなる名前を提供できます: | |
1087 | ||
1088 | package MyModule; | |
1089 | use warnings::register qw(format precision); | |
1090 | ||
1091 | ... | |
1092 | ||
1093 | warnings::warnif('MyModule::format', '...'); | |
1094 | ||
1095 | =head1 FUNCTIONS | |
1096 | ||
1097 | (関数) | |
1098 | ||
72 | 1099 | =over 4 |
73 | 1100 | |
74 | 1101 | =item use warnings::register |
75 | 1102 | |
76 | 1103 | =begin original |
77 | 1104 | |
78 | 1105 | Creates a new warnings category with the same name as the package where |
79 | 1106 | the call to the pragma is used. |
80 | 1107 | |
81 | 1108 | =end original |
82 | 1109 | |
83 | 1110 | プラグマを呼び出したパッケージと同じ名前の新しい警告カテゴリを作成します。 |
84 | 1111 | |
85 | 1112 | =item warnings::enabled() |
86 | 1113 | |
87 | 1114 | =begin original |
88 | 1115 | |
89 | 1116 | Use the warnings category with the same name as the current package. |
90 | 1117 | |
91 | 1118 | =end original |
92 | 1119 | |
93 | 1120 | 現在のパッケージと同じ名前の警告カテゴリを使います。 |
94 | 1121 | |
95 | 1122 | =begin original |
96 | 1123 | |
97 | 1124 | Return TRUE if that warnings category is enabled in the calling module. |
98 | 1125 | Otherwise returns FALSE. |
99 | 1126 | |
100 | 1127 | =end original |
101 | 1128 | |
102 | 1129 | 呼ばれたモジュール内でその警告カテゴリが有効ならば真(TRUE)を返します。 |
103 | 1130 | そうでなければ偽(FALSE)を返します。 |
104 | 1131 | |
105 | 1132 | =item warnings::enabled($category) |
106 | 1133 | |
107 | 1134 | =begin original |
108 | 1135 | |
109 | 1136 | Return TRUE if the warnings category, C<$category>, is enabled in the |
110 | 1137 | calling module. |
111 | 1138 | Otherwise returns FALSE. |
112 | 1139 | |
113 | 1140 | =end original |
114 | 1141 | |
115 | 1142 | 呼ばれたモジュール内で警告カテゴリ(C<$category>)が有効ならば真 |
116 | 1143 | (TRUE)を返します。 |
117 | 1144 | そうでなければ偽(FALSE)を返します。 |
118 | 1145 | |
119 | 1146 | =item warnings::enabled($object) |
120 | 1147 | |
121 | 1148 | =begin original |
122 | 1149 | |
123 | 1150 | Use the name of the class for the object reference, C<$object>, as the |
124 | 1151 | warnings category. |
125 | 1152 | |
126 | 1153 | =end original |
127 | 1154 | |
128 | 1155 | オブジェクトリファレンス(C<$object>)のクラス名を警告カテゴリとして |
129 | 1156 | 使います。 |
130 | 1157 | |
131 | 1158 | =begin original |
132 | 1159 | |
133 | 1160 | Return TRUE if that warnings category is enabled in the first scope |
134 | 1161 | where the object is used. |
135 | 1162 | Otherwise returns FALSE. |
136 | 1163 | |
137 | 1164 | =end original |
138 | 1165 | |
139 | 1166 | そのオブジェクトが使われた最初のスコープ内でその警告カテゴリが有効ならば |
140 | 1167 | 真(TRUE)を返します。 |
141 | 1168 | そうでなければ偽(FALSE)を返します。 |
142 | 1169 | |
1170 | =item warnings::fatal_enabled() | |
1171 | ||
1172 | =begin original | |
1173 | ||
1174 | Return TRUE if the warnings category with the same name as the current | |
1175 | package has been set to FATAL in the calling module. | |
1176 | Otherwise returns FALSE. | |
1177 | ||
1178 | =end original | |
1179 | ||
1180 | 呼ばれたモジュール内で、現在のパッケージと同じ名前の警告カテゴリが FATAL に | |
1181 | 設定されているならば真(TRUE)を返します。 | |
1182 | そうでなければ偽(FALSE)を返します。 | |
1183 | ||
1184 | =item warnings::fatal_enabled($category) | |
1185 | ||
1186 | =begin original | |
1187 | ||
1188 | Return TRUE if the warnings category C<$category> has been set to FATAL in | |
1189 | the calling module. | |
1190 | Otherwise returns FALSE. | |
1191 | ||
1192 | =end original | |
1193 | ||
1194 | 呼ばれたモジュール内で、警告カテゴリ(C<$category>)が FATAL に | |
1195 | 設定されているならば真(TRUE)を返します。 | |
1196 | そうでなければ偽(FALSE)を返します。 | |
1197 | ||
1198 | =item warnings::fatal_enabled($object) | |
1199 | ||
1200 | =begin original | |
1201 | ||
1202 | Use the name of the class for the object reference, C<$object>, as the | |
1203 | warnings category. | |
1204 | ||
1205 | =end original | |
1206 | ||
1207 | オブジェクトリファレンス(C<$object>)のクラス名を警告カテゴリとして | |
1208 | 使います。 | |
1209 | ||
1210 | =begin original | |
1211 | ||
1212 | Return TRUE if that warnings category has been set to FATAL in the first | |
1213 | scope where the object is used. | |
1214 | Otherwise returns FALSE. | |
1215 | ||
1216 | =end original | |
1217 | ||
1218 | そのオブジェクトが使われた最初のスコープ内でその警告カテゴリが FATAL に | |
1219 | 設定されているならば真(TRUE)を返します。 | |
1220 | そうでなければ偽(FALSE)を返します。 | |
1221 | ||
143 | 1222 | =item warnings::warn($message) |
144 | 1223 | |
145 | 1224 | =begin original |
146 | 1225 | |
147 | 1226 | Print C<$message> to STDERR. |
148 | 1227 | |
149 | 1228 | =end original |
150 | 1229 | |
151 | 1230 | STDERR に C<$message> を出力します。 |
152 | 1231 | |
153 | 1232 | =begin original |
154 | 1233 | |
155 | 1234 | Use the warnings category with the same name as the current package. |
156 | 1235 | |
157 | 1236 | =end original |
158 | 1237 | |
159 | 1238 | 現在のパッケージと同じ名前の警告カテゴリを使います。 |
160 | 1239 | |
161 | 1240 | =begin original |
162 | 1241 | |
163 | 1242 | If that warnings category has been set to "FATAL" in the calling module |
164 | 1243 | then die. Otherwise return. |
165 | 1244 | |
166 | 1245 | =end original |
167 | 1246 | |
168 | 1247 | もし、呼ばれたモジュール内でその警告カテゴリーに "FATAL" が |
169 | 1248 | 設定されていたならば、終了(die)します。 |
170 | 1249 | |
171 | 1250 | =item warnings::warn($category, $message) |
172 | 1251 | |
173 | 1252 | =begin original |
174 | 1253 | |
175 | 1254 | Print C<$message> to STDERR. |
176 | 1255 | |
177 | 1256 | =end original |
178 | 1257 | |
179 | 1258 | STDERR に C<$message> を出力します。 |
180 | 1259 | |
181 | 1260 | =begin original |
182 | 1261 | |
183 | 1262 | If the warnings category, C<$category>, has been set to "FATAL" in the |
184 | 1263 | calling module then die. Otherwise return. |
185 | 1264 | |
186 | 1265 | =end original |
187 | 1266 | |
188 | 1267 | もし、呼ばれたモジュール内で警告カテゴリ(C<$category>)に "FATAL" が |
189 | 1268 | 設定されていたならば、終了(die)します。 |
190 | 1269 | |
191 | 1270 | =item warnings::warn($object, $message) |
192 | 1271 | |
193 | 1272 | =begin original |
194 | 1273 | |
195 | 1274 | Print C<$message> to STDERR. |
196 | 1275 | |
197 | 1276 | =end original |
198 | 1277 | |
199 | 1278 | STDERR に C<$message> を出力します。 |
200 | 1279 | |
201 | 1280 | =begin original |
202 | 1281 | |
203 | 1282 | Use the name of the class for the object reference, C<$object>, as the |
204 | 1283 | warnings category. |
205 | 1284 | |
206 | 1285 | =end original |
207 | 1286 | |
208 | 1287 | オブジェクトリファレンス(C<$object>)のクラス名を警告カテゴリとして |
209 | 1288 | 使います。 |
210 | 1289 | |
211 | 1290 | =begin original |
212 | 1291 | |
213 | 1292 | If that warnings category has been set to "FATAL" in the scope where C<$object> |
214 | 1293 | is first used then die. Otherwise return. |
215 | 1294 | |
216 | 1295 | =end original |
217 | 1296 | |
218 | 1297 | もし、C<$object> が最初に使われたスコープ内でその警告カテゴリに |
219 | 1298 | "FATAL" が設定されていたならば、終了(die)します。 |
220 | 1299 | |
221 | 1300 | =item warnings::warnif($message) |
222 | 1301 | |
223 | 1302 | =begin original |
224 | 1303 | |
225 | 1304 | Equivalent to: |
226 | 1305 | |
227 | 1306 | =end original |
228 | 1307 | |
229 | 1308 | 以下のものと等価です: |
230 | 1309 | |
231 | 1310 | if (warnings::enabled()) |
232 | 1311 | { warnings::warn($message) } |
233 | 1312 | |
234 | 1313 | =item warnings::warnif($category, $message) |
235 | 1314 | |
236 | 1315 | =begin original |
237 | 1316 | |
238 | 1317 | Equivalent to: |
239 | 1318 | |
240 | 1319 | =end original |
241 | 1320 | |
242 | 1321 | 以下のものと等価です: |
243 | 1322 | |
244 | 1323 | if (warnings::enabled($category)) |
245 | 1324 | { warnings::warn($category, $message) } |
246 | 1325 | |
247 | 1326 | =item warnings::warnif($object, $message) |
248 | 1327 | |
249 | 1328 | =begin original |
250 | 1329 | |
251 | 1330 | Equivalent to: |
252 | 1331 | |
253 | 1332 | =end original |
254 | 1333 | |
255 | 1334 | 以下のものと等価です: |
256 | 1335 | |
257 | 1336 | if (warnings::enabled($object)) |
258 | 1337 | { warnings::warn($object, $message) } |
259 | 1338 | |
1339 | =item warnings::register_categories(@names) | |
1340 | ||
1341 | =begin original | |
1342 | ||
1343 | This registers warning categories for the given names and is primarily for | |
1344 | use by the warnings::register pragma. | |
1345 | ||
1346 | =end original | |
1347 | ||
1348 | これは指定された名前の警告カテゴリを登録します; 主に | |
1349 | warnings::register プラグマで使われるものです。 | |
1350 | ||
260 | 1351 | =back |
261 | 1352 | |
262 | 1353 | =begin original |
263 | 1354 | |
264 | See L<perlmodlib/Pragmatic Modules> and L<perl | |
1355 | See also L<perlmodlib/Pragmatic Modules> and L<perldiag>. | |
265 | 1356 | |
266 | 1357 | =end original |
267 | 1358 | |
268 | L<perlmodlib/Pragmatic Modules> と L<perl | |
1359 | L<perlmodlib/Pragmatic Modules> と L<perldiag> も見てください。 | |
1360 | ||
1361 | =begin meta | |
1362 | ||
1363 | Translate: SHIRAKATA Kentaro <argrath@ub32.org> | |
1364 | Status: completed | |
1365 | ||
1366 | =end meta | |
269 | 1367 | |
270 | 1368 | =cut |