#!/usr/bin/perl
-$VERSION = '1.01';
+$VERSION = '1.02';
BEGIN {
push @INC, './lib';
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 !!!!!!!
#$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;
print PM " );\n\n" ;
-print PM "%Bits = (\n" ;
+print PM "our %Bits = (\n" ;
foreach $k (sort keys %list) {
my $v = $list{$k} ;
print PM " );\n\n" ;
-print PM "%DeadBits = (\n" ;
+print PM "our %DeadBits = (\n" ;
foreach $k (sort keys %list) {
my $v = $list{$k} ;
package warnings;
-our $VERSION = '1.02';
+our $VERSION = '1.04';
=head1 NAME
=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.
=cut
-use Carp ;
-
KEYWORDS
$All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
sub Croaker
{
+ require Carp;
delete $Carp::CarpInternal{'warnings'};
- croak(@_);
+ Carp::croak(@_);
}
sub bits
${^WARNING_BITS} = $mask ;
}
+my %builtin_type; @builtin_type{qw(SCALAR ARRAY HASH CODE REF GLOB LVALUE Regexp)} = ();
+
sub __chk
{
my $category ;
if (@_) {
# check the category supplied.
$category = shift ;
- if (ref $category) {
- Croaker ("not an object")
- if $category !~ /^([^=]+)=/ ;
- $category = $1 ;
+ if (my $type = ref $category) {
+ Croaker("not an object")
+ if exists $builtin_type{$type};
+ $category = $type;
$isobj = 1 ;
}
$offset = $Offsets{$category};
$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])")
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
(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;