Created
March 19, 2010 22:50
-
-
Save miyagawa/338284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# TWITTER_USERNAME=xxx TWITTER_PASSWORD=xxx plackup -s Twiggy tweet_displayer.pl | |
use 5.010; | |
use AnyEvent::Twitter::Stream; | |
use Markapl; | |
use autobox::Core; | |
use autobox::Encode; | |
my $buf = []; | |
# NOTE: $stream should live outside this PSGI file scope | |
# Change state to our if you're using perl 5.8 | |
state $stream = AnyEvent::Twitter::Stream->new( | |
username => $ENV{TWITTER_USERNAME}, | |
password => $ENV{TWITTER_PASSWORD}, | |
method => 'sample', | |
on_tweet => sub { | |
my $tweet = shift; | |
$buf->unshift($tweet); | |
$buf = $buf->slice(0..9) if $buf->size >= 10; | |
}, | |
); | |
sub { | |
my $mp = html { body { ul { $buf->map(sub { li { $_->{text} } }) } } }; | |
return [ | |
200, | |
[ 'Content-Type', 'text/html; charset=utf-8' ], | |
[ $mp->()->encode('utf8') ], | |
]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment