Apache2-PodBrowser

 view release on metacpan or  search on metacpan

lib/Apache2/PodBrowser.pm  view on Meta::CPAN


    return Apache2::Const::OK;
}

sub Fixup {                     # use a fixup instead of a transhandler here
    my $r = shift;              # so it can be used in a <Location>

    return Apache2::Const::DECLINED unless ($r->uri =~ m!/(\w+).css$!);

    my $name=$1;
    my $css=$INC{"Apache2/PodBrowser.pm"};
    $css=~s!\.pm$!/$name.css!;

    if ($r->dir_config('GZIP')) {
        $r->headers_out->add(Vary=>'accept-encoding');
        if ($r->headers_in->{'Accept-Encoding'}=~/\bgzip\b/ and
            $r->subprocess_env->{'no-gzip'} ne '1' and # behave as mod_deflate
            $r->subprocess_env->{'gzip-only-text/html'} ne '1' and
            -f $css.'.gz') {
            $r->headers_out->{'Content-Encoding'} = 'gzip';
            $r->content_encoding('gzip');
            $r->filename($css.'.gz');
            $r->path_info('');
            $r->handler('default');
            $r->content_type('text/css');
            $r->finfo(APR::Finfo::stat($r->filename, APR::Const::FINFO_NORM,
                                       $r->pool));
            return Apache2::Const::OK;
        }
    }

    if (-f $css) {
        $r->filename($css);
        $r->path_info('');
        $r->handler('default');
        $r->content_type('text/css');
        $r->finfo(APR::Finfo::stat($r->filename, APR::Const::FINFO_NORM,
                                   $r->pool));

        return Apache2::Const::OK;
    }

    return Apache2::Const::DECLINED;
}

{
    package Apache2::PodBrowser::Formatter;

    use strict;
    use base qw/Pod::Simple::HTML/;

    our $VERSION=Apache2::PodBrowser->VERSION;

    @INC{'Apache2/PodBrowser/Formatter.pm'}=1;

    sub new {
        local $Pod::Simple::HTML::Doctype_decl=
            (qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"}.
             qq{ "http://www.w3.org/TR/html4/loose.dtd">\n});

        return shift->SUPER::new(@_);
    }

    sub resolve_pod_page_link {
        my ($I, $to, $sec)=@_;

        $to=~s/::$//s;
        $to=~s/([^A-Za-z0-9\-_.!~*'():])/sprintf("%%%02X", ord $1)/ge;

        return './'.$to.$I->perldoc_url_postfix
            unless length($I->perldoc_url_prefix);

        return $I->perldoc_url_prefix.$to.$I->perldoc_url_postfix;
    }
}

{
    package Apache2::PodBrowser::DirectMode;

    use strict;
    use base qw/Apache2::PodBrowser::Formatter/;

    our $VERSION=Apache2::PodBrowser->VERSION;

    @INC{'Apache2/PodBrowser/DirectMode.pm'}=1;

    sub r {
        my ($I)=@_;

        if( @_>=2 ) {
            $I->{__PACKAGE__.'::r'}=$_[1];
        }
        $I->{__PACKAGE__.'::r'};
    }

    sub resolve_pod_page_link {
        my ($I, $to, $sec)=@_;

        my $r=$I->r;
        my $base=$r->filename;
        substr( $base, -length($r->uri) )='';

        $to=~s!::$!!;
        $to=~s#
                  ::
              |
                  ([^A-Za-z0-9\-_.!~*'()])
              #
                  $1 ? sprintf("%%%02X", ord $1) : '/'
              #gex;
        if( -f $base.'/'.$to.'.pod' ) {
            return '/'.$to.'.pod';
        } elsif( -f $base.'/'.$to.'.pm' ) {
            return '/'.$to.'.pm';
        } elsif( -f $base.'/'.$to.'.pl' ) {
            return '/'.$to.'.pl';
        } else {
            return $I->SUPER::resolve_pod_page_link(@_[1,$#_]);
        }
    }
}

1;

__END__

=encoding utf-8

=head1 NAME

Apache2::PodBrowser - show your POD in a browser

=head1 DESCRIPTION

Yet another mod_perl2 handler to view POD in a HTML browser. See L</HISTORY>
for more information.

=head2 Direct Mode

C<Apache2::PodBrowser> can run in I<direct> and I<perldoc> modes. In
direct mode apache takes care of the URI to filename translation. So,
C<< $r->filename >> points to a regular file when the request hits
C<Apache2::PodBrowser>'s handler. Use this mode if your POD files
are installed in one directory tree which is accessible through the WEB
server. You'll perhaps need an additional directory index handler.

=head2 Perldoc Mode

In I<perldoc> mode you specify a C<Location> where the handler resides.
If you append a module name to the location URL as in

  http://localhost/location/Apache2::PodBrowser

you'll get its documentation.

Further, in perldoc mode you can ask for documentation for a given
perl function similar to C<perldoc -f open> at the command line. Simply
call the location and give the wanted function as CGI keyword:

  http://localhost/location/?open

The same works also for special variables. Try

  http://localhost/location/?$_

and you'll see the documentation for C<$_>.

Usually you want to use perldoc mode. It allows you to access PODs
at their natural locations. On the downside, it is of
course a bit slower.

=head2 Indexes

Also in perldoc mode, there are 2 indexes available, one of all installed
modules and scripts that come with POD and one of built-in functions and
variables.

The the handler location itself shows the module index:



( run in 0.879 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )