Giter Club home page Giter Club logo

tatsumaki's Introduction

NAME
    Tatsumaki - Non-blocking web framework based on Plack and AnyEvent

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([
          '/stream' => 'StreamWriter',
          '/feed/(\w+)' => 'FeedHandler',
          '/' => 'MainHandler',
      ]);
      return $app->psgi_app;

    And now run it with:

      plackup -s Twiggy app.psgi

WARNINGS
    This is considered as alpha quality software. Most of the stuff are
    undocumented since it's considered unstable and will likely to change.
    You should sometimes look at the source code or example apps in *eg*
    directory to see how this thing works.

    Feel free to hack on it and ask me if you have questions or suggestions
    at IRC: #plack on irc.perl.org.

DESCRIPTION
    Tatsumaki 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.

PSGI COMPATIBILITY
    When "asynchronous" is declared in your application, you need a PSGI
    server backend that supports "psgi.streaming" response style. If your
    application does server push with "stream_write", you need a server that
    supports "psgi.nonblocking" (and "psgi.streaming") as well.

    Currently Tatsumaki asynchronous application is supposed to run on
    Twiggy, Feersum, Corona and POE::Component::Server::PSGI.

    If "asynchronous" is not used, your application is supposed to run in
    any PSGI standard environments, including blocking multiprocess
    environments like Starman or Starlet.

TATSUMAKI?
    Tatsumaki is a Japanese for Tornado. Also, it might sound familiar from
    "Tatsumaki Senpuukyaku" of Ryu from Street Fighter II if you loved the
    Capcom videogame back in the day :)

AUTHOR
    Tatsuhiko Miyagawa <[email protected]>

LICENSE
    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

SEE ALSO
    AnyEvent Plack PSGI

tatsumaki's People

Contributors

miyagawa avatar jshirley avatar abh avatar mash avatar hiratara avatar plu avatar

Watchers

Omid Houshyar avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.