This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move the SETJMP exception-handing definitions from scope.h to cop.h
[perl5.git] / warnings.pl
index 875d91e..e7659b9 100644 (file)
@@ -1,7 +1,6 @@
 #!/usr/bin/perl
 
-
-$VERSION = '1.00';
+$VERSION = '1.02';
 
 BEGIN {
   push @INC, './lib';
@@ -50,7 +49,6 @@ my $tree = {
                'misc'          => [ 5.008, DEFAULT_OFF],
                'regexp'        => [ 5.008, DEFAULT_OFF],
                'glob'          => [ 5.008, DEFAULT_OFF],
-               'y2k'           => [ 5.008, DEFAULT_OFF],
                'untie'         => [ 5.008, DEFAULT_OFF],
        'substr'        => [ 5.008, DEFAULT_OFF],
        'taint'         => [ 5.008, DEFAULT_OFF],
@@ -254,7 +252,9 @@ if (@ARGV && $ARGV[0] eq "tree")
 unlink "warnings.h";
 unlink "lib/warnings.pm";
 open(WARN, ">warnings.h") || die "Can't create warnings.h: $!\n";
+binmode WARN;
 open(PM, ">lib/warnings.pm") || die "Can't create lib/warnings.pm: $!\n";
+binmode PM;
 
 print WARN <<'EOM' ;
 /* !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
@@ -415,7 +415,7 @@ while (<DATA>) {
 #$list{'all'} = [ $offset .. 8 * ($warn_size/2) - 1 ] ;
 
 $last_ver = 0;
-print PM "%Offsets = (\n" ;
+print PM "our %Offsets = (\n" ;
 foreach my $k (sort { $a <=> $b } keys %ValueToName) {
     my ($name, $version) = @{ $ValueToName{$k} };
     $name = lc $name;
@@ -431,7 +431,7 @@ foreach my $k (sort { $a <=> $b } keys %ValueToName) {
 
 print PM "  );\n\n" ;
 
-print PM "%Bits = (\n" ;
+print PM "our %Bits = (\n" ;
 foreach $k (sort keys  %list) {
 
     my $v = $list{$k} ;
@@ -445,7 +445,7 @@ foreach $k (sort keys  %list) {
 
 print PM "  );\n\n" ;
 
-print PM "%DeadBits = (\n" ;
+print PM "our %DeadBits = (\n" ;
 foreach $k (sort keys  %list) {
 
     my $v = $list{$k} ;
@@ -476,7 +476,7 @@ __END__
 
 package warnings;
 
-our $VERSION = '1.00';
+our $VERSION = '1.04';
 
 =head1 NAME
 
@@ -509,6 +509,10 @@ warnings - Perl pragma to control optional warnings
 
 =head1 DESCRIPTION
 
+The C<warnings> pragma is a replacement for the command line flag C<-w>,
+but the pragma is limited to the enclosing block, while the flag is global.
+See L<perllexwarn> for more information.
+
 If no import list is supplied, all possible warnings are either enabled
 or disabled.
 
@@ -597,16 +601,15 @@ See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
 
 =cut
 
-use Carp ;
-
 KEYWORDS
 
 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
 
 sub Croaker
 {
+    require Carp;
     delete $Carp::CarpInternal{'warnings'};
-    croak(@_);
+    Carp::croak(@_);
 }
 
 sub bits
@@ -707,6 +710,8 @@ sub unimport
     ${^WARNING_BITS} = $mask ;
 }
 
+my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
+
 sub __chk
 {
     my $category ;
@@ -716,10 +721,10 @@ sub __chk
     if (@_) {
         # check the category supplied.
         $category = shift ;
-        if (ref $category) {
-            Croaker ("not an object")
-                if $category !~ /^([^=]+)=/ ;
-           $category = $;
+        if (my $type = ref $category) {
+            Croaker("not an object")
+                if exists $builtin_type{$type};
+           $category = $type;
             $isobj = 1 ;
         }
         $offset = $Offsets{$category};
@@ -744,17 +749,18 @@ sub __chk
        $i -= 2 ;
     }
     else {
-        for ($i = 2 ; $pkg = (caller($i))[0] ; ++ $i) {
-            last if $pkg ne $this_pkg ;
-        }
-        $i = 2
-            if !$pkg || $pkg eq $this_pkg ;
+        $i = _error_loc(); # see where Carp will allocate the error
     }
 
     my $callers_bitmask = (caller($i))[9] ;
     return ($callers_bitmask, $offset, $i) ;
 }
 
+sub _error_loc {
+    require Carp::Heavy;
+    goto &Carp::short_error_loc; # don't introduce another stack frame
+}                                                             
+
 sub enabled
 {
     Croaker("Usage: warnings::enabled([category])")
@@ -775,10 +781,11 @@ sub warn
 
     my $message = pop ;
     my ($callers_bitmask, $offset, $i) = __chk(@_) ;
-    croak($message)
+    require Carp;
+    Carp::croak($message)
        if vec($callers_bitmask, $offset+1, 1) ||
           vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
-    carp($message) ;
+    Carp::carp($message) ;
 }
 
 sub warnif
@@ -794,11 +801,12 @@ sub warnif
                (vec($callers_bitmask, $offset, 1) ||
                vec($callers_bitmask, $Offsets{'all'}, 1)) ;
 
-    croak($message)
+    require Carp;
+    Carp::croak($message)
        if vec($callers_bitmask, $offset+1, 1) ||
           vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
 
-    carp($message) ;
+    Carp::carp($message) ;
 }
 
 1;