File Coverage

blib/lib/Pod/Simple/XHTML/BlendedCode.pm
Criterion Covered Total %
statement 55 66 83.3
branch 3 10 30.0
condition 0 6 0.0
subroutine 13 13 100.0
pod 4 4 100.0
total 75 99 75.7


line stmt bran cond sub pod time code
1             package Pod::Simple::XHTML::BlendedCode;
2              
3 3     3   150149 use 5.008001;
  3         10  
  3         111  
4 3     3   16 use warnings;
  3         5  
  3         86  
5 3     3   16 use strict;
  3         6  
  3         100  
6 3     3   1121 use parent qw(Pod::Simple::XHTML);
  3         358  
  3         19  
7 3     3   170584 use List::Util qw(first);
  3         8  
  3         378  
8 3     3   2153 use Pod::Simple::XHTML::BlendedCode::Blender 1.000 qw();
  3         84  
  3         117  
9 3     3   36 use IO::String 1.08 qw();
  3         64  
  3         64  
10 3     3   18 use Carp qw(croak);
  3         6  
  3         2568  
11              
12             our $VERSION = '1.003';
13             $VERSION =~ s/_//ms;
14              
15             sub new {
16 2     2 1 35 my $self = shift;
17 2         33 my $new = $self->SUPER::new(@_);
18 2         421 $new->_accessorize(
19             'internal_modules_hash', 'internal_url_postfix',
20             'internal_url_prefix',   'internal_url_divide_slashes',
21             );
22 2         132 $new->internal_url_divide_slashes(1);
23 2         37 $new->internal_modules_hash( {} );
24 2         15 return $new;
25             }
26              
27             ## We cheat by processing through a preprocessor first.
28              
29             sub parse_file {
30 1     1 1 1463 my $self = shift;
31 1         3 my $in_file = shift;
32              
33 1         3 my $pod = q{};
34 1         8 my $pod_handle = IO::String->new($pod);
35              
36 1         72 my $preprocessor = Pod::Simple::XHTML::BlendedCode::Blender->new();
37 1         28 $preprocessor->parseopts( '-want_nonPODs' => 1 );
38 1         218 $preprocessor->parse_from_file( $in_file, $pod_handle );
39              
40 1         138 return $self->SUPER::parse_string_document($pod);
41             } ## end sub parse_file
42              
43             sub parse_string_document {
44 1     1 1 1617 my $self = shift;
45 1         3 my $in_string = shift;
46              
47 1         12 my $in_handle = IO::String->new($in_string);
48              
49 1         59 my $pod = q{};
50 1         6 my $pod_handle = IO::String->new($pod);
51              
52 1         57 my $preprocessor = Pod::Simple::XHTML::BlendedCode::Blender->new();
53 1         28 $preprocessor->parseopts( '-want_nonPODs' => 1 );
54 1         109 $preprocessor->parse_from_file( $in_handle, $pod_handle );
55              
56 1         80 return $self->SUPER::parse_string_document($pod);
57             } ## end sub parse_string_document
58              
59             sub resolve_pod_page_link {
60 11     11 1 375673 my ( $self, $to, $section ) = @_;
61              
62 11 50       38 croak
63             q{The parser's internal_modules_hash method is not returning a hashref}
64             if ( 'HASH' ne ref( $self->internal_modules_hash() ) );
65              
66 11         100 my $key;
67 11 50       27 if ( defined $to ) {
68 10     10   173 $key = first { $to =~ m{\A$_\z}ms }
69 11         39 sort { $a cmp $b } keys %{ $self->internal_modules_hash() };
  0         0  
  11         34  
70 11 50       266 return $self->SUPER::resolve_pod_page_link( $to, $section )
71             if not defined $key;
72             } else {
73 0           return $self->SUPER::resolve_pod_page_link( $to, $section );
74             }
75              
76 0           my $processed_to;
77              
78 0 0         if ( $self->internal_url_divide_slashes() ) {
79 0           $processed_to = $to;
80 0           $processed_to =~ s{::}{/}msg;
81             } else {
82 0           $processed_to = encode_entities($to);
83             }
84              
85 0 0         if ( defined $section ) {
86 0           $section = q{#} . $self->idify( $section, 1 );
87             } else {
88 0           $section = q{};
89             }
90              
91             return
92 0   0       ( $self->internal_url_prefix() || q{} )
      0        
      0        
93             . ( $self->internal_modules_hash->{$key} || q{} )
94             . $processed_to
95             . $section
96             . ( $self->internal_url_postfix() || q{} );
97             } ## end sub resolve_pod_page_link
98              
99              
100             1;                                     # Magic true value required at end of module
101             __END__
102            
103             =pod
104            
105             =begin readme text
106            
107             Pod::Simple::XHTML::BlendedCode version 1.003
108            
109             =end readme
110            
111             =for readme stop
112            
113             =head1 NAME
114            
115             Pod::Simple::XHTML::BlendedCode - Blends syntax-highlighted code and pod in one XHTML document.
116            
117             =head1 VERSION
118            
119             This document describes Pod::Simple::XHTML::BlendedCode version 1.003
120            
121             =begin readme
122            
123             =head1 INSTALLATION
124            
125             To install this module, run the following commands:
126            
127             perl Makefile.PL
128             make
129             make test
130             make install
131            
132             This method of installation will install a current version of Module::Build
133             if it is not already installed.
134            
135             Alternatively, to install with Module::Build, you can use the following commands:
136            
137             perl Build.PL
138             ./Build
139             ./Build test
140             ./Build install
141            
142             =end readme
143            
144             =for readme stop
145            
146             =head1 SYNOPSIS
147            
148             use Pod::Simple::XHTML::BlendedCode 1.003 qw();
149            
150             my $parser = Pod::Simple::XHTML::BlendedCode->new();
151            
152             # These routines are specific to Pod::Simple::XHTML::BlendedCode.
153             $parser->internal_modules_hash({
154             'Perl::Dist::WiX(.*)?' => 'Perl-Dist-WiX/', # Key can be a regex.
155             'Perl::Dist::VanillaWiX' => 'Perl-Dist-WiX/',
156             'File::List::Object' => 'File-List-Object/',
157             'Alien::WiX' => 'Alien-WiX/',
158             });
159             $parser->internal_url_postfix('.pm.html');
160             $parser->internal_url_prefix('http://csjewell.comyr.com/perl/');
161             $parser->internal_url_divide_slashes(1);
162            
163             # Since this is a subclass of Pod::Simple::XHTML,
164             # you can use all of its routines.
165             $parser->index(1);
166             $parser->html_css('code.css');
167             $parser->parse_file('Perl-Dist-WiX\\lib\\Perl\\Dist\\WiX.pm');
168            
169             =head1 DESCRIPTION
170            
171             This class is a formatter that takes Pod and Perl code and renders it as XHTML
172             validating HTML.
173            
174             This is a subclass of L<Pod::Simple::XHTML|Pod::Simple::XHTML> and inherits all
175             its methods.
176            
177             =head1 METHODS
178            
179             C<Pod::Simple::XHTML::BlendedCode> offers additional methods that modify
180             the format of the HTML output. Call these after creating the parser object,
181             but before the call to C<parse_file> or C<parse_string_document>:
182            
183             my $parser = Pod::Simple::XHTML::BlendedCode->new();
184             $parser->set_optional_param("value");
185             $parser->parse_file($file);
186            
187             =head2 internal_modules_hash
188            
189             This determines which modules are internal to your own web site.
190            
191             The module names in C<< LE<lt>E<gt> >> links are compared against the
192             regular expressions (wrapped in C<< \A >> and C<< \z >>) that are contained
193             in the keys. If no keys match, then normal link processing is used.
194            
195             If a key matches, then it is considered a "site-internal" link and the
196             value is appended to C<internal_url_prefix> for this link, and
197             C<internal_url_divide_slashes> and C<internal_url_postfix> are also used
198             when creating the link.
199            
200             If you are putting all modules in one path (so that there are no
201             per-distribution prefixes), set the values to the empty string.
202            
203             This defaults to an empty hashref, and a hashref must be passed in.
204            
205             =head2 internal_url_divide_slashes
206            
207             If this is set to a true value, then slashes are used to divide the portions
208             of a module name in the URL generated for an internal link.
209            
210             If not, then the module name is left as is.
211            
212             =head2 internal_url_prefix
213            
214             In turning an internal link to L<Foo::Bar|Foo::Bar> into
215             L<http://whatever/Foo%3a%3aBar> or L<http://whatever/Foo/Bar>, what to put
216             before the "Foo%3a%3aBar" or "Foo/Bar". This option is not set by default.
217            
218             =head2 perldoc_url_postfix
219            
220             What to put after "Foo%3a%3aBar" or "Foo/Bar" in the URL for an internal link.
221             This option is not set by default.
222            
223             =head1 DIAGNOSTICS
224            
225             "The parser's internal_modules_hash method is not returning a hashref" will
226             be croaked upon processing of the first pod link when the
227             interal_modules_hash method was passed anything but a hashref previously.
228            
229             Also, this module will report any diagnostic
230             L<Pod::Simple::XHTML|Pod::Simple::XHTML> will, as well as any diagnostic
231             that L<Pod::Parser|Pod::Parser> will during the blending process.
232            
233             =head1 CONFIGURATION AND ENVIRONMENT
234            
235             Pod::Simple::XHTML::BlendedCode requires no configuration files or
236             environment variables.
237            
238             =for readme continue
239            
240             =head1 DEPENDENCIES
241            
242             Perl 5.8.1 is the mimimum version of perl that this module will run on.
243            
244             Other modules that this module depends on are
245             L<Pod::Simple::XHTML|Pod::Simple::XHTML>, L<Pod::Parser|Pod::Parser>,
246             L<PPI::HTML|PPI::HTML> 1.08, and L<parent|parent> 0.223.
247            
248             =for readme stop
249            
250             =head1 INCOMPATIBILITIES
251            
252             None reported.
253            
254             =head1 BUGS AND LIMITATIONS (SUPPORT)
255            
256             No bugs have been reported.
257            
258             Bugs should be reported via:
259            
260             1) The CPAN bug tracker at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Pod-Simple-XHTML-BlendedCode>
261             if you have an account there.
262            
263             2) Email to E<lt>bug-Pod-Simple-XHTML-BlendedCode@rt.cpan.orgE<gt> if you do not.
264            
265             =head1 AUTHOR
266            
267             Curtis Jewell C<< <csjewell@cpan.org> >>
268            
269             =head1 SEE ALSO
270            
271             L<http://csjewell.comyr.com/perl/> (for examples of the output of this module.)
272            
273             =for readme continue
274            
275             =head1 LICENSE AND COPYRIGHT
276            
277             Copyright (c) 2010, Curtis Jewell C<< <csjewell@cpan.org> >>. All rights reserved.
278            
279             This module is free software; you can redistribute it and/or
280             modify it under the same terms as Perl itself, either version
281             5.8.1 or any later version. See L<perlartistic|perlartistic>
282             and L<perlgpl|perlgpl>.
283            
284             The full text of the license can be found in the
285             LICENSE file included with this module.
286            
287             =for readme stop
288            
289             =head1 DISCLAIMER OF WARRANTY
290            
291             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
292             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
293             OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
294             PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
295             EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
296             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
297             ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
298             YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
299             NECESSARY SERVICING, REPAIR, OR CORRECTION.
300            
301             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
302             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
303             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
304             LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
305             OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
306             THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
307             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
308             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
309             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
310             SUCH DAMAGES.
311