View/Pod.pm
Go to the documentation of this file.
1 #============================================================= -*-Perl-*-
2 #
3 # Pod::POM::View::Pod
4 #
5 # DESCRIPTION
6 # Pod 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: Pod.pm 77 2009-08-20 20:44:14Z ford $
19 #
20 #========================================================================
21 
22 package BASIS::Pod::POM::View::Pod;
23 
24 require 5.004;
25 
26 use strict;
27 use BASIS::Pod::POM::Nodes;
28 use BASIS::Pod::POM::View;
29 use parent qw( BASIS::Pod::POM::View );
30 use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $MARKUP );
31 
32 $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
33 $DEBUG = 0 unless defined $DEBUG;
34 
35 # create reverse lookup table mapping method name to original sequence
36 $MARKUP = {
37  map { ( $BASIS::Pod::POM::Node::Sequence::NAME{ $_ } => $_ ) }
38  keys %BASIS::Pod::POM::Node::Sequence::NAME,
39 };
40 
41 
42 sub view {
43  my ($self, $type, $item) = @_;
44 
45 # my ($pkg, $file, $line) = caller;
46 # print STDERR "called view ($type) from $file line $line\n";
47 
48  if ($type =~ s/^seq_//) {
49  if ($type eq 'text') {
50  return "$item";
51  }
52  if ($type = $MARKUP->{ $type }) {
53  if ($item =~ /[<>]/) {
54  return "$type<< $item >>";
55  }
56  else {
57  return "$type<$item>";
58  }
59  }
60  }
61  elsif (ref $item eq 'HASH') {
62  if (defined $item->{ content }) {
63  return $item->{ content }->present($self);
64  }
65  elsif (defined $item->{ text }) {
66  my $text = $item->{ text };
67  return ref $text ? $text->present($self) : $text;
68  }
69  else {
70  return '';
71  }
72  }
73  elsif (! ref $item) {
74  return $item;
75  }
76  else {
77  return '';
78  }
79 }
80 
81 
82 sub view_pod {
83  my ($self, $pod) = @_;
84 # return "=pod\n\n" . $pod->content->present($self) . "=cut\n\n";
85  return $pod->content->present($self);
86 }
87 
88 
89 sub view_head1 {
90  my ($self, $head1) = @_;
91  return '=head1 '
92  . $head1->title->present($self)
93  . "\n\n"
94  . $head1->content->present($self);
95 }
96 
97 
98 sub view_head2 {
99  my ($self, $head2) = @_;
100  return '=head2 '
101  . $head2->title->present($self)
102  . "\n\n"
103  . $head2->content->present($self);
104 }
105 
106 
107 sub view_head3 {
108  my ($self, $head3) = @_;
109  return '=head3 '
110  . $head3->title->present($self)
111  . "\n\n"
112  . $head3->content->present($self);
113 }
114 
115 
116 sub view_head4 {
117  my ($self, $head4) = @_;
118  return '=head4 '
119  . $head4->title->present($self)
120  . "\n\n"
121  . $head4->content->present($self);
122 }
123 
124 
125 sub view_over {
126  my ($self, $over) = @_;
127  return '=over '
128  . $over->indent()
129  . "\n\n"
130  . $over->content->present($self)
131  . "=back\n\n";
132 }
133 
134 
135 sub view_item {
136  my ($self, $item) = @_;
137 
138  my $title = $item->title();
139  $title = $title->present($self) if ref $title;
140  return "=item $title\n\n"
141  . $item->content->present($self);
142 }
143 
144 
145 sub view_for {
146  my ($self, $for) = @_;
147  return '=for '
148  . $for->format . ' '
149  . $for->text()
150  . "\n\n"
151  . $for->content->present($self);
152 }
153 
154 
155 sub view_begin {
156  my ($self, $begin) = @_;
157  return '=begin '
158  . $begin->format()
159  . "\n\n"
160  . $begin->content->present($self)
161  . "=end "
162  . $begin->format()
163  . "\n\n";
164 }
165 
166 
167 sub view_textblock {
168  my ($self, $text) = @_;
169  return "$text\n\n";
170 }
171 
172 
173 sub view_verbatim {
174  my ($self, $text) = @_;
175  return "$text\n\n";
176 }
177 
178 
179 sub view_meta {
180  my ($self, $meta) = @_;
181  return '=meta '
182  . $meta->name()
183  . "\n\n"
184  . $meta->content->present($self)
185  . "=end\n\n";
186 }
187 
188 
189 1;
190 
191 =head1 NAME
192 
193 Pod::POM::View::Pod
194 
195 =head1 DESCRIPTION
196 
197 Pod view of a Pod Object Model.
198 
199 =head1 METHODS
200 
201 =over 4
202 
203 =item C<view($self, $type, $item)>
204 
205 =item C<view_pod($self, $pod)>
206 
207 =item C<view_head1($self, $head1)>
208 
209 =item C<view_head2($self, $head2)>
210 
211 =item C<view_head3($self, $head3)>
212 
213 =item C<view_head4($self, $head4)>
214 
215 =item C<view_over($self, $over)>
216 
217 =item C<view_item($self, $item)>
218 
219 =item C<view_for($self, $for)>
220 
221 =item C<view_begin($self, $begin)>
222 
223 =item C<view_textblock($self, $textblock)>
224 
225 =item C<view_verbatim($self, $verbatim)>
226 
227 =item C<view_meta($self, $meta)>
228 
229 =back
230 
231 =head1 AUTHOR
232 
233 Andy Wardley E<lt>abw@kfs.orgE<gt>
234 
235 =head1 COPYRIGHT AND LICENSE
236 
237 Copyright (C) 2000 Andy Wardley. All Rights Reserved.
238 
239 This module is free software; you can redistribute it and/or
240 modify it under the same terms as Perl itself.
241 
242 =cut