http://www.perlmonks.org?node_id=1022654

perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:

I am getting test reports in CPAN for my P module.

Spent some time removing most or all of the new features I could think of -- replacing switch/when things like that -- thinking maybe I could get it working with -- maybe back to 5.8...not sure...

But last time had fails on 5.12-5.16 all platforms.

This time, it's 1 platform that is giving me problems I'm clueless on.

5.12 BSD.

Am getting:

# Failed test at t/P.t line 96. self-test failed: Can't locate object method "print" via package "IO:: +File" at lib/P.pm line 119. Use of uninitialized value $rcase in numeric eq (==) at t/P.t line 95. # Failed test 'received testcase 2' # at t/P.t line 95. Use of uninitialized value $rstr in pattern match (m//) at t/P.t line +96. # Failed test at t/P.t line 96. self-test failed: Can't locate object method "print" via package "IO:: +File" at lib/P.pm line 119. Use of uninitialized value $rcase in numeric eq (==) at t/P.t line 95. ...a bunch more...
In my code at 95+96, I have:
ok($caseno == $rcase, "received testcase $caseno"); if (length($re)) {ok($rstr =~ m{$re}, $name)}
Is something broken on the BSD 5.12 platform? I'm guessing that the test harness is calling print, but "print" in class IO::File, I thought, was a CORE function? How could it not be there?

Maybe someone from BSD land on here -- was perl badly broken in 5.12?

Test case uses 'Test::More'....

Thanks -- I'm sure others have dealt with this type of stuff before, yes? ;-)

Replies are listed 'Best First'.
Re: perl 5.12 BSD portability (CPAN test result)...print
by syphilis (Archbishop) on Mar 10, 2013 at 09:51 UTC
    I'm guessing that the test harness is calling print, but "print" in class IO::File

    The error is being triggered by line 119 of lib/P.pm. That line is:
    $fh->print ($res . (!$ctx ? "\n" : "") );
    and apparently $fh is an IO::File object ... in other words, you've just called object method "print" on an IO::File object. Is that what you intended ?
    Anyway ... hence tobyink's suggestion.

    It all looks very weird to me - I can't see how $fh has come to be an IO::File object in the first place.
    And it's rather odd for a test suite to be doing anything with lib/P.pm - normally the test suite would be using the P.pm that has been put into blib.

    The module also fails to pass its test on Windows. I'm guessing you already know that (as that test suite does some things that simply won't work on Windows).

    Cheers,
    Rob
      Why only on BSD and only on P5.12?

      Windows...yeah...not interesting fail...missing utils, so some win-specific hack there.

      but the fail on 512/Bsd and not linux and not 514 or 516 -- previous report had many more fails on other clients... that only this one is causing probs -- what is diff about this combo? That's what's stumped me...

      Have no easy way to test this on a BSD5.12 system though and am not sure if a change like above wouldn't cause probs on other systems.

      . As for $fh... P takes 'globs'. or IO handles. Does that answer your Q?
      ----
      later

      If I added IO::Handle/IO::File... and if that worked, it would seem to indicated that IO::Handle doesn't have an @ISA relation with IO::Handle. How likely is that on 1 platform?

        CPAN test reports are like money - 95% of it is controlled by just 5% of the population (or something like that).

        There are a small handful of individuals who submit a vast number of CPAN test reports. Check the failure reports you are getting - are they all from the same person? If so, perhaps their system is configured unusually.

        Otherwise, I'd personally just document the problem and then forget about it. Something like:

        =head1 BUGS The test suite fails in Perl 5.12 on BSD operating systems. Upgrading to Perl 5.14 or above should solve this problem. Patches to fix the issue would be joyfully accepted.

        PS: for a hint about why this bug doesn't affect 5.14 and above, see Unexpected behavior of function 'say'.

        package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: perl 5.12 BSD portability (CPAN test result)...print
by tobyink (Canon) on Mar 10, 2013 at 09:10 UTC

    Hmmm... mysterious. Try adding this to your module:

    use IO::File (); use IO::Handle ();
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: perl 5.12 BSD portability (CPAN test result)...print
by ikegami (Patriarch) on Mar 11, 2013 at 19:19 UTC

    Before 5.14, you had to do

    use IO::Handle qw( );

    to load the module if you wanted to use its methods. Since 5.14.0, IO::Handle and IO::File are loaded on demand.

    This has nothing to do with BSD.

      Um... so everyone who uses 'print' or 'printf' needed to use IO::Handle? I doubt that is what you mean, is it?

      In any case, changing the code from '$fh->print' to 'print $fh' seems to have fixed the problem. Of *course* it makes sense -- it's perl! :-)

      That uncovered one last (??*crossing fingers*??) bug where the 'cat' was involved, which was unrelated to the 'rev', which I just supplied in my test directory (in a perl-1-liner script).simulated in a perl 1-liner:

      P> more t/rev sub rv{1>=length $_[0]?$_[0]:substr( $_[0],-1).rv(substr $_[0],0,-1)} +$_=<>;chomp; print rv($_);
      The 'cat' was for my STDERR test, which I cleaned up (and got rid of using 'cat' in testing...didn't want any Humane Society/PITA complaints). It's a split output, where the first part of the line put out by the 'generic example' code is on STDOUT, and the 2nd part is on STDERR... so I just run it twice for that test:
      if ($caseno == 5) { my $null; my $dev; open($null, ">", $dev="/dev/null") or open($null, ">", $dev="NUL:") or die "Cannot open /dev/null nor NUL:"; close ($null); my $resp = get_case($matchp->[0],"2>$dev"); $resp =~ m{$weak_match_expr}; ($rcase,$name, $rstr) = ($1,$2,$3); $resp = get_case($matchp->[0],"2>&1 >$dev"); $resp =~ m{$weak_match_expr}; $rstr = $2; } .... ok($rcase && $caseno == $rcase, "received testcase $caseno"); if (length($re)) {ok($rstr =~ m{$re}, $name)} }
      Hopefully "/dev/null" or "NUL" will work (it works on my linux and on Windows strawbelly16.2.)

      Tedia, tedia, tedia....;-)

      Thanks again for the assists...this is my testing the waters, as it were...
      hopefully it will go well...

        Um... so everyone who uses 'print' or 'printf' needed to use IO::Handle? I doubt that is what you mean, is it?

        It's not what I meant. It's not what I said.

        Everyone who uses IO:Handle's print or printf method (e.g. $fh->print("foo");) needs to use use IO::Handle; or similar before 5.14.

        Using the print or printf operator (e.g. print $fh "foo";) does not require the use of use IO::Handle;.

        Um... so everyone who uses 'print' or 'printf' needed to use IO::Handle?

        Everyone who wanted to use those as methods on filehandles had to use IO::Handle, yes.

        Hopefully "/dev/null" or "NUL" will work (it works on my linux and on Windows strawbelly16.2.)

        For portability File::Spec->devnull() works well.

        Cheers,
        Rob