File Coverage

blib/lib/Apache2/Pod.pm
Criterion Covered Total %
statement 12 51 23.5
branch 0 28 0.0
condition 0 3 0.0
subroutine 4 7 57.1
pod 3 3 100.0
total 19 92 20.6


line stmt bran cond sub pod time code
1             package Apache2::Pod;
2              
3             =head1 NAME
4              
5             Apache2::Pod - base class for converting Pod files to prettier forms
6              
7             =head1 VERSION
8              
9             Version 0.27
10              
11             =cut
12              
13 2     2   63845 use vars qw( $VERSION );
  2         5  
  2         99  
14 2     2   11 use strict;
  2         5  
  2         96  
15              
16             $VERSION = '0.27';
17              
18             =head1 SYNOPSIS
19              
20             The Apache2::Pod::* are mod_perl handlers to easily convert Pod to HTML
21             or other forms. You can also emulate F.
22              
23             =head1 CONFIGURATION
24              
25             All configuration is done in one of the subclasses.
26              
27             =head1 TODO
28              
29             I could envision a day when the user can specify which output format
30             he'd like from the URL, such as
31              
32             http://your.server/perldoc/f/printf?rtf
33              
34             =head1 FUNCTIONS
35              
36             No functions are exported. I don't want to dink around with Exporter
37             in mod_perl if I don't need to.
38              
39             =head2 getpodfile( I<$r> )
40              
41             Returns the filename requested off of the C<$r> request object, or what
42             Perldoc would find, based on Pod::Find.
43              
44             =head2 resolve_modname( I<$r> )
45              
46             Returns a module name based on C<< $r->path_info >>.
47              
48             =head2 getpodfuncdoc( I<$file>, I<$function_name> )
49              
50             Given the full filepath of the C pod file and a function name,
51             returns the section of that pod document pertaining to the function. If
52             the function is not found, returns a pod document phrase stating so.
53              
54             =cut
55              
56 2     2   18 use Pod::Find;
  2         9  
  2         118  
57 2     2   13 use Carp ();
  2         3  
  2         1660  
58              
59             sub getpodfile {
60 0     0 1   my $r = shift;
61              
62 0           my $filename;
63              
64 0 0         if ($r->filename =~ m/\.pod$/i) {
65 0           $filename = $r->filename;
66             }
67             else {
68 0           my $module = resolve_modname( $r );
69 0 0         if ( $module =~ /^f::/ ) {
70 0           $module =~ s/^f:://;
71 0           $filename = "-f<$module>::" . Pod::Find::pod_where( {-inc=>1}, "perlfunc" );
72             }
73             else {
74 0           $filename = Pod::Find::pod_where( {-inc=>1}, $module );
75             }
76             }
77              
78 0           return $filename;
79             }
80              
81             sub resolve_modname {
82 0     0 1   my ( $r ) = @_;
83 0           my $module = $r->path_info;
84 0           $module =~ s|/||;
85 0           $module =~ s|/|::|g;
86 0           $module =~ s|\.html?$||; # Intermodule links end with .html
87 0           return $module;
88             }
89              
90             sub getpodfuncdoc {
91 0     0 1   my ( $file, $fun ) = @_;
92             # Functions like -r, -e, etc. are listed under `-X'.
93 0 0         my $search_re = ($fun =~ /^-[rwxoRWXOeszfdlpSbctugkTBMAC]$/)
94             ? '(?:I<)?-X' : quotemeta($fun) ;
95 0           my $document = '';
96             # TODO: Handle error on open gracefully.
97 0 0         open(PFUNC, "<$file") || Carp::croak "Can't open $file: $!";
98             # Skip introduction
99 0           local $_;
100 0           while ( ) {
101 0 0         last if /^=head2 Alphabetical Listing of Perl Functions/;
102             }
103            
104             # Look for our function
105 0           my $found = 0;
106 0           my $inlist = 0;
107 0           while ( ) { # "The Mothership Connection is here!"
108 0 0         if ( m/^=item\s+$search_re\b/ ) {
    0          
109 0           $found = 1;
110             }
111             elsif (/^=item/) {
112 0 0 0       last if $found > 1 and not $inlist;
113             }
114 0 0         next unless $found;
115 0 0         if (/^=over/) {
    0          
116 0           ++$inlist;
117             }
118             elsif (/^=back/) {
119 0           --$inlist;
120             }
121 0           $document .= "$_";
122 0 0         ++$found if /^\w/; # found descriptive text
123             }
124             # TODO: Handle error on open/close gracefully.
125 0 0         close PFUNC or Carp::croak "Can't open $file: $!";
126 0 0         if ( ! $document ) {
127 0           $document = sprintf "=item %s\n\nNo documentation for perl function '%s' found\n", $fun, $fun; # no $fun
128             }
129 0           return $document;
130             }
131             1;
132              
133             =head1 SEE ALSO
134              
135             L,
136             L,
137              
138             =head1 AUTHOR
139              
140             Theron Lewis C<< >>
141              
142             =head1 HISTORY
143              
144             Adapteded from Andy Lester's C<< >> Apache::Pod
145             package which was adapted from
146             Apache2::Perldoc by Rich Bowen C<< >>
147              
148             =head1 ACKNOWLEDGEMENTS
149              
150             Thanks also to
151             Pete Krawczyk,
152             Kjetil Skotheim,
153             Kate Yoak
154             and
155             Chris Eade
156             for contributions.
157              
158             =head1 LICENSE
159              
160             This package is licensed under the same terms as Perl itself.
161              
162             =cut