Pod/HTML.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Pod/PodSimpleHTML.pm ↑ Summary Pod/Text.pm »
1 package Apache2::Pod::HTML;
2  
3 =head1 NAME
4  
5 Apache2::Pod::HTML - base class for converting Pod files to prettier forms
6  
7 =cut
8  
9 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 $VERSION = '0.27';
13  
14 =head1 VERSION
15  
16 Version 0.27
17  
18 =cut
19  
20 3 ▶use Apache2::Pod;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 ▶use Apache2::Const -compile => qw( OK NOT_FOUND SERVER_ERROR );
Subroutine BEGIN: called CC=1 SCAR=2.6
22 use Apache2::Pod::PodSimpleHTML;
23  
24 =head1 SYNOPSIS
25  
26 A simple mod_perl handler to easily convert Pod to HTML or other forms.
27 You can also emulate F<perldoc>.
28  
29 =head1 CONFIGURATION
30  
31 =head2 Pod-to-HTML conversion
32  
33 Add the following lines to your F<httpd.conf>.
34  
35 <Files *.pod>
36 SetHandler perl-script
37 PerlHandler Apache2::Pod::HTML
38 </Files>
39  
40 All F<*.pod> files will magically be converted to HTML.
41  
42 =head2 F<perldoc> emulation
43  
44 The following configuration should go in your httpd.conf
45  
46 <Location /perldoc>
47 SetHandler perl-script
48 PerlHandler Apache2::Pod::HTML
49 PerlSetVar STYLESHEET auto
50 PerlSetVar LINKBASE http://www.example.com/docs/
51 </Location>
52  
53 You can then get documentation for a module C<Foo::Bar> at the URL
54 C<http://your.server.com/perldoc/Foo::Bar>
55  
56 Note that you can also get the standard Perl documentation with URLs
57 like C<http://your.server.com/perldoc/perlfunc> or just
58 C<http://your.server.com/perldoc> for the main Perl docs.
59  
60 Finally, you can search for a particular Perl keyword with
61 C<http://your.server.com/perldoc/f/keyword> The 'f' is used by analogy
62 with the C<-f> flag to C<perldoc>.
63  
64 =head1 CONFIGURATION VARIABLES
65  
66 =head2 STYLESHEET
67  
68 Specifies the stylesheet to use with the output HTML file.
69  
70 <Location /perldoc>
71 SetHandler perl-script
72 PerlHandler Apache2::Pod::HTML
73 PerlSetVar STYLESHEET auto
74 </Location>
75  
76 Specifying 'auto' for the stylesheet will cause the built-in CSS
77 stylesheet to be used. If you prefer, you can replace the word 'auto'
78 with the URL of your own custom stylesheet file.
79  
80 =head2 INDEX
81  
82 When INDEX is true, a table of contents is added at the top of the
83 HTML document.
84  
85 <Files *.pod>
86 SetHandler perl-script
87 PerlHandler Apache2::Pod::HTML
88 PerlSetVar INDEX 1
89 </Files>
90  
91 By default, this is off.
92  
93 =head2 GZIP
94  
95 When GZIP is true, the whole HTTP body is compressed. The user's browser must
96 accept gzip, and L<Compress::Zlib> must be available. Otherwise, GZIP is ignored.
97  
98 <Files *.pod>
99 SetHandler perl-script
100 PerlHandler Apache2::Pod::HTML
101 PerlSetVar GZIP 1
102 </Files>
103  
104 By default, this is off.
105  
106 =head2 LINKBASE
107  
108 Specifying an optional C<LINKBASE> variable changes the external
109 HTTP links to use a URL prefix of your specification instead of using
110 L<Pod::Simple::HTML>'s default. Using the magic word C<LOCAL> will make
111 links local instead of external.
112  
113 =cut
114  
115 sub handler {
116 my $r = shift;
117  
118 if ( $r->path_info eq '/auto.css' ) {
119 $r->content_type( 'text/css' );
120 $r->print( _css() );
121 return Apache2::Const::OK;
122 }
123  
124 my $body;
125 my $file = Apache2::Pod::getpodfile( $r );
126 my $fun = undef;
127 my $parser = Apache2::Pod::PodSimpleHTML->new;
128 $parser->no_errata_section(1);
129 $parser->complain_stderr(1);
130 $parser->output_string( \$body );
131 $parser->index( $r->dir_config('INDEX') );
132 if ( my $prefix = $r->dir_config('LINKBASE') ) {
133 if ( $prefix eq 'LOCAL' ) {
134 $prefix = $r->location . '/';
135 }
136 $parser->perldoc_url_prefix( $prefix );
137 }
138 if ( $file ) {
139 if ( $file =~ /^-f<([^>]*)>::(.*)$/ ) {
140 $fun = $1;
141 $file = $2;
142 }
143 if ( $fun ) {
144 my $document = Apache2::Pod::getpodfuncdoc( $file, $fun );
145 $parser->parse_string_document( $document );
146 }
147 else {
148 $parser->parse_file( $file );
149 }
150 # TODO: Send the timestamp of the file in the header here
151 } else {
152 my $modstr = Apache2::Pod::resolve_modname( $r ) || $r->filename || '';
153 my $document = sprintf "=item %1\$s\n\nNo documentation found for \"%1\$s\".\n", $modstr;
154 $parser->parse_string_document( $document );
155 }
156 my $stylesheet = $r->dir_config('STYLESHEET') || '';
157 $stylesheet = $r->location . '/auto.css' if $stylesheet =~ /^auto/i;
158 if ( $stylesheet ) {
159 # Stick in a link to our stylesheet
160 $stylesheet = qq(<LINK REL="stylesheet" HREF="$stylesheet" TYPE="text/css">);
161 $body =~ s{(?=</head)}{$stylesheet\n}i;
162 }
163 if ( $r->dir_config('GZIP') && ($r->header_in('Accept-Encoding') =~ /gzip/) ) {
164 local $@;
165 eval {
166 require Compress::Zlib;
167 $body = Compress::Zlib::memGzip( $body );
168 $r->header_out('Content-Encoding','gzip');
169 };
170 }
171 $r->content_type('text/html');
172 $r->print( $body );
173
174 return Apache2::Const::OK;
175 }
176  
177 sub _css {
178 return <<'EOF';
179 BODY {
180 background: white;
181 color: black;
182 font-family: times,serif;
183 margin: 0;
184 padding: 1ex;
185 }
186  
187 TABLE {
188 border-collapse: collapse;
189 border-spacing: 0;
190 border-width: 0;
191 color: inherit;
192 }
193  
194 A:link, A:visited {
195 background: transparent;
196 color: #006699;
197 }
198  
199 PRE {
200 background: #eeeeee;
201 border: 1px solid #888888;
202 color: black;
203 padding-top: 1em;
204 padding-bottom: 1em;
205 white-space: pre;
206 }
207  
208 H1 {
209 background: transparent;
210 color: #006699;
211 font-size: x-large;
212 font-family: tahoma,sans-serif;
213 }
214  
215 H2 {
216 background: transparent;
217 color: #006699;
218 font-size: large;
219 font-family: tahoma,sans-serif;
220 }
221  
222 .block {
223 background: transparent;
224 }
225  
226 TD .block {
227 color: #006699;
228 background: #dddddd;
229 padding: 0.2em;
230 font-size: large;
231 }
232  
233 HR {
234 display: none;
235 }
236 EOF
237 }
238  
239 =head1 SEE ALSO
240  
241 L<Apache2::Pod>,
242 L<Apache2::Pod::Text>
243  
244 =head1 AUTHOR
245  
246 Theron Lewis C<< <theron at theronlewis dot com> >>
247  
248 =head1 HISTORY
249  
250 Adapteded from Andy Lester's C<< <andy at petdance dot com> >> Apache::Pod
251 package which was adapted from
252 Apache2::Perldoc by Rich Bowen C<< <rbowen@ApacheAdmin.com> >>
253  
254 =head1 ACKNOWLEDGEMENTS
255  
256 Thanks also to
257 Pete Krawczyk,
258 Kjetil Skotheim,
259 Kate Yoak
260 and
261 Chris Eade
262 for contributions.
263  
264 =head1 LICENSE
265  
266 This package is licensed under the same terms as Perl itself.
267  
268 =cut
269  
270 1;
« Pod/PodSimpleHTML.pm ↑ Summary Pod/Text.pm »