[Catalyst] IO::Pipe and the Catalyst Server

Bill Moseley moseley at hank.org
Thu Feb 5 06:25:15 GMT 2009


I have a module that uses IO::Pipe and when I run it under the
Catalyst server the pipe doesn't work (see below).

Anyone using IO::Pipe in an application?  Even if not, any idea
what's happening here?  Is the Cat server selecting this handle
somehow?

If I run the application with mod_perl the pipe works perfectly.


It's a very simple module:

    $ cat lib/Echo.pm 
    package Echo;
    use strict;
    use warnings;
    use IO::Pipe;

    sub sayit {
        my $pipe = IO::Pipe->new;
        $pipe->reader( '/bin/echo', 'hello' );

        warn "about to read from handle\n";
        while ( <$pipe> ) {
            chomp;
            warn "Got [$_]\n";
        }
    }

    1;


Produces:

    $ perl -Ilib -MEcho -le 'Echo::sayit()'
    about to read from handle
    Got [hello]


Now use it in a Catalyst application:

    $ cat lib/Pipe.pm 
    package Pipe;
    use strict;
    use warnings;
    use Catalyst::Runtime '5.70';
    use Catalyst;
    use NEXT;

    use Echo;

    __PACKAGE__->config( name => 'Pipe' );
    __PACKAGE__->setup();


    sub default :Private {
        my ( $self, $c ) = @_;
        Echo::sayit();
        $c->response->body( 'echo' );
        $c->response->status(200);
        $c->response->content_type( 'text/plain' );
    }


    1;

Running Catalyst from the command line:

    $ script/pipe_test.pl /
    about to read from handle
    Got [hello]      <-------- what I would expect
    echo

But, using the server:

    $ script/pipe_server.pl

In another window:

    $ GET http://localhost:3000/
    echo

And the server's output:

    $ script/pipe_server.pl
    You can connect to your server at http://bumby2:3000
    about to read from handle
    hello

Looks like my pipe is leaking.

Again, if I run the app under mod_perl it works as expected.

I might try IPC::Cmd next.


-- 
Bill Moseley
moseley at hank.org
Sent from my iMutt




More information about the Catalyst mailing list