Tatsumaki

Non-blocking web framework based on Plack and AnyEvent
Download

Tatsumaki Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Tatsuhiko Miyagawa
  • Publisher web site:
  • http://search.cpan.org/~miyagawa/

Tatsumaki Tags


Tatsumaki Description

Non-blocking web framework based on Plack and AnyEvent The Tatsumaki Perl module is a toy port of Tornado for Perl using Plack (with non-blocking extensions) and AnyEvent.It allows you to write a web application that does a immediate response with template rendering, IO-bound delayed response (like fetching third party API or XML feeds), server push streaming and long-poll Comet in a clean unified API.SYNOPSIS ### app.psgi use Tatsumaki::Error; use Tatsumaki::Application; use Tatsumaki::HTTPClient; use Tatsumaki::Server; package MainHandler; use parent qw(Tatsumaki::Handler); sub get { my $self = shift; $self->write("Hello World"); } package FeedHandler; use parent qw(Tatsumaki::Handler); __PACKAGE__->asynchronous(1); use JSON; sub get { my($self, $query) = @_; my $client = Tatsumaki::HTTPClient->new; $client->get("http://friendfeed-api.com/v2/feed/$query", $self->async_cb(sub { $self->on_response(@_) })); } sub on_response { my($self, $res) = @_; if ($res->is_error) { Tatsumaki::Error::HTTP->throw(500); } my $json = JSON::decode_json($res->content); $self->write("Fetched " . scalar(@{$json->{entries}}) . " entries from API"); $self->finish; } package StreamWriter; use parent qw(Tatsumaki::Handler); __PACKAGE__->asynchronous(1); use AnyEvent; sub get { my $self = shift; $self->response->content_type('text/plain'); my $try = 0; my $t; $t = AE::timer 0, 0.1, sub { $self->stream_write("Current UNIX time is " . time . "\n"); if ($try++ >= 10) { undef $t; $self->finish; } }; } package main; my $app = Tatsumaki::Application->new(); return $app;And now run it with: plackup -s AnyEvent -a app.psgi Requirements: · Perl


Tatsumaki Related Software