Feersum
view release on metacpan or search on metacpan
eg/chat.feersum view on Meta::CPAN
#!perl
use warnings;
use strict;
use JSON::XS;
use EV;
use Scalar::Util qw/weaken/;
use HTML::Entities qw/encode_entities/;
use URI::Escape qw/uri_unescape/;
my $clients = 0;
my @handles;
my @timers;
my @html_hdrs = (
'Content-Type' => 'text/html; charset=UTF-8',
'Cache-Control' => 'no-cache, no-store, private',
eg/chat.feersum view on Meta::CPAN
</form>
</body>
</html>
EOHTML
}
sub start_stream {
my ($r, $client) = @_;
my $w = $r->start_streaming(200, \@html_hdrs);
$handles[$client] = $w;
weaken $w;
$timers[$client] = EV::timer 1,1,sub {
$w->write('<!-- keep-alive -->') if $w;
};
$w->write(<<EOH);
<html>
<head></head>
<body>
<p>Hello! (connection $client)</p>
EOH
}
lib/Feersum/Runner.pm view on Meta::CPAN
package Feersum::Runner;
use warnings;
use strict;
use EV;
use Feersum;
use Socket qw/SOMAXCONN/;
use POSIX ();
use Scalar::Util qw/weaken/;
use Carp qw/carp croak/;
use File::Spec::Functions 'rel2abs';
use constant DEATH_TIMER => 5.0; # seconds
use constant DEATH_TIMER_INCR => 2.0; # seconds
use constant DEFAULT_HOST => 'localhost';
use constant DEFAULT_PORT => 5000;
our $INSTANCE;
sub new { ## no critic (RequireArgUnpacking)
lib/Feersum/Runner.pm view on Meta::CPAN
return;
}
# for overriding:
sub assign_request_handler { ## no critic (RequireArgUnpacking)
return $_[0]->{endjinn}->request_handler($_[1]);
}
sub run {
my $self = shift;
weaken $self;
$self->{quiet} or warn "Feersum [$$]: starting...\n";
$self->_prepare();
my $app = shift || delete $self->{app};
if (!$app && $self->{app_file}) {
local ($@, $!);
$app = do(rel2abs($self->{app_file}));
warn "couldn't parse $self->{app_file}: $@" if $@;
lib/Feersum/Runner.pm view on Meta::CPAN
$self->_start_pre_fork if $self->{pre_fork};
EV::run;
$self->{quiet} or warn "Feersum [$$]: done\n";
$self->DESTROY();
return;
}
sub _fork_another {
my ($self, $slot) = @_;
weaken $self;
my $pid = fork;
croak "failed to fork: $!" unless defined $pid;
unless ($pid) {
EV::default_loop()->loop_fork;
$self->{quiet} or warn "Feersum [$$]: starting\n";
delete $self->{_kids};
delete $self->{pre_fork};
eval { EV::run; }; ## no critic (RequireCheckingReturnValueOfEval)
carp $@ if $@;
lib/Plack/Handler/Feersum.pm view on Meta::CPAN
package Plack::Handler::Feersum;
use warnings;
use strict;
use Feersum::Runner;
use base 'Feersum::Runner';
use Scalar::Util qw/weaken/;
sub assign_request_handler {
my $self = shift;
weaken $self;
$self->{endjinn}->psgi_request_handler(shift);
# Plack::Loader::Restarter will SIGTERM the parent
$self->{_term} = EV::signal 'TERM', sub { $self->quit };
return;
}
sub _prepare {
my $self = shift;
$self->SUPER::_prepare(@_);
$self->{server_ready}->($self)
sv_resetpvn|5.017005||Viu
SvRMAGICAL|5.003007||Viu
SvRMAGICAL_off|5.003007||Viu
SvRMAGICAL_on|5.003007||Viu
SvROK|5.003007|5.003007|
SvROK_off|5.003007|5.003007|
SvROK_on|5.003007|5.003007|
SvRV|5.003007|5.003007|
SvRV_const|5.010001||Viu
SvRV_set|5.009003|5.003007|p
sv_rvunweaken|5.027004|5.027004|
sv_rvweaken|5.006000|5.006000|
SvRVx|5.003007||Viu
SvRX|5.009005|5.003007|p
SvRXOK|5.009005|5.003007|p
SV_SAVED_COPY|5.009005||Viu
SvSCREAM|5.003007||Viu
SvSCREAM_off|5.003007||Viu
SvSCREAM_on|5.003007||Viu
sv_setbool|5.035004|5.035004|
sv_setbool_mg|5.035004|5.035004|
sv_setgid|5.019001||Viu
use Test::More ();
use Socket qw/SOMAXCONN/;
use IO::Socket::INET;
use bytes; no bytes;
use blib;
use Carp qw(carp cluck confess croak);
use Encode ();
use AnyEvent ();
use AnyEvent::Handle ();
use Guard ();
use Scalar::Util qw/blessed weaken/;
use utf8;
$SIG{PIPE} = 'IGNORE';
my $CRLF = "\015\012";
sub import {
my ($pkg) = caller;
no strict 'refs';
*{$pkg.'::carp'} = \&Carp::carp;
*{$pkg.'::cluck'} = \&Carp::cluck;
*{$pkg.'::confess'} = \&Carp::confess;
*{$pkg.'::croak'} = \&Carp::croak;
*{$pkg.'::guard'} = \&Guard::guard;
*{$pkg.'::scope_guard'} = \&Guard::scope_guard;
*{$pkg.'::weaken'} = \&Scalar::Util::weaken;
*{$pkg.'::blessed'} = \&Scalar::Util::blessed;
*{$pkg.'::get_listen_socket'} = \&get_listen_socket;
*{$pkg.'::simple_client'} = \&simple_client;
return 1;
}
our $last_port;
sub get_listen_socket {
my $start = shift || 10000;
on_connect => sub {
my $h = shift;
Test::More::pass("$name connected");
$conn_cb->($h);
return;
},
on_error => $err_cb,
timeout => $opts{timeout} || 30,
);
my $strong_h = $h;
weaken($h);
my $done = sub { $done_cb->($buf,\%hdrs); $h->destroy if $h; };
$h->on_read(sub {
Test::More::fail "$name got extra bytes!";
});
$h->push_read(line => "$CRLF$CRLF", sub {
{
my @hdrs = split($CRLF, $_[1]);
my $status_line = shift @hdrs;
( run in 2.425 seconds using v1.01-cache-2.11-cpan-65fba6d93b7 )