Created
August 19, 2009 06:36
-
-
Save miyagawa/170208 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
# 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