Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
It's very easy to implement a dispatching module based on the MIME type of the request—that is, for different content handlers to be called for different MIME types. Example A-5 shows such a dispatcher.
package Book::MimeTypeDispatch;
use Apache::Constants qw(DECLINED);
my %mime_types = (
'text/html' => \&HTML::Template::handler,
'text/plain' => \&Book::Text::handler,
);
sub handler {
my $r = shift;
if (my $h = $mime_types{$r->content_type}) {
$r->push_handlers(PerlHandler => $h);
$r->handler('perl-script');
}
return DECLINED;
}
1;
_ _END_ _ |