blib/lib/Pod/POM/View/Text.pm

filter: Statementstmt 96.0% 120 / 125 Branchbran 57.5% 23 / 40 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 25 / 25 Podpod 100% 19 / 19 totaltotal 88.0% 191 / 217 CC 22 SCAR 12.2
CC
22
Cov
86%
view
11.6
view_textblock
3.0
view_over
3.0
CRAP 3.4
« blib/lib/Pod/POM/Node/Sequence.pm ↑ Summary lib/Pod/POM/Test.pm »
1 #============================================================= -*-Perl-*-
2 #
3 # Pod::POM::View::Text
4 #
5 # DESCRIPTION
6 # Text view of a Pod Object Model.
7 #
8 # AUTHOR
9 # Andy Wardley <abw@kfs.org>
10 #
11 # COPYRIGHT
12 # Copyright (C) 2000 Andy Wardley. All Rights Reserved.
13 #
14 # This module is free software; you can redistribute it and/or
15 # modify it under the same terms as Perl itself.
16 #
17 # REVISION
18 # $Id: Text.pm 77 2009-08-20 20:44:14Z ford $
19 #
20 #========================================================================
21  
22 package Pod::POM::View::Text;
23 6 $Pod::POM::View::Text::VERSION = '2.01';
24 6 require 5.006;
25 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 6 ▶use Pod::POM::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶use parent qw( Pod::POM::View );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use vars qw( $DEBUG $ERROR $AUTOLOAD $INDENT );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 6 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Pod::POM::View::Text::DEBUG 6 0 6
34 6 $INDENT = 0;
35  
36  
37 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
38 2 my $class = shift;
39 2 ▶ my $args = ref $_[0] eq 'HASH' ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 2 2
40 2 bless {
41 INDENT => 0,
42 %$args,
43 }, $class;
44 }
45  
46  
47 265 ▶sub view {
Subroutine view: called CC=7 SCAR=24.5
Pod documented
48 265 my ($self, $type, $item) = @_;
49  
50 265 ▶ if ($type =~ s/^seq_//) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type =~ s/^seq_//) { } 251 14 265
elsif (UNIVERSAL::isa($item, 'HASH')) { } 12 2 14
elsif (not ref $item) { } 2 0 2
51 251 return $item;
52 }
53 elsif (UNIVERSAL::isa($item, 'HASH')) {
54 12 ▶ if (defined $item->{ content }) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $item->{'content'}) { } 12 0 12
elsif (defined $item->{'text'}) { } 0 0 0
55 12 return $item->{ content }->present($self);
56 }
57 elsif (defined $item->{ text }) {
58 0 my $text = $item->{ text };
59 0 ▶ return ref $text ? $text->present($self) : $text;
Branch: 1 branch
BranchTrueFalseTotal
ref $text ? : 0 0 0
60 }
61 else {
62 0 return '';
63 }
64 }
65 elsif (! ref $item) {
66 2 return $item;
67 }
68 else {
69 0 return '';
70 }
71 }
72  
73  
74 32 ▶sub view_head1 {
Subroutine view_head1: called CC=2 SCAR=6.9
Pod documented
75 32 my ($self, $head1) = @_;
76 32 ▶ my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 32 32
77 32 my $pad = ' ' x $$indent;
78 32 local $Text::Wrap::unexpand = 0;
79 32 my $title = wrap($pad, $pad,
80 $head1->title->present($self));
81
82 32 $$indent += 4;
83 32 my $output = "$title\n" . $head1->content->present($self);
84 32 $$indent -= 4;
85  
86 32 return $output;
87 }
88  
89  
90 8 ▶sub view_head2 {
Subroutine view_head2: called CC=2 SCAR=6.9
Pod documented
91 8 my ($self, $head2) = @_;
92 8 ▶ my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 8 8
93 8 my $pad = ' ' x $$indent;
94 8 local $Text::Wrap::unexpand = 0;
95 8 my $title = wrap($pad, $pad,
96 $head2->title->present($self));
97  
98 8 $$indent += 4;
99 8 my $output = "$title\n" . $head2->content->present($self);
100 8 $$indent -= 4;
101  
102 8 return $output;
103 }
104  
105  
106 5 ▶sub view_head3 {
Subroutine view_head3: called CC=2 SCAR=6.9
Pod documented
107 5 my ($self, $head3) = @_;
108 5 ▶ my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 5 5
109 5 my $pad = ' ' x $$indent;
110 5 local $Text::Wrap::unexpand = 0;
111 5 my $title = wrap($pad, $pad,
112 $head3->title->present($self));
113  
114 5 $$indent += 4;
115 5 my $output = "$title\n" . $head3->content->present($self);
116 5 $$indent -= 4;
117  
118 5 return $output;
119 }
120  
121  
122 7 ▶sub view_head4 {
Subroutine view_head4: called CC=2 SCAR=6.9
Pod documented
123 7 my ($self, $head4) = @_;
124 7 ▶ my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 7 7
125 7 my $pad = ' ' x $$indent;
126 7 local $Text::Wrap::unexpand = 0;
127 7 my $title = wrap($pad, $pad,
128 $head4->title->present($self));
129  
130 7 $$indent += 4;
131 7 my $output = "$title\n" . $head4->content->present($self);
132 7 $$indent -= 4;
133  
134 7 return $output;
135 }
136  
137  
138 #------------------------------------------------------------------------
139 # view_over($self, $over)
140 #
141 # Present an =over block - this is a blockquote if there are no =items
142 # within the block.
143 #------------------------------------------------------------------------
144  
145 8 ▶sub view_over {
Subroutine view_over: called CC=3 SCAR=11.0
Pod documented
146 8 my ($self, $over) = @_;
147  
148 8 ▶ if (@{$over->item}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$over->item;}) { } 5 3 8
149 5 return $over->content->present($self);
150 }
151 else {
152 3 ▶ my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 3 3
153 3 my $pad = ' ' x $$indent;
154 3 $$indent += 4;
155 3 my $content = $over->content->present($self);
156 3 $$indent -= 4;
157
158 3 return $content;
159 }
160 }
161  
162 12 ▶sub view_item {
Subroutine view_item: called CC=2 SCAR=6.9
Pod documented
163 12 my ($self, $item) = @_;
164 12 ▶ my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 12 12
165 12 my $pad = ' ' x $$indent;
166 12 local $Text::Wrap::unexpand = 0;
167 12 my $title = wrap($pad . '* ', $pad . ' ',
168 $item->title->present($self));
169  
170 12 $$indent += 2;
171 12 my $content = $item->content->present($self);
172 12 $$indent -= 2;
173
174 12 return "$title\n\n$content";
175 }
176  
177  
178 1 ▶sub view_for {
Subroutine view_for: called CC=2 SCAR=8.1
Pod documented
179 1 my ($self, $for) = @_;
180 1 ▶ return '' unless $for->format() =~ /\btext\b/;
Branch: 1 branch
BranchTrueFalseTotal
unless $for->format =~ /\btext\b/ 1 0 1
181 0 return $for->text()
182 . "\n\n";
183 }
184  
185
186 4 ▶sub view_begin {
Subroutine view_begin: called CC=2 SCAR=6.9
Pod documented
187 4 my ($self, $begin) = @_;
188 4 ▶ return '' unless $begin->format() =~ /\btext\b/;
Branch: 1 branch
BranchTrueFalseTotal
unless $begin->format =~ /\btext\b/ 3 1 4
189 1 return $begin->content->present($self);
190 }
191  
192
193 82 ▶sub view_textblock {
Subroutine view_textblock: called CC=3 SCAR=11.0
Pod documented
194 82 my ($self, $text) = @_;
195 82 ▶ my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 82 82
196 82 $text =~ s/\s+/ /mg;
197  
198 82 ▶ $$indent ||= 0;
Condition100%2/2
$$indent ||= 0
l!l
775
MC/DC100%1/1
$$indent ||= 0
$$indent
Truth table100%2/2
A
A= $$indent
Aresult
11
00
199 82 my $pad = ' ' x $$indent;
200 82 local $Text::Wrap::unexpand = 0;
201 82 return wrap($pad, $pad, $text) . "\n\n";
202 }
203  
204  
205 6 ▶sub view_verbatim {
Subroutine view_verbatim: called CC=2 SCAR=7.0
Pod documented
206 6 my ($self, $text) = @_;
207 6 ▶ my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 6 6
208 6 my $pad = ' ' x $$indent;
209 6 $text =~ s/^/$pad/mg;
210 6 return "$text\n\n";
211 }
212  
213  
214 10 ▶sub view_seq_bold {
Subroutine view_seq_bold: called CC=1 SCAR=0.0
Pod documented
215 10 my ($self, $text) = @_;
216 10 return "*$text*";
217 }
218  
219  
220 9 ▶sub view_seq_italic {
Subroutine view_seq_italic: called CC=1 SCAR=0.0
Pod documented
221 9 my ($self, $text) = @_;
222 9 return "_${text}_";
223 }
224  
225  
226 7 ▶sub view_seq_code {
Subroutine view_seq_code: called CC=1 SCAR=0.0
Pod documented
227 7 my ($self, $text) = @_;
228 7 return "'$text'";
229 }
230  
231  
232 3 ▶sub view_seq_file {
Subroutine view_seq_file: called CC=1 SCAR=0.0
Pod documented
233 3 my ($self, $text) = @_;
234 3 return "_${text}_";
235 }
236  
237 6 my $entities = {
238 gt => '>',
239 lt => '<',
240 amp => '&',
241 quot => '"',
242 };
243  
244  
245 10 ▶sub view_seq_entity {
Subroutine view_seq_entity: called CC=2 SCAR=8.1
Pod documented
246 10 my ($self, $entity) = @_;
247 10 ▶ return $entities->{ $entity } || $entity;
Condition33%1/3
$entities->{$entity} || $entity
l!l&&r!l&&!r
1000
MC/DC0%0/2
$entities->{$entity} || $entity
$entities->{$entity} $entity
Truth table33%1/3
A || B
A= $entities->{$entity}B= $entity
ABresult
1X1
011
000
248 }
249  
250 2 ▶sub view_seq_index {
Subroutine view_seq_index: called CC=1 SCAR=0.0
Pod documented
251 2 return '';
252 }
253  
254 3 ▶sub view_seq_link {
Subroutine view_seq_link: called CC=2 SCAR=6.9
Pod documented
255 3 my ($self, $link) = @_;
256 3 ▶ if ($link =~ s/^.*?\|//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link =~ s/^.*?\|//) { } 1 2 3
257 1 return $link;
258 }
259 else {
260 2 return "the $link manpage";
261 }
262 }
263
264
265  
266 6 1;
267  
268 =head1 NAME
269  
270 Pod::POM::View::Text - create text views of POM objects
271  
272 =head1 DESCRIPTION
273  
274 Text view of a Pod Object Model.
275  
276 =head1 METHODS
277  
278 =over 4
279  
280 =item C<view($self, $type, $item)>
281  
282 =item C<view_pod($self, $pod)>
283  
284 =item C<view_head1($self, $head1)>
285  
286 =item C<view_head2($self, $head2)>
287  
288 =item C<view_head3($self, $head3)>
289  
290 =item C<view_head4($self, $head4)>
291  
292 =item C<view_over($self, $over)>
293  
294 =item C<view_item($self, $item)>
295  
296 =item C<view_for($self, $for)>
297  
298 =item C<view_begin($self, $begin)>
299  
300 =item C<view_textblock($self, $textblock)>
301  
302 =item C<view_verbatim($self, $verbatim)>
303  
304 =item C<view_meta($self, $meta)>
305  
306 =item C<view_seq_bold($self, $text)>
307  
308 Returns the text of a C<BE<lt>E<gt>> sequence in 'bold' (i.e. surrounded by asterisks, like *this*).
309  
310 =item C<view_seq_italic($self, $text)>
311  
312 Returns the text of a C<IE<lt>E<gt>> sequence in 'italics' (i.e. surrounded by underscores, like _this_).
313  
314 =item C<view_seq_code($self, $text)>
315  
316 =item C<view_seq_file($self, $text)>
317  
318 =item C<view_seq_entity($self, $text)>
319  
320 =item C<view_seq_index($self, $text)>
321  
322 Returns an empty string. Index sequences are suppressed in text view.
323  
324 =item C<view_seq_link($self, $text)>
325  
326 =back
327  
328 =head1 AUTHOR
329  
330 Andy Wardley E<lt>abw@kfs.orgE<gt>
331  
332 =head1 COPYRIGHT AND LICENSE
333  
334 Copyright (C) 2000 Andy Wardley. All Rights Reserved.
335  
336 This module is free software; you can redistribute it and/or
337 modify it under the same terms as Perl itself.
338  
339 =cut
« blib/lib/Pod/POM/Node/Sequence.pm ↑ Summary lib/Pod/POM/Test.pm »