Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created August 19, 2009 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyagawa/170208 to your computer and use it in GitHub Desktop.
Save miyagawa/170208 to your computer and use it in GitHub Desktop.
# Run a tweet as a perl script:
# perl -Mtwitter -e http://m.twitter.com/miyagawa/status/3412563203
# See http://bulknews.typepad.com/blog/2009/08/run-a-tweet-like-perl.html for details.
package twitter;
use JSON;
use LWP::Simple;
my $id;
use overload "/" => sub { $id = $_[1]; $_[0] }, fallback => 1;
sub import {
my $pkg = caller;
*{"$pkg\::com"} = *{"$pkg\::status"} = sub() { bless {}, __PACKAGE__ };
}
END {
if ($id) {
my $t = JSON::decode_json(LWP::Simple::get("http://twitter.com/status/show/$id.json"));
my $e;
if ($t->{text} =~ /^\#?perl\s/) {
system $t->{text}; $e = $!;
} else {
eval $t->{text}; $e = $@;
}
die $e if $e;
}
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment