After reading my compelling post on a clojure Slack-bot, an astute reader1 pointed out that using the fullblown apparatus of compojure, jetty, jvm, etc. for something this silly is really only justified when the entire purpose of the exercise is procrastination. Well, dear astute reader, that was the entire purpose, but you're right. Ok, here it is in perl,

    #!/usr/bin/env perl
    use Mojolicious::Lite;
    use File::Slurp;
    my $token = read_file("TOKEN");
    my @lines = split(/\0/,read_file("LINES"));
    post '/slacks' => sub {
      my $c   = shift;
      my $t   = $c->param('token');
      if ($t eq $token) {
          $c->render(json => {text => $lines[int(rand($#lines+1))]})
      } else {
          $c->render(text => 'denied',status => 403);

and you run it as ./slackbot.pl daemon -l 'http://localhost:3001'

You shouldn't need to actually know perl to read this, but if any haters out there want to call it illegible, I'm happy as long is makes them happy to do so.

Plump it up

I could fill up a bit more space by providing counsel on the virtues of perlbrew and noting that the main thing that changes in the commando recipe is

export PERLBREW_ROOT=${HOME}/perl5/perlbrew
export PERLBREW_HOME=/tmp/.perlbrew
source ${PERLBREW_ROOT}/etc/bashrc
Daemon -D ${DIR} -O ${DIR}/STDOUT -E ${DIR}/STDERR -- perlbrew exec --with perl-5.21.2 ./slackbot.pl daemon -l 'http://localhost:3001'

but I can't think of much else.

  1. Ok, it was me. 


comments powered by Disqus