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

Hello,

I've a Problem with my own CPAN-Module. One of the CPAN-Tests failed (http://www.nntp.perl.org/group/perl.cpan.testers/2007/05/msg495843.html)

The test which this error causes is line 51:
45 my $w = ''; 46 is(close(STDERR), 1, 'close STDERR'); 47 is(open(STDERR, ">", \$w), 1, 'reopen STDERR'); 48 49 50 is($test->init( abc => 1), 0, 'init with unknown parameters'); 51 is(length($w) > 0, 1, 'warnings after failed init');
The $test->init() allways warns (via Carp::carp()) so it can't be that there is no warning. I think, it's the reconnect of STDERR to catch all warnings into the lexical variable $w.

Is there a known error with this behavior in perl 5.6? Or is there an error in my catch-STDERR-code? All other CPAN-tests are passed, so I think that the code is correct.

Any wisdoms about it?

__END__
tobiwan

Replies are listed 'Best First'.
Re: Catch STDERR in variables via open() failed?
by shmem (Chancellor) on May 27, 2007 at 10:18 UTC
    Printing to a scalar reference was introduced in 5.8, so there's nothing wrong with that failing on 5.6.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Catch STDERR in variables via open() failed?
by RMGir (Prior) on May 27, 2007 at 09:33 UTC
    Did perl 5.6 even support opening a stream into a scalar like that? Off the top of my head, I _think_ that's a newer feature than 5.6...

    Do you wind up with a file in the current directory with a name something like "SCALAR(0x1002f0a0)"?

    close(STDERR) followed by that same open into a variable does work under 5.8.7, if that helps...


    Mike
Re: Catch STDERR in variables via open() failed?
by jettero (Monsignor) on May 27, 2007 at 11:58 UTC
    I love the cpan testers. I have fixed so many problems with my modules because of that project.

    However, getting reports that certain 5.8 things don't work in 5.6 is less helpful... I considered that my problem though. When I asked, it was because I needed a way to instruct 5.6 testers to skip a module: testers.cpan vs perl 5.8.

    The answer was to "use 5.008" at the top of the Makefile.PL. Although, the obvious work around was to use a code block thingy in my print statement (ie {$fh}).

    -Paul