BASIS  r3148
Pod.pm
Go to the documentation of this file.
00001 #============================================================= -*-Perl-*-
00002 #
00003 # Pod::POM::View::Pod
00004 #
00005 # DESCRIPTION
00006 #   Pod view of a Pod Object Model.
00007 #
00008 # AUTHOR
00009 #   Andy Wardley   <abw@kfs.org>
00010 #
00011 # COPYRIGHT
00012 #   Copyright (C) 2000 Andy Wardley.  All Rights Reserved.
00013 #
00014 #   This module is free software; you can redistribute it and/or
00015 #   modify it under the same terms as Perl itself.
00016 #
00017 # REVISION
00018 #   $Id: Pod.pm 77 2009-08-20 20:44:14Z ford $
00019 #
00020 #========================================================================
00021 
00022 package BASIS::Pod::POM::View::Pod;
00023 
00024 require 5.004;
00025 
00026 use strict;
00027 use BASIS::Pod::POM::Nodes;
00028 use BASIS::Pod::POM::View;
00029 use parent qw( BASIS::Pod::POM::View );
00030 use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $MARKUP );
00031 
00032 $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
00033 $DEBUG   = 0 unless defined $DEBUG;
00034 
00035 # create reverse lookup table mapping method name to original sequence
00036 $MARKUP = {
00037     map { ( $BASIS::Pod::POM::Node::Sequence::NAME{ $_ } => $_ ) } 
00038        keys %BASIS::Pod::POM::Node::Sequence::NAME,
00039 };
00040 
00041 
00042 sub view {
00043     my ($self, $type, $item) = @_;
00044 
00045 #    my ($pkg, $file, $line) = caller;
00046 #    print STDERR "called view ($type) from $file line $line\n";
00047 
00048     if ($type =~ s/^seq_//) {
00049     if ($type eq 'text') {
00050         return "$item";
00051     }
00052     if ($type = $MARKUP->{ $type }) {
00053         if ($item =~ /[<>]/) {
00054         return "$type<< $item >>";
00055         }
00056         else {
00057         return "$type<$item>";      
00058         }
00059     }
00060     }
00061     elsif (ref $item eq 'HASH') {
00062     if (defined $item->{ content }) {
00063         return $item->{ content }->present($self);
00064     }
00065     elsif (defined $item->{ text }) {
00066         my $text = $item->{ text };
00067         return ref $text ? $text->present($self) : $text;
00068     }
00069     else {
00070         return '';
00071     }
00072     }
00073     elsif (! ref $item) {
00074     return $item;
00075     }
00076     else {
00077     return '';
00078     }
00079 }
00080 
00081 
00082 sub view_pod {
00083     my ($self, $pod) = @_;
00084 #    return "=pod\n\n" . $pod->content->present($self) . "=cut\n\n";
00085     return $pod->content->present($self);
00086 }
00087 
00088 
00089 sub view_head1 {
00090     my ($self, $head1) = @_;
00091     return '=head1 ' 
00092     . $head1->title->present($self) 
00093     . "\n\n"    
00094     . $head1->content->present($self);
00095 }
00096 
00097 
00098 sub view_head2 {
00099     my ($self, $head2) = @_;
00100     return '=head2 ' 
00101     . $head2->title->present($self) 
00102     . "\n\n" 
00103     . $head2->content->present($self);
00104 }
00105 
00106 
00107 sub view_head3 {
00108     my ($self, $head3) = @_;
00109     return '=head3 ' 
00110     . $head3->title->present($self) 
00111     . "\n\n" 
00112     . $head3->content->present($self);
00113 }
00114 
00115 
00116 sub view_head4 {
00117     my ($self, $head4) = @_;
00118     return '=head4 ' 
00119     . $head4->title->present($self) 
00120     . "\n\n" 
00121     . $head4->content->present($self);
00122 }
00123 
00124 
00125 sub view_over {
00126     my ($self, $over) = @_;
00127     return '=over ' 
00128     . $over->indent() 
00129     . "\n\n" 
00130     . $over->content->present($self) 
00131     . "=back\n\n";
00132 }
00133 
00134 
00135 sub view_item {
00136     my ($self, $item) = @_;
00137 
00138     my $title = $item->title();
00139     $title = $title->present($self) if ref $title;
00140     return "=item $title\n\n"
00141     . $item->content->present($self);
00142 }
00143 
00144 
00145 sub view_for {
00146     my ($self, $for) = @_;
00147     return '=for ' 
00148     . $for->format . ' ' 
00149     . $for->text() 
00150     . "\n\n"
00151     . $for->content->present($self);
00152 }
00153     
00154 
00155 sub view_begin {
00156     my ($self, $begin) = @_;
00157     return '=begin ' 
00158     . $begin->format() 
00159     . "\n\n"
00160     . $begin->content->present($self)
00161         . "=end "
00162     . $begin->format() 
00163     . "\n\n";
00164 }
00165     
00166 
00167 sub view_textblock {
00168     my ($self, $text) = @_;
00169     return "$text\n\n";
00170 }
00171 
00172 
00173 sub view_verbatim {
00174     my ($self, $text) = @_;
00175     return "$text\n\n";
00176 }
00177 
00178 
00179 sub view_meta {
00180     my ($self, $meta) = @_;
00181     return '=meta '
00182     . $meta->name()
00183     . "\n\n"
00184     . $meta->content->present($self)
00185         . "=end\n\n";
00186 }
00187 
00188 
00189 1;
00190 
00191 =head1 NAME
00192 
00193 Pod::POM::View::Pod
00194 
00195 =head1 DESCRIPTION
00196 
00197 Pod view of a Pod Object Model.
00198 
00199 =head1 METHODS
00200 
00201 =over 4
00202 
00203 =item C<view($self, $type, $item)>
00204 
00205 =item C<view_pod($self, $pod)>
00206 
00207 =item C<view_head1($self, $head1)>
00208 
00209 =item C<view_head2($self, $head2)>
00210 
00211 =item C<view_head3($self, $head3)>
00212 
00213 =item C<view_head4($self, $head4)>
00214 
00215 =item C<view_over($self, $over)>
00216 
00217 =item C<view_item($self, $item)>
00218 
00219 =item C<view_for($self, $for)>
00220 
00221 =item C<view_begin($self, $begin)>
00222 
00223 =item C<view_textblock($self, $textblock)>
00224 
00225 =item C<view_verbatim($self, $verbatim)>
00226 
00227 =item C<view_meta($self, $meta)>
00228 
00229 =back
00230 
00231 =head1 AUTHOR
00232 
00233 Andy Wardley E<lt>abw@kfs.orgE<gt>
00234 
00235 =head1 COPYRIGHT AND LICENSE
00236 
00237 Copyright (C) 2000 Andy Wardley.  All Rights Reserved.
00238 
00239 This module is free software; you can redistribute it and/or
00240 modify it under the same terms as Perl itself.
00241 
00242 =cut