Skip to content

Instantly share code, notes, and snippets.

@mdom

mdom/inet.pm

Created May 21, 2019
Embed
What would you like to do?
Start mojo application for inetd server
package Mojolicious::Command::inetd;
use Mojo::Base 'Mojolicious::Command';
use Mojo::IOLoop;
use Scalar::Util 'weaken';
has description => 'Start application for inetd server';
sub run {
my ( $self, @args ) = @_;
my $tx = Mojo::Transaction::HTTP->new;
$tx->req->parse( STDIN->getline ) while !$tx->req->is_finished;
my $ua = Mojo::UserAgent->new( ioloop => Mojo::IOLoop->singleton );
$ua->server->app( $self->app );
$ua->on(
start => sub {
my ( $ua, $tx ) = @_;
weaken $tx;
$tx->res->content->unsubscribe('read')->on(
read => sub {
return if $tx->res->is_redirect;
print pop;
}
);
}
);
STDOUT->autoflush(1);
$ua->start($tx);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment