X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperllexwarn.pod;h=1eb8b30087ddefaa92ec2e706aba48a61b59a2d6;hb=7360c6b444ea6e19b6583f9530f845bee19c7921;hp=3dd3ba977aad4b466e3d2c8188aef118c892703b;hpb=22d4bb9ccb8701e68f9243547d7e3a3c55f70908;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perllexwarn.pod b/pod/perllexwarn.pod index 3dd3ba9..1eb8b30 100644 --- a/pod/perllexwarn.pod +++ b/pod/perllexwarn.pod @@ -1,13 +1,16 @@ =head1 NAME +X X X perllexwarn - Perl Lexical Warnings =head1 DESCRIPTION -The C pragma is a replacement for both the command line -flag B<-w> and the equivalent Perl variable, C<$^W>. +The C pragma enables to control precisely what warnings are +to be enabled in which parts of a Perl program. It's a more flexible +alternative for both the command line flag B<-w> and the equivalent Perl +variable, C<$^W>. -The pragma works just like the existing "strict" pragma. +This pragma works just like the C pragma. This means that the scope of the warning pragma is limited to the enclosing block. It also means that the pragma setting will not leak across files (via C, C or C). This allows @@ -19,21 +22,21 @@ doesn't attempt to control the warnings will work unchanged. All warnings are enabled in a block by either of these: - use warnings ; - use warnings 'all' ; + use warnings; + use warnings 'all'; Similarly all warnings are disabled in a block by either of these: - no warnings ; - no warnings 'all' ; + no warnings; + no warnings 'all'; For example, consider the code below: - use warnings ; - my @a ; + use warnings; + my @a; { - no warnings ; - my $b = @a[0] ; + no warnings; + my $b = @a[0]; } my $c = @a[0]; @@ -62,7 +65,7 @@ example, in the code below, an C<"isn't numeric"> warning will only be reported for the C<$a> variable. my $a = "2:" + 3; - no warnings ; + no warnings; my $b = "2:" + 3; Note that neither the B<-w> flag or the C<$^W> can be used to @@ -82,9 +85,9 @@ fundamentally flawed. For a start, say you want to disable warnings in a block of code. You might expect this to be enough to do the trick: { - local ($^W) = 0 ; - my $a =+ 2 ; - my $b ; chop $b ; + local ($^W) = 0; + my $a =+ 2; + my $b; chop $b; } When this code is run with the B<-w> flag, a warning will be produced @@ -95,8 +98,8 @@ disable compile-time warnings you need to rewrite the code like this: { BEGIN { $^W = 0 } - my $a =+ 2 ; - my $b ; chop $b ; + my $a =+ 2; + my $b; chop $b; } The other big problem with C<$^W> is the way you can inadvertently @@ -107,13 +110,13 @@ the first will not. sub doit { - my $b ; chop $b ; + my $b; chop $b; } - doit() ; + doit(); { - local ($^W) = 1 ; + local ($^W) = 1; doit() } @@ -130,6 +133,7 @@ warnings are (or aren't) produced: =over 5 =item B<-w> +X<-w> This is the existing flag. If the lexical warnings pragma is B used in any of you code, or any of the modules that you use, this flag @@ -137,6 +141,7 @@ will enable warnings everywhere. See L for details of how this flag interacts with lexical warnings. =item B<-W> +X<-W> If the B<-W> flag is used on the command line, it will enable all warnings throughout the program regardless of whether warnings were disabled @@ -145,6 +150,7 @@ included via C, C or C. Think of it as the Perl equivalent of the "lint" command. =item B<-X> +X<-X> Does the exact opposite to the B<-W> flag, i.e. it disables all warnings. @@ -199,6 +205,7 @@ the C pragma to control the warning behavior of $^W-type code (using a C) if it really wants to, but not vice-versa. =head2 Category Hierarchy +X A hierarchy of "categories" have been defined to allow groups of warnings to be enabled/disabled in isolation. @@ -207,10 +214,10 @@ The current hierarchy is: all -+ | - +- chmod - | +- closure | + +- deprecated + | +- exiting | +- glob @@ -221,12 +228,16 @@ The current hierarchy is: | | | +- exec | | + | +- layer + | | | +- newline | | | +- pipe | | | +- unopened | + +- imprecision + | +- misc | +- numeric @@ -265,8 +276,6 @@ The current hierarchy is: | | | +- bareword | | - | +- deprecated - | | | +- digit | | | +- parenthesis @@ -285,7 +294,7 @@ The current hierarchy is: | +- taint | - +- umask + +- threads | +- uninitialized | @@ -296,27 +305,31 @@ The current hierarchy is: +- utf8 | +- void - | - +- y2k Just like the "strict" pragma any of these categories can be combined - use warnings qw(void redefine) ; - no warnings qw(io syntax untie) ; + use warnings qw(void redefine); + no warnings qw(io syntax untie); Also like the "strict" pragma, if there is more than one instance of the C pragma in a given scope the cumulative effect is additive. - use warnings qw(void) ; # only "void" warnings enabled + use warnings qw(void); # only "void" warnings enabled ... - use warnings qw(io) ; # only "void" & "io" warnings enabled + use warnings qw(io); # only "void" & "io" warnings enabled ... - no warnings qw(void) ; # only "io" warnings enabled + no warnings qw(void); # only "io" warnings enabled To determine which category a specific warning has been assigned to see L. +Note: In Perl 5.6.1, the lexical warnings category "deprecated" was a +sub-category of the "syntax" category. It is now a top-level category +in its own right. + + =head2 Fatal Warnings +X The presence of the word "FATAL" in the category list will escalate any warnings detected from the categories specified in the lexical scope @@ -324,18 +337,18 @@ into fatal errors. In the code below, the use of C