11 sub DEFAULT_ON () { 1 }
12 sub DEFAULT_OFF () { 2 }
17 'io' => { 'pipe' => DEFAULT_OFF,
18 'unopened' => DEFAULT_OFF,
19 'closed' => DEFAULT_OFF,
20 'newline' => DEFAULT_OFF,
21 'exec' => DEFAULT_OFF,
23 'syntax' => { 'ambiguous' => DEFAULT_OFF,
24 'semicolon' => DEFAULT_OFF,
25 'precedence' => DEFAULT_OFF,
26 'bareword' => DEFAULT_OFF,
27 'reserved' => DEFAULT_OFF,
28 'digit' => DEFAULT_OFF,
29 'parenthesis' => DEFAULT_OFF,
30 'deprecated' => DEFAULT_OFF,
31 'printf' => DEFAULT_OFF,
32 'prototype' => DEFAULT_OFF,
35 'severe' => { 'inplace' => DEFAULT_ON,
36 'internal' => DEFAULT_ON,
37 'debugging' => DEFAULT_ON,
38 'malloc' => DEFAULT_ON,
40 'void' => DEFAULT_OFF,
41 'recursion' => DEFAULT_OFF,
42 'redefine' => DEFAULT_OFF,
43 'numeric' => DEFAULT_OFF,
44 'uninitialized' => DEFAULT_OFF,
45 'once' => DEFAULT_OFF,
46 'misc' => DEFAULT_OFF,
47 'regexp' => DEFAULT_OFF,
48 'glob' => DEFAULT_OFF,
50 'chmod' => DEFAULT_OFF,
51 'umask' => DEFAULT_OFF,
52 'untie' => DEFAULT_OFF,
53 'substr' => DEFAULT_OFF,
54 'taint' => DEFAULT_OFF,
55 'signal' => DEFAULT_OFF,
56 'closure' => DEFAULT_OFF,
57 'overflow' => DEFAULT_OFF,
58 'portable' => DEFAULT_OFF,
59 'utf8' => DEFAULT_OFF,
60 'exiting' => DEFAULT_OFF,
61 'pack' => DEFAULT_OFF,
62 'unpack' => DEFAULT_OFF,
63 #'default' => DEFAULT_ON,
68 ###########################################################################
71 $t .= "\t" x ($l - (length($t) + 1) / 8);
75 ###########################################################################
87 foreach $k (sort keys %$tre) {
89 die "duplicate key $k\n" if defined $list{$k} ;
90 $Value{$index} = uc $k ;
91 push @{ $list{$k} }, $index ++ ;
93 { push (@{ $list{$k} }, walk ($v)) }
94 push @list, @{ $list{$k} } ;
100 ###########################################################################
109 for ($i = 1 ; $i < @a; ++ $i) {
111 if $a[$i] == $a[$i - 1] + 1 && $a[$i] + 1 == $a[$i + 1] ;
114 my $out = join(",",@out);
116 $out =~ s/,(\.\.,)+/../g ;
120 ###########################################################################
128 my $max = (sort {$a <=> $b} map { length $_ } keys %$tre)[-1] ;
130 $prefix .= " " x $indent ;
131 foreach $k (sort keys %$tre) {
133 print $prefix . "|\n" ;
134 print $prefix . "+- $k" ;
137 print " " . "-" x ($max - length $k ) . "+\n" ;
138 printTree ($v, $prefix . "|" , $max + $indent - 1)
146 ###########################################################################
151 my $mask = "\x00" x $max ;
155 vec($mask, $_, 1) = 1 ;
158 #$string = unpack("H$max", $mask) ;
159 #$string =~ s/(..)/\x$1/g;
160 foreach (unpack("C*", $mask)) {
161 $string .= '\x' . sprintf("%2.2x", $_) ;
166 ###########################################################################
168 if (@ARGV && $ARGV[0] eq "tree")
171 printTree($tree, " ", 4) ;
176 unlink "lib/warnings.pm";
177 open(WARN, ">warnings.h") || die "Can't create warnings.h: $!\n";
178 open(PM, ">lib/warnings.pm") || die "Can't create lib/warnings.pm: $!\n";
181 /* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
182 This file is built by warnings.pl
183 Any changes made here will be lost!
187 #define Off(x) ((x) / 8)
188 #define Bit(x) (1 << ((x) % 8))
189 #define IsSet(a, x) ((a)[Off(x)] & Bit(x))
192 #define G_WARN_OFF 0 /* $^W == 0 */
193 #define G_WARN_ON 1 /* -w flag and $^W != 0 */
194 #define G_WARN_ALL_ON 2 /* -W flag */
195 #define G_WARN_ALL_OFF 4 /* -X flag */
196 #define G_WARN_ONCE 8 /* set if 'once' ever enabled */
197 #define G_WARN_ALL_MASK (G_WARN_ALL_ON|G_WARN_ALL_OFF)
199 #define pWARN_STD Nullsv
200 #define pWARN_ALL (Nullsv+1) /* use warnings 'all' */
201 #define pWARN_NONE (Nullsv+2) /* no warnings 'all' */
203 #define specialWARN(x) ((x) == pWARN_STD || (x) == pWARN_ALL || \
210 #@{ $list{"all"} } = walk ($tree) ;
215 my $warn_size = int($index / 8) + ($index % 8 != 0) ;
218 foreach $k (sort { $a <=> $b } keys %Value) {
219 print WARN tab(5, "#define WARN_$Value{$k}"), "$k\n" ;
223 print WARN tab(5, '#define WARNsize'), "$warn_size\n" ;
224 #print WARN tab(5, '#define WARN_ALLstring'), '"', ('\377' x $warn_size) , "\"\n" ;
225 print WARN tab(5, '#define WARN_ALLstring'), '"', ('\125' x $warn_size) , "\"\n" ;
226 print WARN tab(5, '#define WARN_NONEstring'), '"', ('\0' x $warn_size) , "\"\n" ;
230 #define isLEXWARN_on (PL_curcop->cop_warnings != pWARN_STD)
231 #define isLEXWARN_off (PL_curcop->cop_warnings == pWARN_STD)
232 #define isWARN_ONCE (PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
233 #define isWARN_on(c,x) (IsSet(SvPVX(c), 2*(x)))
234 #define isWARNf_on(c,x) (IsSet(SvPVX(c), 2*(x)+1))
237 ( ! specialWARN(PL_curcop->cop_warnings) && \
238 ( isWARNf_on(PL_curcop->cop_warnings, WARN_ALL) || \
239 isWARNf_on(PL_curcop->cop_warnings, x)))
242 ( (isLEXWARN_on && PL_curcop->cop_warnings != pWARN_NONE && \
243 (PL_curcop->cop_warnings == pWARN_ALL || \
244 isWARN_on(PL_curcop->cop_warnings, x) ) ) \
245 || (isLEXWARN_off && PL_dowarn & G_WARN_ON) )
247 #define ckWARN2(x,y) \
248 ( (isLEXWARN_on && PL_curcop->cop_warnings != pWARN_NONE && \
249 (PL_curcop->cop_warnings == pWARN_ALL || \
250 isWARN_on(PL_curcop->cop_warnings, x) || \
251 isWARN_on(PL_curcop->cop_warnings, y) ) ) \
252 || (isLEXWARN_off && PL_dowarn & G_WARN_ON) )
254 #define ckWARN_d(x) \
255 (isLEXWARN_off || PL_curcop->cop_warnings == pWARN_ALL || \
256 (PL_curcop->cop_warnings != pWARN_NONE && \
257 isWARN_on(PL_curcop->cop_warnings, x) ) )
259 #define ckWARN2_d(x,y) \
260 (isLEXWARN_off || PL_curcop->cop_warnings == pWARN_ALL || \
261 (PL_curcop->cop_warnings != pWARN_NONE && \
262 (isWARN_on(PL_curcop->cop_warnings, x) || \
263 isWARN_on(PL_curcop->cop_warnings, y) ) ) )
265 /* end of file warnings.h */
272 last if /^KEYWORDS$/ ;
276 #$list{'all'} = [ $offset .. 8 * ($warn_size/2) - 1 ] ;
278 #my %Keys = map {lc $Value{$_}, $_} keys %Value ;
280 print PM "%Offsets = (\n" ;
281 foreach my $k (sort { $a <=> $b } keys %Value) {
282 my $v = lc $Value{$k} ;
284 print PM tab(4, " '$v'"), "=> $k,\n" ;
289 print PM "%Bits = (\n" ;
290 foreach $k (sort keys %list) {
293 my @list = sort { $a <=> $b } @$v ;
295 print PM tab(4, " '$k'"), '=> "',
296 # mkHex($warn_size, @list),
297 mkHex($warn_size, map $_ * 2 , @list),
298 '", # [', mkRange(@list), "]\n" ;
303 print PM "%DeadBits = (\n" ;
304 foreach $k (sort keys %list) {
307 my @list = sort { $a <=> $b } @$v ;
309 print PM tab(4, " '$k'"), '=> "',
310 # mkHex($warn_size, @list),
311 mkHex($warn_size, map $_ * 2 + 1 , @list),
312 '", # [', mkRange(@list), "]\n" ;
316 print PM '$NONE = "', ('\0' x $warn_size) , "\";\n" ;
317 print PM '$LAST_BIT = ' . "$index ;\n" ;
318 print PM '$BYTES = ' . "$warn_size ;\n" ;
327 # This file was created by warnings.pl
328 # Any changes made here will be lost.
333 our $VERSION = '1.00';
337 warnings - Perl pragma to control optional warnings
347 use warnings::register;
348 if (warnings::enabled()) {
349 warnings::warn("some warning");
352 if (warnings::enabled("void")) {
353 warnings::warn("void", "some warning");
356 if (warnings::enabled($object)) {
357 warnings::warn($object, "some warning");
360 warnif("some warning");
361 warnif("void", "some warning");
362 warnif($object, "some warning");
366 If no import list is supplied, all possible warnings are either enabled
369 A number of functions are provided to assist module authors.
373 =item use warnings::register
375 Creates a new warnings category with the same name as the package where
376 the call to the pragma is used.
378 =item warnings::enabled()
380 Use the warnings category with the same name as the current package.
382 Return TRUE if that warnings category is enabled in the calling module.
383 Otherwise returns FALSE.
385 =item warnings::enabled($category)
387 Return TRUE if the warnings category, C<$category>, is enabled in the
389 Otherwise returns FALSE.
391 =item warnings::enabled($object)
393 Use the name of the class for the object reference, C<$object>, as the
396 Return TRUE if that warnings category is enabled in the first scope
397 where the object is used.
398 Otherwise returns FALSE.
400 =item warnings::warn($message)
402 Print C<$message> to STDERR.
404 Use the warnings category with the same name as the current package.
406 If that warnings category has been set to "FATAL" in the calling module
407 then die. Otherwise return.
409 =item warnings::warn($category, $message)
411 Print C<$message> to STDERR.
413 If the warnings category, C<$category>, has been set to "FATAL" in the
414 calling module then die. Otherwise return.
416 =item warnings::warn($object, $message)
418 Print C<$message> to STDERR.
420 Use the name of the class for the object reference, C<$object>, as the
423 If that warnings category has been set to "FATAL" in the scope where C<$object>
424 is first used then die. Otherwise return.
427 =item warnings::warnif($message)
431 if (warnings::enabled())
432 { warnings::warn($message) }
434 =item warnings::warnif($category, $message)
438 if (warnings::enabled($category))
439 { warnings::warn($category, $message) }
441 =item warnings::warnif($object, $message)
445 if (warnings::enabled($object))
446 { warnings::warn($object, $message) }
450 See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
458 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
464 foreach my $word (@_) {
465 if ($word eq 'FATAL') {
468 elsif ($catmask = $Bits{$word}) {
470 $mask |= $DeadBits{$word} if $fatal ;
473 { croak("unknown warnings category '$word'")}
481 my $mask = ${^WARNING_BITS} ;
482 if (vec($mask, $Offsets{'all'}, 1)) {
483 $mask |= $Bits{'all'} ;
484 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
486 ${^WARNING_BITS} = $mask | bits(@_ ? @_ : 'all') ;
491 my $mask = ${^WARNING_BITS} ;
492 if (vec($mask, $Offsets{'all'}, 1)) {
493 $mask |= $Bits{'all'} ;
494 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
496 ${^WARNING_BITS} = $mask & ~ (bits(@_ ? @_ : 'all') | $All) ;
506 # check the category supplied.
509 croak ("not an object")
510 if $category !~ /^([^=]+)=/ ;+
514 $offset = $Offsets{$category};
515 croak("unknown warnings category '$category'")
516 unless defined $offset;
519 $category = (caller(1))[0] ;
520 $offset = $Offsets{$category};
521 croak("package '$category' not registered for warnings")
522 unless defined $offset ;
525 my $this_pkg = (caller(1))[0] ;
530 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
531 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
536 for ($i = 2 ; $pkg = (caller($i))[0] ; ++ $i) {
537 last if $pkg ne $this_pkg ;
540 if !$pkg || $pkg eq $this_pkg ;
543 my $callers_bitmask = (caller($i))[9] ;
544 return ($callers_bitmask, $offset, $i) ;
549 croak("Usage: warnings::enabled([category])")
550 unless @_ == 1 || @_ == 0 ;
552 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
554 return 0 unless defined $callers_bitmask ;
555 return vec($callers_bitmask, $offset, 1) ||
556 vec($callers_bitmask, $Offsets{'all'}, 1) ;
562 croak("Usage: warnings::warn([category,] 'message')")
563 unless @_ == 2 || @_ == 1 ;
566 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
567 local $Carp::CarpLevel = $i ;
569 if vec($callers_bitmask, $offset+1, 1) ||
570 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
576 croak("Usage: warnings::warnif([category,] 'message')")
577 unless @_ == 2 || @_ == 1 ;
580 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
581 local $Carp::CarpLevel = $i ;
584 unless defined $callers_bitmask &&
585 (vec($callers_bitmask, $offset, 1) ||
586 vec($callers_bitmask, $Offsets{'all'}, 1)) ;
589 if vec($callers_bitmask, $offset+1, 1) ||
590 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;