Skip to content

Commit

Permalink
Perl rewrite. No more nasty shell!
Browse files Browse the repository at this point in the history
  • Loading branch information
tsibley committed Mar 27, 2012
1 parent cdd9112 commit d76565b
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions wikiserve
@@ -1,15 +1,38 @@
#!/bin/bash
root=$1
shift
plackup --port 4242 -MPlack::App::Directory -e '
enable_if { $_[0]->{REQUEST_URI} =~ /\.(md|mkdwn|markdown)$/ }
#!/usr/bin/env perl
use strict;
use warnings;

use Plack::Builder;
use Plack::Runner;
use Plack::App::Directory;

my $root = @ARGV ? shift : '.';

# Default differently than plackup's port 5000 so we don't conflict.
unshift @ARGV, '--port' => 4242;

my $app = builder {
my $is_markdown = qr/\.(md|mkdwn|markdown)$/i;

enable_if { $_[0]->{REQUEST_URI} =~ /$is_markdown/ }
SimpleContentFilter => filter => sub {
use Text::MultiMarkdown qw(markdown);
$_ = markdown($_, {use_wikilinks=>1})
eval {
require Text::MultiMarkdown;
$_ = Text::MultiMarkdown::markdown($_, { use_wikilinks => 1 });
};
return $_;
};
enable_if { $_[0]->{REQUEST_URI} =~ /\.(md|mkdwn|markdown)$/ }
Header => set => [qw(Content-Type text/html)];

enable_if { $_[0]->{REQUEST_URI} =~ /$is_markdown/ }
Header => set => [ 'Content-Type' => 'text/html' ];

enable Expires =>
content_type => qr/./,
expires => "now plus 1 second";
Plack::App::Directory->new({ root => q['"$root"'] })->to_app' "$@"

Plack::App::Directory->new({ root => $root })->to_app;
};

my $runner = Plack::Runner->new;
$runner->parse_options(@ARGV);
$runner->run($app);

0 comments on commit d76565b

Please sign in to comment.