Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 120 lines (92 sloc) 3.655 kB
8f662a7 @miyagawa initial commit
authored
1 NAME
9d6f999 @miyagawa fixed docs
authored
2 Tatsumaki - Non-blocking web framework based on Plack and AnyEvent
8f662a7 @miyagawa initial commit
authored
3
4 SYNOPSIS
9d6f999 @miyagawa fixed docs
authored
5 ### app.psgi
8f662a7 @miyagawa initial commit
authored
6 use Tatsumaki::Error;
7 use Tatsumaki::Application;
8 use Tatsumaki::HTTPClient;
9 use Tatsumaki::Server;
10
11 package MainHandler;
59f7150 @miyagawa s/Moose/Any::Moose/
authored
12 use parent qw(Tatsumaki::Handler);
8f662a7 @miyagawa initial commit
authored
13
14 sub get {
15 my $self = shift;
16 $self->write("Hello World");
17 }
18
03f6f6f @miyagawa docs
authored
19 package FeedHandler;
59f7150 @miyagawa s/Moose/Any::Moose/
authored
20 use parent qw(Tatsumaki::Handler);
c94930f @miyagawa rename nonblocking to asynchrnouns to avoid confusion with psgi.nonbl…
authored
21 __PACKAGE__->asynchronous(1);
8f662a7 @miyagawa initial commit
authored
22
62f3e93 @miyagawa docs cargo culting
authored
23 use JSON;
24
8f662a7 @miyagawa initial commit
authored
25 sub get {
26 my($self, $query) = @_;
27 my $client = Tatsumaki::HTTPClient->new;
e40d392 @miyagawa use async_cb
authored
28 $client->get("http://friendfeed-api.com/v2/feed/$query", $self->async_cb(sub { $self->on_response(@_) }));
8f662a7 @miyagawa initial commit
authored
29 }
30
31 sub on_response {
32 my($self, $res) = @_;
33 if ($res->is_error) {
34 Tatsumaki::Error::HTTP->throw(500);
35 }
36 my $json = JSON::decode_json($res->content);
37 $self->write("Fetched " . scalar(@{$json->{entries}}) . " entries from API");
38 $self->finish;
39 }
40
03f6f6f @miyagawa docs
authored
41 package StreamWriter;
59f7150 @miyagawa s/Moose/Any::Moose/
authored
42 use parent qw(Tatsumaki::Handler);
c94930f @miyagawa rename nonblocking to asynchrnouns to avoid confusion with psgi.nonbl…
authored
43 __PACKAGE__->asynchronous(1);
03f6f6f @miyagawa docs
authored
44
62f3e93 @miyagawa docs cargo culting
authored
45 use AnyEvent;
46
03f6f6f @miyagawa docs
authored
47 sub get {
48 my $self = shift;
49 $self->response->content_type('text/plain');
50
51 my $try = 0;
52 my $t; $t = AE::timer 0, 0.1, sub {
62f3e93 @miyagawa docs cargo culting
authored
53 $self->stream_write("Current UNIX time is " . time . "\n");
03f6f6f @miyagawa docs
authored
54 if ($try++ >= 10) {
55 undef $t;
56 $self->finish;
57 }
58 };
59 }
60
8f662a7 @miyagawa initial commit
authored
61 package main;
62
9d6f999 @miyagawa fixed docs
authored
63 my $app = Tatsumaki::Application->new([
64 '/stream' => 'StreamWriter',
65 '/feed/(\w+)' => 'FeedHandler',
66 '/' => 'MainHandler',
67 ]);
2dee241 @miyagawa Fixed terribly outdated doc
authored
68 return $app->psgi_app;
9d6f999 @miyagawa fixed docs
authored
69
70 And now run it with:
71
2dee241 @miyagawa Fixed terribly outdated doc
authored
72 plackup -s Twiggy app.psgi
8f662a7 @miyagawa initial commit
authored
73
4c2fb97 @miyagawa warnings
authored
74 WARNINGS
0912af9 @miyagawa some docs
authored
75 This is considered as alpha quality software. Most of the stuff are
76 undocumented since it's considered unstable and will likely to change.
77 You should sometimes look at the source code or example apps in *eg*
78 directory to see how this thing works.
79
80 Feel free to hack on it and ask me if you have questions or suggestions
81 at IRC: #plack on irc.perl.org.
4c2fb97 @miyagawa warnings
authored
82
8f662a7 @miyagawa initial commit
authored
83 DESCRIPTION
8698e1a @miyagawa docs
authored
84 Tatsumaki is a toy port of Tornado for Perl using Plack (with
03f6f6f @miyagawa docs
authored
85 non-blocking extensions) and AnyEvent.
86
8698e1a @miyagawa docs
authored
87 It allows you to write a web application that does a immediate response
88 with template rendering, IO-bound delayed response (like fetching third
89 party API or XML feeds), server push streaming and long-poll Comet in a
90 clean unified API.
03f6f6f @miyagawa docs
authored
91
c94930f @miyagawa rename nonblocking to asynchrnouns to avoid confusion with psgi.nonbl…
authored
92 PSGI COMPATIBILITY
93 When "asynchronous" is declared in your application, you need a PSGI
94 server backend that supports "psgi.streaming" response style. If your
95 application does server push with "stream_write", you need a server that
96 supports "psgi.nonblocking" (and "psgi.streaming") as well.
97
98 Currently Tatsumaki asynchronous application is supposed to run on
2dee241 @miyagawa Fixed terribly outdated doc
authored
99 Twiggy, Feersum, Corona and POE::Component::Server::PSGI.
c94930f @miyagawa rename nonblocking to asynchrnouns to avoid confusion with psgi.nonbl…
authored
100
101 If "asynchronous" is not used, your application is supposed to run in
102 any PSGI standard environments, including blocking multiprocess
2dee241 @miyagawa Fixed terribly outdated doc
authored
103 environments like Starman or Starlet.
c94930f @miyagawa rename nonblocking to asynchrnouns to avoid confusion with psgi.nonbl…
authored
104
1889d45 @miyagawa more docs
authored
105 TATSUMAKI?
106 Tatsumaki is a Japanese for Tornado. Also, it might sound familiar from
107 "Tatsumaki Senpuukyaku" of Ryu from Street Fighter II if you loved the
108 Capcom videogame back in the day :)
109
8f662a7 @miyagawa initial commit
authored
110 AUTHOR
111 Tatsuhiko Miyagawa <miyagawa@bulknews.net>
112
113 LICENSE
114 This library is free software; you can redistribute it and/or modify it
115 under the same terms as Perl itself.
116
117 SEE ALSO
20b75d9 @miyagawa remove the link to tornado not to confuse people that it's Tatsumaki …
authored
118 AnyEvent Plack PSGI
8f662a7 @miyagawa initial commit
authored
119
Something went wrong with that request. Please try again.