syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm trying to build Gtk2-1.22 on Win32 with perl-5.8.0.
It builds ok, but nearly all of the tests fail because of a syntax error in TestHelper.pm, which is one of the files that ship with the Gtk2 source. Surprisingly, (to me at least), identical syntax is considered fine in both perl-5.10.0 and perl-5.12.0.
The actual error is:
C:\build\Gtk2-1.222>perl -Mblib -c blib\lib/Gtk2/TestHelper.pm syntax error at blib\lib/Gtk2/TestHelper.pm line 98, near "ok " syntax error at blib\lib/Gtk2/TestHelper.pm line 100, near "}" blib\lib/Gtk2/TestHelper.pm had compilation errors.
And here's the relevant section of the TestHelper.pm:
sub ok_idle ($;$) { 88: my ($testsub, $test_name) = @_; 89: run_main { 90: # 0 Test::More::ok 91: # 1 this block's ok() call 92: # 2 idle callback in run_main 93: # 3 Gtk2::main call in run_main 94: # 4 Gtk2::main call in run_main (again) 95: # 5 ok_idle 96: # 6 the caller we want to print 97: local $Test::Builder::Level = 6; 98: ok ($testsub->(), $test_name); 99: } 100: }
Does anyone know why perl-5.8 sees that as syntactically erroneous ? ... and what do do about it ?

I wondered if it might be something to do with the antiquated version of Test::Simple/Test::Builder I was running, so I updated to 0.96, and updated ExtUtils::MakeMaker to 6.57. Both of those modules passed all tests while building, but the syntax error persists.

Cheers,
Rob

Replies are listed 'Best First'.
Re: syntax error - perl-5.8 only
by DrHyde (Prior) on Oct 18, 2010 at 09:58 UTC

    I've seen some weird syntax error-ish bugs around subs that are prototyped to take a sub-ref as an argument, which in recent perls lets you supply what looks like a block as their argument, just like your run_main presumably is. I *thought* that that was fixed in 5.8.*, but maybe it was still present in some early 5.8 releases.

    The fix in my case was to make the code block an explicit sub-ref, thus ...

    run_main sub { ... };

      I've seen some weird syntax error-ish bugs around subs that are prototyped to take a sub-ref as an argument

      Yes, that seems to be the trouble here.

      The problem is with the run_main prototype of (;&)
      If I change that to simply (&) all seems well on 5.8, except that run_main then needs to be called with at least one argument.
      That is, with a prototype specification of (;&) we can simply do run_main; on perl-5.10 and 5.12, but with a prototype specification of (&) on my perl-5.8.0, we're not allowed to do simply run_main. Instead we have to do run_main sub {} which looks very much like what you were suggesting. But that only works on my perl-5.8.0 if I also change the prototype from (;&) to (&)
      That's the best I've yet been able to come up with.

      This may well have been fixed in later versions of perl-5.8. I haven't checked.

      Sorry it took so long to reply - I was unable to access perlmonks last night (though access to every other site was fine).

      Cheers,
      Rob
Re: syntax error - perl-5.8 only
by Anonymous Monk on Oct 19, 2010 at 16:48 UTC

    It's not something stupid to do with the space after "ok" is it? I'm asking because the first error says near "ok_" which looks a little odd.