develooper Front page | perl.perl5.porters | Postings from February 2009

[perl #62522] warnings::register regressions introduced in 5.10

Thread Next
From:
Bram via RT
Date:
February 17, 2009 00:00
Subject:
[perl #62522] warnings::register regressions introduced in 5.10
Message ID:
rt-3.6.HEAD-12283-1234816546-297.62522-15-0@perl.org
> After upgrading to 5.10 warnings::register related warning suppression
> does not work as expected in all cases (i.e. as it did in 5.8).

Test case:

#!/usr/bin/perl -l

{
  package P1;

  sub p1 {
    if (warnings::enabled("substr")) {
      warn "foo";
    }
  }
}

{
  package P2;

  use strict;
  use warnings;
  no warnings 'substr';
  our @ISA = qw/P1/;

  sub p2 {
    my $self = shift;
    $self->p1();
  }
}


use warnings;
P2->p2();
__END__

$ perl-5.8.9 rt-62522-1.pl
(no output)

$ perl-5.10.0 rt-62522-1.pl
foo at rt-62522-1.pl line 8.


The reason why the output changed is because of:
- http://rt.perl.org/rt3/Ticket/Display.html?id=15395 'lexical warnings 
and inheritance'
- http://public.activestate.com/cgi-bin/perlbrowse/p/21167


The summary of that ticket:

When Carp::carp/Carp::cloak/Carp:* is used then the output can be 
'confusing'. That is, Carp will check @ISA for inheritence while the 
warning::enabled check will not.

Test case:

(Difference from the previous test case: removed "no warnings 
'substr';" from package P2 and use of Carp::carp instead of warn)

#!/usr/bin/perl -l

{
  package P1;
  use Carp;

  sub p1 {
    if (warnings::enabled("substr")) {
      carp "foo";
    }
  }
}

{
  package P2;

  use strict;
  use warnings;
  our @ISA = qw/P1/;   
  
  sub p2 {
    my $self = shift;
    $self->p1();
  }
}  
 

use warnings;
P2->p2();
__END__

$ perl-5.8.9 rt-62522-2.pl
foo at rt-62522-2.pl line 29

This warning is confusing in the sense that adding  no warnings 
'substr' on line 28 will have no effect on the error message; it has to 
be added in  package P2; as demonstrated by:

#!/usr/bin/perl -l

{
  package P1;
  use Carp;

  sub p1 {
    if (warnings::enabled("substr")) {
      carp "foo";
    }
  }
}

{
  package P2;

  use strict;
  use warnings;
  our @ISA = qw/P1/;

  sub p2 {
    my $self = shift;
    $self->p1();
  }
}


use warnings;
no warnings 'substr';
P2->p2();
__END__

$ perl589 rt-62522-2.pl 
foo at rt-62522-2.pl line 30


The behaviour of 5.10 makes sense but so does the behaviour of 5.8...


The result of this change is that there is no way to disable a warning 
in 'package P1' in the 'P2 package'.


Perhaps a better solution is to only return true in warnings::enabled if
- the warning is enabled in package P2; (and any other packages it 
inherits from)
- the warning is enabled in package main; 



Any thoughts?



Kind regards,

Bram

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About