blib/lib/Template/Plugin/PodSimple.pm

filter: Statementstmt 33.9% 20 / 59 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 1 totaltotal 18.2% 25 / 137 CC 25 SCAR 50.6
CC
25
Cov
18%
_do_pod_link
240.0
parse
132.0
_do_man_link
2.0
CRAP 158.1
↑ Summary
1 =head1 NAME
2  
3 Template::Plugin::PodSimple - simple Pod::Simple plugin for TT
4  
5 =head1 SYNOPSIS
6  
7 [% USE PodSimple %]
8 [% PodSimple.parse('format',string_containing_pod_or_filename) %]
9  
10 =head1 DESCRIPTION
11  
12 [% SET somepod = "
13
14 =head1 NAME
15
16 the name
17
18 =head1 DESCRIPTION
19
20 somepod
21
22 =cut
23
24 ";
25 USE PodSimple;
26 %]
27
28 [% PodSimple.parse('Text', somepod, 76) %]
29 [% PodSimple.parse('xml', somepod) %]
30 [% mySimpleTree = PodSimple.parse('tree', somepod ) %]
31 [% PodSimple.parse('html', somepod, 'pod_link_prefix','man_link_prefix') %]
32  
33 Text translates to L<Pod::Simple::Text|Pod::Simple::Text>.
34 When dealing with text, the 3rd argument is the value for C< $Text::Wrap::columns >.
35  
36 xMl translates to L<Pod::Simple::XMLOutStream|Pod::Simple::XMLOutStream>.
37  
38 tree translates to L<Pod::Simple::SimpleTree|Pod::Simple::SimpleTree>,
39 and the tree B<root> is what's returned.
40 This is what you want to use if you want to create your own formatter.
41  
42 htMl translates to L<Pod::Simple::HTML|Pod::Simple::HTML>.
43 When dealing with htMl, the 3rd and 4th arguments are
44 is used to prefix all non-local LE<lt>E<gt>inks,
45 by temporarily overriding
46 C<< *Pod::Simple::HTML::do_pod_link >>.
47 and
48 C<< *Pod::Simple::HTML::do_man_link >>.
49 pod_link_prefix is "?" by default.
50 man_link_prefix is C<< http://man.linuxquestions.org/index.php?type=2&query= >>
51 by default.
52 The prefix always gets html escaped by Pod::Simple.
53 An example man link is C<< L<crontab(5)> >>.
54  
55  
56  
57 =head1 SEE ALSO
58  
59 L<Template::Plugin|Template::Plugin>,
60 L<Pod::Simple|Pod::Simple>.
61  
62 =head1 BUGS
63
64 To report bugs, go to
65 E<lt>http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Plugin-PodSimpleE<gt>
66 or send mail to E<lt>bug-Template-Plugin-PodSimple#rt.cpan.orgE<gt>.
67  
68 =head1 LICENSE
69
70 Copyright (c) 2003 by D.H. (PodMaster). All rights reserved.
71
72 This module is free software; you can redistribute it and/or modify it
73 under the same terms as Perl itself. The LICENSE file contains the full
74 text of the license.
75  
76 =cut
77  
78 package Template::Plugin::PodSimple;
79 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 1 ▶use Pod::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 1 ▶use base qw[ Template::Plugin ];
Subroutine BEGIN: called CC=1 SCAR=0.0
83 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
84 1 $VERSION = sprintf "%d.%03d", q$Revision: 1.10 $ =~ /(\d+).(\d+)/g;
85
86  
87 1 my %map = (
88 tree => 'SimpleTree',
89 html => 'HTML',
90 text => 'Text',
91 xml => 'XMLOutStream',
92 );
93  
94 1 my $pod_link_prefix = '';
95 1 my $man_link_prefix = '';
96 0 ▶sub _do_man_link {
Subroutine _do_man_link: not called CC=1 SCAR=6.9
97 0 my($self, $link) = @_;
98 0 my $to = $link->attr('to');
99 0 $to =~ s/\(\d+\)$//;
100 0 return $man_link_prefix.$self->unicode_escape_url($to);
101 }
102 0 ▶sub _do_pod_link {
Subroutine _do_pod_link: not called CC=15 SCAR=54.8
103 0 my($self, $link) = @_;
104 0 my $to = $link->attr('to');
105 0 my $section = $link->attr('section');
106 return undef unless( # should never happen
107 0 ▶ (defined $to and length $to) or
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to and length $to or defined $section and length $section 0 0 0
Condition0%0/9
defined $to and length $to or defined $section and length $section
l!l&&r!l&&!r
000
defined $to and length $to
!ll&&!rl&&r
000
defined $section and length $section
!ll&&!rl&&r
000
MC/DC0%0/4
defined $to and length $to or defined $section and length $section
defined $to length $to defined $section length $section
Truth table0%0/7
A and B or C and D
A= defined $toB= length $toC= defined $sectionD= length $section
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
108 (defined $section and length $section)
109 );
110  
111 # if(defined $to and length $to) {
112 # $to = $self->resolve_pod_page_link($to, $section);
113 # return undef unless defined $to and length $to;
114 # resolve_pod_page_link returning undef is how it
115 # can signal that it gives up on making a link
116 # (I pass it the section value, but I don't see a
117 # particular reason it'd use it.)
118 # }
119
120 0 ▶ if(defined $section and length($section .= '')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $section and length(($section .= ''))) 0 0 0
Condition0%0/3
defined $section and length(($section .= ''))
!ll&&!rl&&r
000
MC/DC0%0/2
defined $section and length(($section .= ''))
defined $section length(($section .= ''))
Truth table0%0/3
A and B
A= defined $sectionB= length(($section .= ''))
ABresult
0X0
100
111
121 0 $section =~ tr/ /_/;
122 0 $section =~ tr/\x00-\x1F\x80-\x9F//d if 'A' eq chr(65);
123 0 $section = $self->unicode_escape_url($section);
124 # Turn char 1234 into "(1234)"
125 0 ▶ $section = '_' unless length $section;
Branch: 1 branch
BranchTrueFalseTotal
unless length $section 0 0 0
126 }
127
128 0 foreach my $it ($to, $section) {
129 0 ▶ $it =~ s/([^\._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf('%%%02X',ord($1))/eg
Branch: 1 branch
BranchTrueFalseTotal
if defined $it 0 0 0
130 if defined $it;
131 # Yes, stipulate the list without a range, so that this can work right on
132 # all charsets that this module happens to run under.
133 # Altho, hmm, what about that ord? Presumably that won't work right
134 # under non-ASCII charsets. Something should be done about that.
135 }
136
137 0 ▶ my $out = $to if defined $to and length $to;
Branch: 1 branch
BranchTrueFalseTotal
if defined $to and length $to 0 0 0
Condition0%0/3
defined $to and length $to
!ll&&!rl&&r
000
MC/DC0%0/2
defined $to and length $to
defined $to length $to
Truth table0%0/3
A and B
A= defined $toB= length $to
ABresult
0X0
100
111
138 0 ▶ $out .= "#" . $section if defined $section and length $section;
Branch: 1 branch
BranchTrueFalseTotal
if defined $section and length $section 0 0 0
Condition0%0/3
defined $section and length $section
!ll&&!rl&&r
000
MC/DC0%0/2
defined $section and length $section
defined $section length $section
Truth table0%0/3
A and B
A= defined $sectionB= length $section
ABresult
0X0
100
111
139 0 ▶ return undef unless length $out;
Branch: 1 branch
BranchTrueFalseTotal
unless length $out 0 0 0
140 0 return $pod_link_prefix.$out;
141 }
142  
143 0 ▶sub parse {
Subroutine parse: not called CC=11 SCAR=48.8
Pod undocumented
144 0 my $self = shift;
145 0 my $class = lc shift;
146 0 ▶ $pod_link_prefix = $_[1] || '?';
Condition0%0/2
$_[1] || '?'
l!l
00
MC/DC0%0/1
$_[1] || '?'
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
147 0 ▶ $man_link_prefix = $_[2] || 'http://man.linuxquestions.org/index.php?type=2&query=';
Condition0%0/2
$_[2] || 'http://man.linuxquestions.org/index.php?type=2&query='
l!l
00
MC/DC0%0/1
$_[2] || 'http://man.linuxquestions.org/index.php?type=2&query='
$_[2]
Truth table0%0/2
A
A= $_[2]
Aresult
11
00
148  
149 0 my $somestring="";
150 0 my $new;
151  
152 0 ▶ unless( exists $INC{"lib/Pod/Simple/$map{$class}.pm"} ){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $INC{"lib/Pod/Simple/$map{$class}.pm"}) 0 0 0
153 0 eval "require Pod::Simple::$map{$class};";
154 0 ▶ croak("Template::Plugin::PodSimple could not load Pod::Simple::$map{$class} : $@ $!")
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
155 if $@;
156 }
157
158 0 $new = "Pod::Simple::$map{$class}"->new();
159  
160 0 ▶ croak("`$class' not recognized by Template::Plugin::PodSimple $@ $!")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 0 0
161 unless defined $new;
162  
163 0 $new->output_string( \$somestring );
164  
165 0 ▶ local *Pod::Simple::HTML::do_pod_link = \&_do_pod_link
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "html" 0 0 0
Condition0%0/5
$class eq 'html' && ((local *Pod::Simple::HTML::do_pod_link = \&Template::Plugin::PodSimple::_do_pod_link) && (local *Pod::Simple::HTML::do_man_link = \&Template::Plugin::PodSimple::_do_man_link))
!ll&&!rl&&r
000
local *Pod::Simple::HTML::do_pod_link = \&Template::Plugin::PodSimple::_do_pod_link and local *Pod::Simple::HTML::do_man_link = \&Template::Plugin::PodSimple::_do_man_link
!ll
00
MC/DC0%0/2
$class eq 'html' && ((local *Pod::Simple::HTML::do_pod_link = \&Template::Plugin::PodSimple::_do_pod_link) && (local *Pod::Simple::HTML::do_man_link = \&Template::Plugin::PodSimple::_do_man_link))
$class eq 'html' local *Pod::Simple::HTML::do_pod_link = \&Template::Plugin::PodSimple::_do_pod_link
Truth table0%0/3
A && B
A= $class eq 'html'B= local *Pod::Simple::HTML::do_pod_link = \&Template::Plugin::PodSimple::_do_pod_link
ABresult
0X0
100
111
166 and
167 local *Pod::Simple::HTML::do_man_link = \&_do_man_link
168 if $class eq 'html';
169  
170 0 ▶ local $Text::Wrap::columns = $_[1] if $class eq 'text';
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "text" 0 0 0
171  
172 0 ▶ if( $_[0] =~ /\n/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\n/) { } 0 0 0
173 0 $new->parse_string_document( $_[0] );
174 } else {
175 0 $new->parse_file($_[0]);
176 }
177  
178 0 ▶ $somestring = $new->root if $class eq 'tree';
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "tree" 0 0 0
179  
180 0 return $somestring;
181 }
182
183  
184 1 1;
185 __END__
↑ Summary