Plurking in Perl

作者:   發佈於:  

Net-Plurk and AnyEvent-Plurk are fine, but they are sometimes too big for one small purpose.

I use this small piece of code to post to plurk:

package PlurkPoster;
use Object::Tiny qw(username password);
use WWW::Mechanize;
use Try::Tiny;

sub login {
    my $self = shift;
    my $ua = WWW::Mechanize->new;
    $ua->submit_form(with_fields => { username => $self->username, password => $self->password });
    $self->{ua} = $ua;

sub post {
    my ($self, $content) = @_;
    try {
        $self->{ua}->submit_form(with_fields => { content =>  $content });

The usage is simple:

my $plurker = PlurkPoster->new(
    username => $config->{username},
    password => $config->{password},


This PlurkPoster can only post to plurk, but not reading it. And that is the whole purpose of it.

With Perl, you can always have easy solutions for simple purposes.