Created
January 14, 2010 09:14
-
-
Save typester/277005 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
config_local.pl |
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
use Plack::Builder; | |
use Plack::Middleware::Static; | |
use Tweet; | |
my $app = Tweet->new; | |
$app->setup; | |
builder { | |
enable 'Plack::Middleware::Static', | |
path => qr{^/(js/|css/|swf/|images?/|imgs?/|static/|[^/]+\.[^/]+$)}, | |
root => $app->path_to('root')->stringify; | |
$app->handler; | |
}; |
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
return { | |
twitter => { | |
username => '', | |
password => '', | |
}, | |
}; | |
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
use Config::Pit; | |
return { | |
twitter => pit_get('twitter.com', require => { | |
username => '', | |
password => '', | |
}), | |
}; | |
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
package Tweet::Models; | |
use strict; | |
use warnings; | |
use Ark::Models '-base'; | |
register clients => sub { {} }; | |
1; | |
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
package Tweet::Controller::Root; | |
use Ark 'Controller'; | |
use Tweet::Models; | |
has '+namespace' => default => ''; | |
sub default :Path :Args { | |
my ($self, $c) = @_; | |
$c->res->status(404); | |
$c->res->body('404 Not Found'); | |
} | |
sub index :Path { | |
my ($self, $c) = @_; | |
$c->res->content_type('text/plain; charset=utf-8'); | |
$c->res->streaming(sub { | |
my $r = shift; | |
models('clients')->{"$r"} = $r; | |
}); | |
} | |
__PACKAGE__->meta->make_immutable; |
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
package Tweet; | |
use Ark; | |
use Tweet::Models; | |
use Encode; | |
use AnyEvent::Twitter::Stream; | |
use Try::Tiny; | |
# track keywords | |
my $guard; $guard = AnyEvent::Twitter::Stream->new( | |
%{ models('conf')->{twitter} }, | |
method => "filter", | |
track => "Perl,Music", | |
on_tweet => sub { | |
my $tweet = shift; | |
scalar $guard; | |
for my $k (keys %{ models('clients') }) { | |
my $client = models('clients')->{$k}; | |
try { | |
$client->write(encode_utf8 sprintf "%s: %s\n", | |
$tweet->{user}{screen_name}, $tweet->{text}); | |
} catch { | |
delete models('clients')->{$k}; | |
}; | |
} | |
}, | |
); | |
__PACKAGE__->meta->make_immutable; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment