+= miniblerg - a tiny hack of a perl script to post to Blërg.
+
+Miniblerg is a half hour of hacking for a simple goal: log in to
+[Blërg](http://blerg.cc/) and post something from the command-line.
+I used Perl and the excellent LWP library. Like most half-hour hacks,
+it's not clean or pretty, but it gets the job done. :]
+
+== Installation
+
+miniblerg can be used from anywhere, but it requires Perl >5.10 and the
+JSON module.
+
+== Configuration
+
+Create a file called .miniblerg.rc in your home directory. It only
+needs one directive, username. It should look like this:
+
+username = foo
+
+Which, of course, is your Blërg username.
+
+== Usage
+
+ * miniblerg login
+ - interactively log in to your account
+ * miniblerg logout
+ - log out of your account
+ * miniblerg post
+ - post to Blërg either through an interactive editor or by reading
+ from stdin
+
+== Files
+
+miniblerg stores your login cookie in ~/.miniblerg.cookies. These
+cookies stick around between invocations (but are only user readable).
+#!/usr/bin/perl
+use LWP::UserAgent;
+use strict;
+use v5.10;
+
+my $baseurl = 'http://blerg.cc/';
+my $rc = "$ENV{HOME}/.miniblerg.rc";
+my $cookies = "$ENV{HOME}/.miniblerg.cookies";
+
+open OPTIONS, $rc;
+my %options = map { chomp; split /\s*=\s*/ } <OPTIONS>;
+close OPTIONS;
+
+my $agent = LWP::UserAgent->new(
+ cookie_jar => {
+ file => $cookies,
+ ignore_discard => 1
+ }
+);
+
+sub blerg_call {
+ my ($name, $params) = @_;
+
+ my $res = $agent->post($baseurl . $name, $params);
+
+ return $res->decoded_content =~ /success/;
+}
+
+my $op = shift;
+
+given ($op) {
+ when ('login') {
+ print "Password: ";
+ system('stty -echo');
+ my $password = <STDIN>;
+ system('stty echo');
+ chomp $password;
+ print "\n";
+
+ blerg_call('login', {
+ username => $options{username},
+ password => $password
+ }) or die "Could not log in\n";
+ $agent->cookie_jar->save;
+ chmod 0600, $cookies;
+ }
+ when('logout') {
+ blerg_call('logout', {
+ username => $options{username}
+ });
+ unlink $cookies;
+ }
+ when ('post') {
+ my $data;
+
+ if (-t STDIN) {
+ my $editor = $ENV{EDITOR} // $ENV{VISUAL};
+ system "touch /tmp/miniblerg.post.$$";
+ system "$editor /tmp/miniblerg.post.$$";
+ open DATA, "/tmp/miniblerg.post.$$";
+ $data = join('', <DATA>);
+ close DATA;
+ } else {
+ $data .= $_ while <STDIN>;
+ }
+ chomp $data;
+
+ if (!$data) {
+ print "Aborting empty post\n";
+ exit 1;
+ }
+
+ blerg_call('put', {
+ username => $options{username},
+ data => $data
+ }) or die "Could not post\n";
+
+ END {
+ unlink "/tmp/miniblerg.post.$$";
+ }
+ }
+}