http://qs1969.pair.com?node_id=1020979

Most of the time I want to read the doc for a module, I either bring up konqueror where I have a shortcut "mod:" that sends me to "https://metacpan.org/module/\{@}", or I have to run "perldoc" on the module in my console because either I need the specific version of the module I'm using, and that's not always the latest, or, more likely, I need the doc to a module in our own repository (i.e., our code).

Having given up on that, I whipped together the following. Now I can go to "http://localhost:8877/Module::Name" and get the perldoc in HTML form in my browser for this particular level. As a bonus, the links (L<...>) between modules works as well, which didn't quite happen for free.

TODO list includes being able to dynamically switch between multiple installed perls for the @INC that I'll be using, as well as multiple code streams (getting the doc for My::Foo in the current release, the previous release, etc.), probably by allowing some sort of version identifier in the URL (http://localhost:8877/v3/My::Foo), and getting the perldoc -f flag :)

In the hopes it gives someone else a starting point...

# App::PerldocServer use autopackage; use strict; use warnings FATAL => 'all'; use 5.16.2; use EV; use AnyEvent::HTTPD; use File::Basename qw(basename dirname); use Pod::Simple::HTML; use URI::Escape qw(uri_unescape); sub new { bless {} } sub run { my $self = shift; my $httpd = AnyEvent::HTTPD->new( port => 8877 ); $httpd->reg_cb( '' => sub { my ($httpd, $req) = @_; my $path = $req->url()->path(); my $m = uri_unescape(basename($path)); $httpd->stop_request(); my $f = $self->find_module($m); my $html; if ($f) { local $Pod::Simple::HTML::Perldoc_URL_Prefi +x = ('http://localhost:8877' . dirname($path) . '/') =~ s[/+$][/]r; my $p = Pod::Simple::HTML->new(); $p->output_string(\$html); $p->parse_file($f); } else { $html = "<html><body><h1>Unknown module: $m +</h1></body></html>"; } $req->respond( { content => [ 'text/html', $html ] } ); }, ); EV::loop; } sub find_module { my $self = shift; my $m = shift; my @paths; push @paths, File::Spec->catdir($ENV{CC_ROOT},'lib'), if $ENV{CC_ROOT}; push @paths, @INC; $m =~ s[::][/]g; for my $p (@paths) { for my $e (qw(pod pm)) { my $fullpath = "$p/$m.$e"; return $fullpath if -r $fullpath; } } return undef; } 1;
And the main script is my as-always-so-short:
#!/usr/bin/perl use rlib '../lib'; use App::PerldocServer; my $app = App::PerldocServer->new(); exit $app->run();

Update: removed reference to parent class - I don't think it's needed here.

Replies are listed 'Best First'.
Re: Personal perldoc webserver
by Your Mother (Archbishop) on Feb 28, 2013 at 06:24 UTC
    perl -Mojo -e 'plugin "PODRenderer"; a()->start' daemon

    Then try http://localhost:3000/perldoc/Mojo, for example. :P

      Very cool.
      Never knew it was that simple!
Re: Personal perldoc webserver
by Anonymous Monk on Feb 28, 2013 at 04:49 UTC
Re: Personal perldoc webserver
by perl-diddler (Chaplain) on Mar 14, 2013 at 05:45 UTC
    Where does one find:
    'App::ISAS::Base';