10. $env
Streaming Interface
sub {
my $responder = shift;
my $writer = $responder->([
'200',
[ 'Content-Type' => 'text/plain' ]);
# later, of in a callback
$writer->write(“Hello world!”);
$writer->close();
}
13. AnyEvent
• event-driven programming, painless
• compatible with many other event loops
use AnyEvent::HTTP;
http_get "http://osdc.tw/",
sub { print $_[1] };
15. sub POE::Kernel::ASSERT_DEFAULT () { 1 }
use HTTP::Request;
use POE qw(Component::Client::HTTP);
POE::Component::Client::HTTP->spawn(
Alias => 'ua', # defaults to 'weeble'
Timeout => 20, # defaults to 180 seconds
);
POE::Session->create(
inline_states => {
_start => sub {
POE::Kernel->post(
'ua', # posts to the 'ua' alias
'request', # posts to ua's 'request' state
'response', # which of our states will receive the response
HTTP::Request->new(GET => “http://osdc.tw”),
);
},
_stop => sub {},
response => &response_handler,
},
);
POE::Kernel->run();
exit;
sub response_handler {
my ($request_packet, $response_packet) = @_[ARG0, ARG1];
my $request_object = $request_packet->[0];
my $response_object = $response_packet->[0];
}
19. AnyMQ
• Inspired by Tatsumaki::MessageQueue
• Refactored to support timeout handler,
multiple subscription
• Support binding to other message queues
using moose traits
• Available on CPAN and github
20. AnyMQ
my $bus = AnyMQ->new;
my $topic = $bus->topic("Foo");
my $sub = $bus->new_listener($topic);
$sub->poll(sub { my $msg = shift; })
$topic->publish($msg)
21. AnyMQ with AMQP
my $bus = AnyMQ->new_with_traits
( traits => [ ‘AMQP’],
# host => ..., port => ..);
my $topic = $bus->topic("Foo");
my $sub = $bus->new_listener($topic);
$sub->poll(sub { my $msg = shift; })
$topic->publish($msg)
24. Comet
The word comet came to English by way of the Latin word cometes. This word, in turn, came
from the Greek word κόμη, which means "hair of the head". The Greek scientist and
philosopher Aristotlefirst used the derived form of κόμη, κομήτης, to describe what he saw
as "stars with hair." Theastronomical symbol for comets is (☄), consisting of a small disc with
three hairlike extensions.
• 2006, coined by Alex Russell
• Server push for real time notification
26. Lots of hacks!
• multi-part XHR
• forever iframe, with script callbacks
• spinning “loading” indicator for FF and IE
• number of connections limits
33. Hippie
• Abstracts persistent connections:
Websocket, MXHR
Just a normal PSGI-app!
enable "+Web::Hippie";
sub { my $env = shift;
my $args = $env->{'hippie.args'};
my $handle = $env->{'hippie.handle'};
# Your handler based on PATH_INFO:
# /init, /error, /message
}