Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Capture-Tiny CPAN distribution.

Report information
The Basics
Id: 74861
Status: open
Priority: 0/
Queue: Capture-Tiny

People
Owner: Nobody in particular
Requestors: GAISSMAI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Capture::Tiny breaks under FCGI
Hi, thanks for Capture::Tiny! FCGI has a broken Tie::Handle XS implementation. If you use Capture::Tiny in a FCGI driven webapp it dies: Not a GLOB reference at .../lib/perl5/i486-linux-gnu-thread-multi/FCGI.pm line 125. The reason is the buggy Tie::Handle implementation from FCGI. See the attached test script to show the problems if STDIN is tied to such a buggy Tie::Handle class. Maybe you can solve this within Capture::Tiny's redirecting in the parent. That would be great! Best Regards Charly
Subject: capture-tiny-tied.pl
use strict; use warnings; use Capture::Tiny qw(capture); # tie STDIN to a buggy Tie::Handle implementation like FCGI does tie *STDIN, 'My::Handle'; my ( $stdin, $stdout ) = capture { system('date') }; exit; # buggy Tie::Handle implementation, play wrong as FCGI does { package My::Handle; use Carp; require Tie::Handle; @My::Handle::ISA = qw(Tie::Handle); sub TIEHANDLE { my $fh = \ do { no warnings; local *FH }; return bless $fh, shift; } #sub OPEN { @_ == 2 ? open( $_[0], $_[1] ) : open( $_[0], $_[1], $_[2] ) } sub OPEN { Carp::confess "Buggy OPEN in package 'My::Handle', died"; } sub CLOSE { close @_ } sub FILENO { -1 } }
Thanks for the report. As the documentation says, anything that modifies the handles ahead of time might break things and that's particularly true of a buggy tied handle implementation. I suspect you can localize *STDIN for the duration of the capture call, though and that should avoid the issue (at least it does in the sample code you gave me). my ($stdout, $stderr) = do { local *STDIN; capture { ... } }; Hope that helps. I'm going to close this ticket, though. Regards, David
Am Fr 10. Feb 2012, 16:27:43, DAGOLDEN schrieb: Show quoted text
> Thanks for the report. As the documentation says, anything that > modifies the handles ahead of time might break things and that's > particularly true of a buggy tied handle implementation. > > I suspect you can localize *STDIN for the duration of the capture call, > though and that should avoid the issue (at least it does in the sample > code you gave me). > > my ($stdout, $stderr) = do { local *STDIN; capture { ... } }; > > Hope that helps.
Yep, and it helps also for the real problem in the FCGI webapp! After fork_exec you untie the handles in the child code, but FCGI breaks in your parent code. I wonder if you could localize *STDIN in your part of the parent code? But you know it better for sure. Would be helpful if you could give a hint in the POD for the workaround, especially under FCGI since the die handler under FCGI hides the source of problem. Best Regards and thanks for your help Charly
I uploaded 0.16 that documents the issue and workaround. Regards, David
On Sun Feb 12 21:06:21 2012, DAGOLDEN wrote: Show quoted text
> I uploaded 0.16 that documents the issue and workaround. > > Regards, > David
I found that to get Capture::Tiny and FCGI to play nicely I needed to localize STD{IN,OUT,ERR} if they're tied, without regard to their being captured or not. Here's a pull request implementing it: https://github.com/dagolden/capture-tiny/pull/2