summaryrefslogtreecommitdiff
path: root/posts/2009-12-21-tatsumaki-or-how-to-write-a-nice-webapp-in-less-than-two-hours.md
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--posts/2009-12-21-tatsumaki-or-how-to-write-a-nice-webapp-in-less-than-two-hours.md (renamed from posts/2009-12-21-tatsumaki-or-how-to-write-a-nice-webapp-in-less-than-two-hours.org)57
1 files changed, 19 insertions, 38 deletions
diff --git a/posts/2009-12-21-tatsumaki-or-how-to-write-a-nice-webapp-in-less-than-two-hours.org b/posts/2009-12-21-tatsumaki-or-how-to-write-a-nice-webapp-in-less-than-two-hours.md
index 1ffab5e..0764a0a 100644
--- a/posts/2009-12-21-tatsumaki-or-how-to-write-a-nice-webapp-in-less-than-two-hours.org
+++ b/posts/2009-12-21-tatsumaki-or-how-to-write-a-nice-webapp-in-less-than-two-hours.md
@@ -1,20 +1,10 @@
-Until today, I had a script named "lifestream.pl". This script was
-triggered via cron once every hour, to fetch various feeds from services
-I use (like github, identi.ca, ...) and to process the result through a
-template and dump the result in a HTML file.
-
-Today I was reading Tatsumaki's code and some examples (Social and
-Subfeedr). Tatsumaki is a "port" tornado (a non blocking server in
-Python), based on Plack and AnyEvent. I though that using this to
-replace my old lifestream script would be a good way to test it. Two
-hours later I have a complete webapp that works (and the code is
-available here).
-
-The code is really simple: first, I define an handler for my HTTP
-request. As I have only one things to do (display entries), the handler
-is really simple:
-
-#+BEGIN_SRC perl
+Until today, I had a script named "lifestream.pl". This script was triggered via cron once every hour, to fetch various feeds from services I use (like github, identi.ca, ...) and to process the result through a template and dump the result in a HTML file.
+
+Today I was reading Tatsumaki's code and some examples (Social and Subfeedr). Tatsumaki is a "port" tornado (a non blocking server in Python), based on Plack and AnyEvent. I though that using this to replace my old lifestream script would be a good way to test it. Two hours later I have a complete webapp that works (and the code is available here).
+
+The code is really simple: first, I define an handler for my HTTP request. As I have only one things to do (display entries), the handler is really simple:
+
+``` perl
package Lifestream::Handler;
use Moose;
extends 'Tatsumaki::Handler';
@@ -30,17 +20,13 @@ is really simple:
);
}
1;
-#+END_SRC
+```
-For all the get request, 2 methods are called : memes and services. The
-memes get a list of memes to display on the page. The services get the
-list of the various services I use (to display them on a sidebar).
+For all the get request, 2 methods are called : memes and services. The memes get a list of memes to display on the page. The services get the list of the various services I use (to display them on a sidebar).
-Now, as I don't want to have anymore my lifestream.pl script in cron, I
-will let Tatsumaki do the polling. For this, I add a service to my app,
-which is just a worker.
+Now, as I don't want to have anymore my lifestream.pl script in cron, I will let Tatsumaki do the polling. For this, I add a service to my app, which is just a worker.
-#+BEGIN_SRC perl
+``` perl
package Lifestream::Worker;
use Moose;
extends 'Tatsumaki::Service';
@@ -64,14 +50,13 @@ which is just a worker.
}
);
}
-#+END_SRC
+```
-From now, every 60 minutes, feeds will be checked. Tatsumaki::HTTPClient
-is a HTTP client based on AnyEvent::HTTP.
+From now, every 60 minutes, feeds will be checked. Tatsumaki::HTTPClient is a HTTP client based on AnyEvent::HTTP.
Let's write the app now
-#+BEGIN_SRC perl
+``` perl
package Lifestream;
use Moose;
@@ -93,23 +78,19 @@ Let's write the app now
sub services {
}
-#+END_SRC
+```
-The memes and services method called from the handler are defined here.
-In the app method, I "attch" the "/" path to the handler, and I add the
-service.
+The memes and services method called from the handler are defined here. In the app method, I "attch" the "/" path to the handler, and I add the service.
and to launch the app
-#+BEGIN_SRC perl
+``` perl
my $app = Lifestream->app(config => LoadFile($config));
require Tatsumaki::Server;
Tatsumaki::Server->new(
port => 9999,
host => 0,
)->run($app);
-#+END_SRC
+```
-And that's it, I now have a nice webapp, with something like only 200
-LOC. I will keep playing with Tatsumaki as I have more ideas (and
-probably subfeedr too). Thanks to miyagawa for all this code.
+And that's it, I now have a nice webapp, with something like only 200 LOC. I will keep playing with Tatsumaki as I have more ideas (and probably subfeedr too). Thanks to miyagawa for all this code.