# 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_Prefix = ('http://localhost:8877' . dirname($path) . '/') =~ s[/+$][/]r; my $p = Pod::Simple::HTML->new(); $p->output_string(\$html); $p->parse_file($f); } else { $html = "

Unknown module: $m

"; } $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;