Skip to content

Instantly share code, notes, and snippets.

@karronoli
Created May 3, 2012 05:29
Show Gist options
  • Save karronoli/2583496 to your computer and use it in GitHub Desktop.
Save karronoli/2583496 to your computer and use it in GitHub Desktop.
Hello world Plack + Pod::Perldoc
# -*- Perl -*-
use strict;
use warnings;
use Plack::Request;
# for exit in Pod::Perldoc
BEGIN {*CORE::GLOBAL::exit = sub { warn 'exit!' };}
use Pod::Perldoc;
sub {
my $env = shift;
my $req = Plack::Request->new($env)->param('arg');
my $html = eval {
my @tmp = split (/ /, $req);
local @ARGV = ('-T', '-ohtml', (@tmp)? @tmp: '-h');
local (*STDOUT, *STDERR);
my ($stdout, $stderr) = ('', '');
open *STDOUT, '>', \$stdout;
open *STDERR, '>', \$stderr;
Pod::Perldoc->run();
$stdout || $stderr
};
my $type = (substr($html, 0, 6) eq '<html>')?
'text/html': 'text/plain';
return [ '200', [ 'Content-Type' => $type ],
[ $html || "bad keyword $req.\n$@"] ];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment