Hi,
This relates to the RT ticket at http://rt.cpan.org/Ticket/Display.html?id=6327 .

For testing that fix, I've written a simple test script (06parseregexp.t) to verify that ParseRegeExp.pm is (basically) usable. I've added it to the C/t directory and listed it in the MANIFEST file - but only on my own local copy of the Inline source (at this stage).
It looks like this:

----------------------------
use warnings;
use strict;
use Test::Simple tests => 1;

use Inline C => Config =>
   USING => 'ParseRegExp',
   #BUILD_NOISY => 1,
   DIRECTORY => '_Inline_test';


use Inline C => <<'EOC';

void foo() {
    printf( "Hello World\n" );
}

void foo2() {
    Inline_Stack_Vars;
    int i;

    Inline_Stack_Reset;

    if(0)
      printf( "Hello World again\n" ); /* tests balanced quotes bugfix */

    for(i = 24; i < 30; ++ i)
      Inline_Stack_Push(sv_2mortal(newSViv(i)));

    Inline_Stack_Done;
    Inline_Stack_Return(6);
}

EOC

my @z = foo2();

ok(scalar(@z) == 6, 'testing ParseRegExp.pm');

---------------------------- But when that test script gets run as part of 'make test', I get the following warning:

Subroutine Inline::C::get_parser redefined at C:\_32\comp\Inline\blib\lib/Inline.pm line 321.

The relevant section of Inline.pm is:

-----------------------------
317: sub pop_overrides {
318:     my ($o) = @_;
319:     for my $override (keys %{$o->{OVERRIDDEN}}) {
320:         no strict 'refs';
321:         *{$override} = $o->{OVERRIDDEN}{$override};
322:     }
323:     delete $o->{OVERRIDDEN};
324: }
325:
-----------------------------

Seems that pop_overrides() gets called when the script is run as part of 'make test', but does *not* get called when run as 'perl 06parseregexp.t'. Hence the warning is emitted *only* when the test script is run as part of 'make test'.

For that reason, I'm tempted to ignore it altogether and do nothing (option 1).

One simple fix would be to commence sub pop_overrides with "no warnings 'redefine';" (option 2) but that would, I believe, break pre 5.6 perls - something which seems to be a consideration.

Alternatively, one could avoid breaking those ancient perls by rewriting pop_overrides as (option 3):

------------------------------
sub pop_overrides {
   my $nowarn = $] >= 5.006 ? "no warnings 'redefine';" : '';
   eval ($nowarn .
   'my ($o) = @_;
   for my $override (keys %{$o->{OVERRIDDEN}}) {
       no strict "refs";
       *{$override} = $o->{OVERRIDDEN}{$override};
   }
   delete $o->{OVERRIDDEN};')
}
------------------------------

Or maybe there's a better option 4 that I haven't thought of. Comments ?

(I'll go with option 3 unless someone convinces me I should do otherwise.)

Cheers,
Rob

Reply via email to