File Coverage

blib/lib/Pod/POM/View/Text.pm
Criterion Covered Total %
statement 114 119 95.8
branch 22 38 57.8
condition 3 5 60.0
subroutine 25 25 100.0
pod 19 19 100.0
total 183 206 88.8


line stmt bran cond sub pod time code
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
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             $Pod::POM::View::Text::VERSION = '2.01';
24             require 5.006;
25 6     6   3367 use strict;
  6         11  
  6         149  
26 6     6   29 use warnings;
  6         11  
  6         158  
27              
28 6     6   28 use Pod::POM::View;
  6         11  
  6         139  
29 6     6   28 use parent qw( Pod::POM::View );
  6         9  
  6         35  
30 6     6   331 use vars qw( $DEBUG $ERROR $AUTOLOAD $INDENT );
  6         12  
  6         400  
31 6     6   6021 use Text::Wrap;
  6         20257  
  6         9661  
32              
33             $DEBUG = 0 unless defined $DEBUG;
34             $INDENT = 0;
35              
36              
37             sub new {
38 2     2 1 17 my $class = shift;
39 2 50       9 my $args = ref $_[0] eq 'HASH' ? shift : { @_ };
40 2         12 bless {
41             INDENT => 0,
42             %$args,
43             }, $class;
44             }
45              
46              
47             sub view {
48 265     265 1 467 my ($self, $type, $item) = @_;
49              
50 265 100       841 if ($type =~ s/^seq_//) {
    100          
    50          
51 251         1093 return $item;
52             }
53             elsif (UNIVERSAL::isa($item, 'HASH')) {
54 12 50       28 if (defined $item->{ content }) {
    0          
55 12         47 return $item->{ content }->present($self);
56             }
57             elsif (defined $item->{ text }) {
58 0         0 my $text = $item->{ text };
59 0 0       0 return ref $text ? $text->present($self) : $text;
60             }
61             else {
62 0         0 return '';
63             }
64             }
65             elsif (! ref $item) {
66 2         9 return $item;
67             }
68             else {
69 0         0 return '';
70             }
71             }
72              
73              
74             sub view_head1 {
75 32     32 1 52 my ($self, $head1) = @_;
76 32 50       64 my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
77 32         56 my $pad = ' ' x $$indent;
78 32         43 local $Text::Wrap::unexpand = 0;
79 32         156 my $title = wrap($pad, $pad,
80             $head1->title->present($self));
81            
82 32         3282 $$indent += 4;
83 32         172 my $output = "$title\n" . $head1->content->present($self);
84 32         2660 $$indent -= 4;
85              
86 32         90 return $output;
87             }
88              
89              
90             sub view_head2 {
91 8     8 1 12 my ($self, $head2) = @_;
92 8 50       20 my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
93 8         19 my $pad = ' ' x $$indent;
94 8         8 local $Text::Wrap::unexpand = 0;
95 8         49 my $title = wrap($pad, $pad,
96             $head2->title->present($self));
97              
98 8         769 $$indent += 4;
99 8         46 my $output = "$title\n" . $head2->content->present($self);
100 8         218 $$indent -= 4;
101              
102 8         20 return $output;
103             }
104              
105              
106             sub view_head3 {
107 5     5 1 10 my ($self, $head3) = @_;
108 5 50       11 my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
109 5         10 my $pad = ' ' x $$indent;
110 5         7 local $Text::Wrap::unexpand = 0;
111 5         30 my $title = wrap($pad, $pad,
112             $head3->title->present($self));
113              
114 5         504 $$indent += 4;
115 5         30 my $output = "$title\n" . $head3->content->present($self);
116 5         9 $$indent -= 4;
117              
118 5         15 return $output;
119             }
120              
121              
122             sub view_head4 {
123 7     7 1 11 my ($self, $head4) = @_;
124 7 50       13 my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
125 7         15 my $pad = ' ' x $$indent;
126 7         9 local $Text::Wrap::unexpand = 0;
127 7         37 my $title = wrap($pad, $pad,
128             $head4->title->present($self));
129              
130 7         685 $$indent += 4;
131 7         37 my $output = "$title\n" . $head4->content->present($self);
132 7         14 $$indent -= 4;
133              
134 7         17 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             sub view_over {
146 8     8 1 17 my ($self, $over) = @_;
147              
148 8 100       10 if (@{$over->item}) {
  8         47  
149 5         26 return $over->content->present($self);
150             }
151             else {
152 3 50       8 my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
153 3         6 my $pad = ' ' x $$indent;
154 3         5 $$indent += 4;
155 3         17 my $content = $over->content->present($self);
156 3         241 $$indent -= 4;
157            
158 3         9 return $content;
159             }
160             }
161              
162             sub view_item {
163 12     12 1 19 my ($self, $item) = @_;
164 12 50       27 my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
165 12         25 my $pad = ' ' x $$indent;
166 12         15 local $Text::Wrap::unexpand = 0;
167 12         66 my $title = wrap($pad . '* ', $pad . ' ',
168             $item->title->present($self));
169              
170 12         1205 $$indent += 2;
171 12         62 my $content = $item->content->present($self);
172 12         990 $$indent -= 2;
173            
174 12         42 return "$title\n\n$content";
175             }
176              
177              
178             sub view_for {
179 1     1 1 3 my ($self, $for) = @_;
180 1 50       10 return '' unless $for->format() =~ /\btext\b/;
181 0         0 return $for->text()
182             . "\n\n";
183             }
184              
185            
186             sub view_begin {
187 4     4 1 10 my ($self, $begin) = @_;
188 4 100       26 return '' unless $begin->format() =~ /\btext\b/;
189 1         8 return $begin->content->present($self);
190             }
191              
192            
193             sub view_textblock {
194 82     82 1 122 my ($self, $text) = @_;
195 82 50       158 my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
196 82         424 $text =~ s/\s+/ /mg;
197              
198 82   100     201 $$indent ||= 0;
199 82         144 my $pad = ' ' x $$indent;
200 82         103 local $Text::Wrap::unexpand = 0;
201 82         239 return wrap($pad, $pad, $text) . "\n\n";
202             }
203              
204              
205             sub view_verbatim {
206 6     6 1 11 my ($self, $text) = @_;
207 6 50       15 my $indent = ref $self ? \$self->{ INDENT } : \$INDENT;
208 6         13 my $pad = ' ' x $$indent;
209 6         33 $text =~ s/^/$pad/mg;
210 6         30 return "$text\n\n";
211             }
212              
213              
214             sub view_seq_bold {
215 10     10 1 16 my ($self, $text) = @_;
216 10         39 return "*$text*";
217             }
218              
219              
220             sub view_seq_italic {
221 9     9 1 17 my ($self, $text) = @_;
222 9         37 return "_${text}_";
223             }
224              
225              
226             sub view_seq_code {
227 7     7 1 14 my ($self, $text) = @_;
228 7         26 return "'$text'";
229             }
230              
231              
232             sub view_seq_file {
233 3     3 1 8 my ($self, $text) = @_;
234 3         14 return "_${text}_";
235             }
236              
237             my $entities = {
238             gt => '>',
239             lt => '<',
240             amp => '&',
241             quot => '"',
242             };
243              
244              
245             sub view_seq_entity {
246 10     10 1 13 my ($self, $entity) = @_;
247 10   33     49 return $entities->{ $entity } || $entity;
248             }
249              
250             sub view_seq_index {
251 2     2 1 8 return '';
252             }
253              
254             sub view_seq_link {
255 3     3 1 8 my ($self, $link) = @_;
256 3 100       13 if ($link =~ s/^.*?\|//) {
257 1         6 return $link;
258             }
259             else {
260 2         12 return "the $link manpage";
261             }
262             }
263            
264            
265              
266             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
281              
282             =item C
283              
284             =item C
285              
286             =item C
287              
288             =item C
289              
290             =item C
291              
292             =item C
293              
294             =item C
295              
296             =item C
297              
298             =item C
299              
300             =item C
301              
302             =item C
303              
304             =item C
305              
306             =item C
307              
308             Returns the text of a CE> sequence in 'bold' (i.e. surrounded by asterisks, like *this*).
309              
310             =item C
311              
312             Returns the text of a CE> sequence in 'italics' (i.e. surrounded by underscores, like _this_).
313              
314             =item C
315              
316             =item C
317              
318             =item C
319              
320             =item C
321              
322             Returns an empty string. Index sequences are suppressed in text view.
323              
324             =item C
325              
326             =back
327              
328             =head1 AUTHOR
329              
330             Andy Wardley Eabw@kfs.orgE
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