Pod.pm

filter: Statementstmt 26.4% 14 / 53 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 21.0% 21 / 100 CC 18 SCAR 52.1
CC
18
Cov
16%
getpodfuncdoc
272.0
getpodfile
12.0
resolve_modname
2.0
CRAP 183.1
↑ Summary Pod/PodSimpleHTML.pm »
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 3 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 $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<perldoc>.
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<perlfunc> 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 3 ▶use Pod::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 0 ▶sub getpodfile {
Subroutine getpodfile: not called CC=3 SCAR=24.8
Pod documented
60 0 my $r = shift;
61  
62 0 my $filename;
63  
64 0 ▶ if ($r->filename =~ m/\.pod$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->filename =~ /\.pod$/i) { } 0 0 0
65 0 $filename = $r->filename;
66 }
67 else {
68 0 my $module = resolve_modname( $r );
69 0 ▶ if ( $module =~ /^f::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module =~ /^f::/) { } 0 0 0
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 0 ▶sub resolve_modname {
Subroutine resolve_modname: not called CC=1 SCAR=6.9
Pod documented
82 0 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 0 ▶sub getpodfuncdoc {
Subroutine getpodfuncdoc: not called CC=16 SCAR=56.1
Pod documented
91 0 my ( $file, $fun ) = @_;
92 # Functions like -r, -e, etc. are listed under `-X'.
93 0 ▶ my $search_re = ($fun =~ /^-[rwxoRWXOeszfdlpSbctugkTBMAC]$/)
Branch: 1 branch
BranchTrueFalseTotal
$fun =~ /^-[rwxoRWXOeszfdlpSbctugkTBMAC]$/ ? : 0 0 0
94 ? '(?:I<)?-X' : quotemeta($fun) ;
95 0 my $document = '';
96 # TODO: Handle error on open gracefully.
97 0 ▶ open(PFUNC, "<$file") || Carp::croak "Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open PFUNC, "<$file" or Carp::croak("Can't open ${file}: $!") 0 0 0
98 # Skip introduction
99 0 local $_;
100 0 ▶ while ( <PFUNC> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline PFUNC)) 0 0 0
101 0 ▶ last if /^=head2 Alphabetical Listing of Perl Functions/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=head2 Alphabetical Listing of Perl Functions/ 0 0 0
102 }
103
104 # Look for our function
105 0 my $found = 0;
106 0 my $inlist = 0;
107 0 ▶ while ( <PFUNC> ) { # "The Mothership Connection is here!"
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline PFUNC)) 0 0 0
108 0 ▶ if ( m/^=item\s+$search_re\b/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^=item\s+$search_re\b/) { } 0 0 0
elsif (/^=item/) { } 0 0 0
109 0 $found = 1;
110 }
111 elsif (/^=item/) {
112 0 ▶ last if $found > 1 and not $inlist;
Branch: 1 branch
BranchTrueFalseTotal
if $found > 1 and not $inlist 0 0 0
Condition0%0/3
$found > 1 and not $inlist
!ll&&!rl&&r
000
MC/DC0%0/2
$found > 1 and not $inlist
$found > 1 not $inlist
Truth table0%0/3
A and not(B)
A= $found > 1B= not $inlist
ABresult
0X0
100
111
113 }
114 0 ▶ next unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 0 0
115 0 ▶ if (/^=over/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^=over/) { } 0 0 0
elsif (/^=back/) { } 0 0 0
116 0 ++$inlist;
117 }
118 elsif (/^=back/) {
119 0 --$inlist;
120 }
121 0 $document .= "$_";
122 0 ▶ ++$found if /^\w/; # found descriptive text
Branch: 1 branch
BranchTrueFalseTotal
if /^\w/ 0 0 0
123 }
124 # TODO: Handle error on open/close gracefully.
125 0 ▶ close PFUNC or Carp::croak "Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
close PFUNC or Carp::croak("Can't open ${file}: $!") 0 0 0
126 0 ▶ if ( ! $document ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($document) 0 0 0
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 3 1;
132  
133 =head1 SEE ALSO
134  
135 L<Apache2::Pod::HTML>,
136 L<Apache2::Pod::Text>,
137  
138 =head1 AUTHOR
139  
140 Theron Lewis C<< <theron at theronlewis dot com> >>
141  
142 =head1 HISTORY
143  
144 Adapteded from Andy Lester's C<< <andy at petdance dot com> >> Apache::Pod
145 package which was adapted from
146 Apache2::Perldoc by Rich Bowen C<< <rbowen@ApacheAdmin.com> >>
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
↑ Summary Pod/PodSimpleHTML.pm »