Subject: | Patch: configure the page title. |
Date: | Sun, 22 Feb 2009 19:48:02 -0600 |
To: | bug-pod-pom-web [...] rt.cpan.org |
From: | Elliot Shank <perl [...] galumph.com> |
I've got multiple perl installs to deal with. I want to be able to differentiate different Pod::POM::Web instances via the page title. The attached patch adds an option to specify the page title. I don't consider the patch complete-- the documentation hasn't been updated-- but I wanted to get your opinion on the approach before continuing. Assuming this is OK, I'll get the documentation updated. After this, I want to add a further option to add to the script directories.
=== modified file 'lib/Pod/POM/Web.pm'
--- lib/Pod/POM/Web.pm 2009-02-23 00:18:31 +0000
+++ lib/Pod/POM/Web.pm 2009-02-23 01:26:30 +0000
@@ -78,7 +78,7 @@
#----------------------------------------------------------------------
sub server { # builtin HTTP server; unused if running under Apache
- my ($class, $port) = @_;
+ my ($class, $port, $options) = @_;
$port ||= 8080;
my $daemon = HTTP::Daemon->new(LocalPort => $port,
@@ -92,7 +92,7 @@
print STDERR "URL : " , $req->url, "\n";
$client_connection->force_last_request; # patch by CDOLAN
my $response = HTTP::Response->new;
- $class->handler($req, $response);
+ $class->handler($req, $response, $options);
$client_connection->send_response($response);
}
$client_connection->close;
@@ -103,8 +103,8 @@
sub handler : method {
- my ($class, $request, $response) = @_;
- my $self = $class->new($request, $response);
+ my ($class, $request, $response, $options) = @_;
+ my $self = $class->new($request, $response, $options);
eval { $self->dispatch_request(); 1}
or $self->send_content({content => $@, code => 500});
return 0; # Apache2::Const::OK;
@@ -112,8 +112,9 @@
sub new {
- my ($class, $request, $response) = @_;
+ my ($class, $request, $response, $options) = @_;
my $self;
+ $options ||= {};
# cheat: will create an instance of the Indexer subclass if possible
if (!$no_indexer && $class eq __PACKAGE__) {
@@ -128,7 +129,8 @@
$q->query($request->args);
my $params = $q->query_form_hash;
(my $uri = $request->uri) =~ s/$path$//;
- $self = {response => $request, # Apache API: same object for both
+ $self = {%{$options}, # Put first so that it gets overwritten below
+ response => $request, # Apache API: same object for both
root_url => $uri,
path => $path,
params => $params,
@@ -137,7 +139,8 @@
};
/^HTTP/ and do { # coming from HTTP::Daemon // server() method above
- $self = {response => $response,
+ $self = {%{$options}, # Put first so that it gets overwritten below
+ response => $response,
root_url => "",
path => $request->url->path,
params => $request->url->query_form_hash,
@@ -215,9 +218,12 @@
sub index_frameset {
my ($self) = @_;
+
+ my $title = $self->{page_title} || 'Perl documentation';
+ $title =~ s/([&<>"])/$escape_entity{$1}/g;
return $self->send_html(<<__EOHTML__);
<html>
- <head><title>Perl documentation</title></head>
+ <head><title>$title</title></head>
<frameset cols="25%, 75%">
<frame name="tocFrame" src="toc" ></frame>
<frame name="contentFrame" src="perl" ></frame>