atoomic / perl

a repo to show what could be p7
Other
18 stars 8 forks source link

cpan/Text-Balanced: 'warnings' pragma cannot be used prior to perl-5.6 #301

Closed jkeenan closed 4 years ago

jkeenan commented 4 years ago

In the alpha-dev-03-warnings branch -- i.e., once we've turned on warnings by default -- cpan/Text-Balanced/t/09_gentag.t emits these warnings:

$ cd t; TEST_JOBS=1 ./perl harness -v ../cpan/Text-Balanced/t/09_gentag.t; cd -
../cpan/Text-Balanced/t/09_gentag.t .. 
1..37
ok 1
ok 2
ok 3
Subroutine main::f redefined at t/09_gentag.t line 32, <DATA> line 5.
ok 4
ok 5
Subroutine main::f redefined at t/09_gentag.t line 32, <DATA> line 8.
ok 6
ok 7
ok 8
ok 9
Subroutine main::f redefined at t/09_gentag.t line 32, <DATA> line 12.
ok 10
ok 11
Subroutine main::f redefined at t/09_gentag.t line 32, <DATA> line 15.
ok 12
ok 13
Subroutine main::f redefined at t/09_gentag.t line 32, <DATA> line 18.
ok 14
ok 15
ok 16
ok 17
Subroutine main::f redefined at t/09_gentag.t line 32, <DATA> line 26.
ok 18
ok 19
ok 20
ok 21
Subroutine main::f redefined at t/09_gentag.t line 32, <DATA> line 30.
ok 22
ok 23
Subroutine main::f redefined at t/09_gentag.t line 32, <DATA> line 34.
ok 24
ok 25

[snip]

ok
All tests successful.

The relevant code:

 25 while (defined($str = <DATA>))
 26 {
 27     chomp $str;
 28     $str =~ s/\\n/\n/g;
 29     if ($str =~ s/\A# USING://)
 30     {
 31         $neg = 0;
 32         eval{local$^W;*f = eval $str || die};
 33         next;
 34     }

So the warning is coming from inside the string eval at line 32.

In most other places in this branch, we would suppress this warning by prepending no warnings 'redefine'; to the beginning of $str.

However, on CPAN this distribution has an implicit minimum version of perl 5.003_096 (from Makefile.PL). AFAIK, the warnings pragma did not exist prior to perl 5.6. So we can't use no warnings here without major surgery.

More generally, $^W is used liberally throughout this CPAN distribution:

$ ack '(warnings|\$\^W)' cpan/Text-Balanced/
cpan/Text-Balanced/lib/Text/Balanced.pm
887:                if $^W && defined($_[2]) && $max > 1;

cpan/Text-Balanced/t/08_extvar.t
143:$^W;

cpan/Text-Balanced/t/01_compile.t
6:  $^W = 1;

cpan/Text-Balanced/t/09_gentag.t
32:     eval{local$^W;*f = eval $str || die};

cpan/Text-Balanced/t/05_extmul.t
23: local $^W;
94:expect   [ eval{local$^W;scalar extract_multiple($text,undef,2)} ],
111:expect  [ eval{local$^W;scalar extract_multiple($text,undef,3)} ],
128:expect  [ eval{local$^W;scalar extract_multiple($text,undef,4)} ],
146:expect  [ eval{local$^W;scalar extract_multiple($text,undef,5)} ],
234:expect  [ eval{local$^W;scalar extract_multiple($text,[\&extract_quotelike],2,1)} ],

How should we proceed? What should we request of the upstream maintainer?

@atoomic, @toddr

Thank you very much. Jim Keenan

jkeenan commented 4 years ago

I figured out a work-around for t/09_gentag.t in commit 78482fccd5, namely, simply capture the warning and do nothing further with it.

jkeenan commented 4 years ago

I figured out a work-around for t/09_gentag.t in commit 78482fc, namely, simply capture the warning and do nothing further with it.

Patches submitted upstream at https://rt.cpan.org/Ticket/Display.html?id=133514.

Closing ticket.