home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / POM.pm < prev    next >
Encoding:
Perl POD Document  |  2002-03-08  |  43.2 KB  |  1,542 lines

  1. #============================================================= -*-Perl-*-
  2. #
  3. # Pod::POM
  4. #
  5. # DESCRIPTION
  6. #   Parses POD from a file or text string and builds a tree structure,
  7. #   hereafter known as the POD Object Model (POM).
  8. #
  9. # AUTHOR
  10. #   Andy Wardley   <abw@kfs.org>
  11. #
  12. # COPYRIGHT
  13. #   Copyright (C) 2000, 2001 Andy Wardley.  All Rights Reserved.
  14. #
  15. #   This module is free software; you can redistribute it and/or
  16. #   modify it under the same terms as Perl itself.
  17. #
  18. # REVISION
  19. #   $Id: POM.pm,v 1.4 2002/02/25 11:02:02 abw Exp $
  20. #
  21. #========================================================================
  22.  
  23. package Pod::POM;
  24.  
  25. require 5.004;
  26.  
  27. use strict;
  28. use Pod::POM::Constants qw( :all );
  29. use Pod::POM::Nodes;
  30. use Pod::POM::View::Pod;
  31.  
  32. use vars qw( $VERSION $DEBUG $ERROR $ROOT $TEXTSEQ $DEFAULT_VIEW );
  33. use base qw( Exporter );
  34.  
  35. $VERSION = 0.15;
  36. $DEBUG   = 0 unless defined $DEBUG;
  37. $ROOT    = 'Pod::POM::Node::Pod';               # root node class
  38. $TEXTSEQ = 'Pod::POM::Node::Sequence';          # text sequence class
  39. $DEFAULT_VIEW = 'Pod::POM::View::Pod';          # default view class
  40.  
  41.  
  42. #------------------------------------------------------------------------
  43. # allow 'meta' to be specified as a load option to activate =meta tags
  44. #------------------------------------------------------------------------
  45.  
  46. use vars qw( @EXPORT_FAIL @EXPORT_OK $ALLOW_META );
  47. @EXPORT_OK   = qw( meta );
  48. @EXPORT_FAIL = qw( meta );
  49. $ALLOW_META  = 0;
  50.  
  51. sub export_fail {
  52.     my $class = shift;
  53.     my $meta  = shift;
  54.     return ($meta, @_) unless $meta eq 'meta';
  55.     $ALLOW_META++;
  56.     return @_;
  57. }
  58.  
  59.  
  60.  
  61. #------------------------------------------------------------------------
  62. # new(\%options)
  63. #------------------------------------------------------------------------
  64.  
  65. sub new {
  66.     my $class  = shift;
  67.     my $config = ref $_[0] eq 'HASH' ? shift : { @_ };
  68.  
  69.     bless {
  70.     CODE     => $config->{ code } || 0,
  71.         WARN     => $config->{ warn } || 0,
  72.     META     => $config->{ meta } || $ALLOW_META,
  73.     WARNINGS => [ ],
  74.     FILENAME => '',
  75.     ERROR    => '',
  76.     }, $class;
  77. }
  78.  
  79.  
  80. #------------------------------------------------------------------------
  81. # parse($text_or_file)
  82. #
  83. # General purpose parse method which attempts to Do The Right Thing in
  84. # calling parse_file() or parse_text() according to the argument
  85. # passed.  A hash reference can be specified that contains a 'text'
  86. # or 'file' key and corresponding value.  Otherwise, the argument can
  87. # be a reference to an input handle which is passed off to parse_file().
  88. # If the argument is a text string that contains '=' at the start of 
  89. # any line then it is treated as Pod text and passed to parse_text(),
  90. # otherwise it is assumed to be a filename and passed to parse_file().
  91. #------------------------------------------------------------------------
  92.  
  93. sub parse {
  94.     my ($self, $input) = @_;
  95.     my $result;
  96.  
  97.     if (ref $input eq 'HASH') {
  98.     if ($input = $input->{ text }) {
  99.         $result = $self->parse_text($input, $input->{ name });
  100.     }
  101.     elsif ($input = $input->{ file }) {
  102.         $result = $self->parse_file($input);
  103.     }
  104.     else {
  105.         $result = $self->error("no 'text' or 'file' specified");
  106.     }
  107.     }
  108.     elsif (ref $input || $input !~ /^=/m) {    # doesn't look like POD text
  109.     $result = $self->parse_file($input);
  110.     }
  111.     else {                    # looks like POD text
  112.     $result = $self->parse_text($input);
  113.     }
  114.  
  115.     return $result;
  116. }
  117.  
  118.  
  119. #------------------------------------------------------------------------
  120. # parse_file($filename_or_handle)
  121. #
  122. # Reads the content of a Pod file specified by name or file handle, and
  123. # passes it to parse_text() for parsing.
  124. #------------------------------------------------------------------------
  125.  
  126. sub parse_file {
  127.     my ($self, $file) = @_;
  128.     my ($text, $name);
  129.  
  130.     if (ref $file) {        # assume open filehandle
  131.     local $/ = undef;
  132.     $name = '<filehandle>';
  133.     $text = <$file>;
  134.     }
  135.     else {            # a file which must be opened
  136.     local *FP;
  137.     local $/ = undef;
  138.     $name = ( $file eq '-' ? '<standard input>' : $file );
  139.     open(FP, $file) || return $self->error("$file: $!");
  140.     $text = <FP>;
  141.     close(FP);
  142.     }
  143.  
  144.     $self->parse_text($text, $name);
  145. }
  146.  
  147.  
  148. #------------------------------------------------------------------------
  149. # parse_text($text, $name)
  150. #
  151. # Main parser method.  Scans the input text for Pod sections and splits
  152. # them into paragraphs.  Builds a tree of Pod::POM::Node::* objects
  153. # to represent the Pod document in object model form.
  154. #------------------------------------------------------------------------
  155.  
  156. sub parse_text {
  157.     my ($self, $text, $name) = @_;
  158.     my ($para, $paralen, $gap, $type, $line, $inpod, $code, $result);
  159.     my $warn = $self->{ WARNINGS } = [ ];
  160.  
  161.     my @stack = ( );
  162.     my $item = $ROOT->new($self);
  163.     return $self->error($ROOT->error())
  164.     unless defined $item;
  165.     push(@stack, $item);
  166.  
  167.     $name = '<input text>' unless defined $name;
  168.     $self->{ FILENAME } = $name;
  169.  
  170.     $code   =  $self->{ CODE };
  171.     $line   = \$self->{ LINE };
  172.     $$line  = 1;
  173.     $inpod  = 0;
  174.  
  175.     
  176.     while ($text =~ /(?:(.*?)(\n{2,}))|(.+$)/sg) {
  177.     ($para, $gap) = defined $1 ? ($1, $2) : ($3, '');
  178.  
  179.     if ($para =~ s/^==?(\w+)\s*//) {
  180.         $type = $1;
  181.         # switch on for =pod or any other =cmd, switch off for =cut
  182.         if    ($type eq 'pod') { $inpod = 1; next }
  183.         elsif ($type eq 'cut') { $inpod = 0; next }
  184.         else                   { $inpod = 1 };
  185.  
  186.         if ($type eq 'meta') {
  187.         $self->{ META }
  188.             ? $stack[0]->metadata(split(/\s+/, $para, 2))
  189.             : $self->warning("metadata not allowed", $name, $$line);
  190.         next;
  191.         }
  192.     }
  193.     elsif (! $inpod) {
  194.         next unless $code;
  195.         $type  = 'code';
  196.         $para .= $gap;
  197.         $gap   = '';
  198.     }
  199.     elsif ($para =~ /^\s+/) {
  200.         $type = 'verbatim';
  201.     }
  202.     else {
  203.         $type = 'text';
  204.         chomp($para);        # catches last line in file
  205.     }
  206.     while(@stack) {
  207.         $result = $stack[-1]->add($self, $type, $para);
  208.         if (! defined $result) {
  209.         $self->warning($stack[-1]->error(), $name, $$line);
  210.         last;
  211.         }
  212.         elsif (ref $result) {
  213.         push(@stack, $result);
  214.         last;
  215.         }
  216.         elsif ($result == REDUCE) {
  217.         pop @stack;
  218.         last;
  219.         }
  220.         elsif ($result == REJECT) {
  221.         $self->warning($stack[-1]->error(), $name, $$line);
  222.         pop @stack;
  223.         }
  224.         elsif (@stack == 1) {
  225.         $self->warning("unexpected $type", $name, $$line);
  226.         last;
  227.         }
  228.         else {
  229.         pop @stack;
  230.         }
  231.     }
  232.     }
  233.     continue {
  234.     $$line += ($para =~ tr/\n//);
  235.     $$line += ($gap  =~ tr/\n//);
  236.     }
  237.  
  238.     return $stack[0];
  239. }
  240.  
  241.  
  242. #------------------------------------------------------------------------
  243. # parse_sequence($text)
  244. #
  245. # Parse a text paragraph to identify internal sequences (e.g. B<foo>)
  246. # which may be nested within each other.  Returns a simple scalar (no
  247. # embedded sequences) or a reference to a Pod::POM::Text object.
  248. #------------------------------------------------------------------------
  249.  
  250. sub parse_sequence {
  251.     my ($self, $text) = @_;
  252.     my ($cmd, $lparen, $rparen, $plain);
  253.     my ($name, $line, $warn) = @$self{ qw( FILENAME LINE WARNINGS ) };
  254.     my @stack;
  255.  
  256.     push(@stack, [ '', '', 'EOF', $name, $line, [ ] ] );
  257.     
  258.     while ($text =~ / 
  259.                       (?: ([A-Z]) (< (?:<+\s)?) )      # open
  260.             | ( (?:\s>+)? > )              # or close
  261.             | (?: (.+?)                  # or text...
  262.                 (?=                  # ...up to
  263.                 (?: [A-Z]< )              #   open
  264.                   | (?: (?: \s>+)? > )        #   or close  
  265.                               | $                         #   or EOF
  266.                             ) 
  267.                       )
  268.        /gxs) {
  269.     if (defined $1) {
  270.         ($cmd, $lparen) = ($1, $2);
  271.         $lparen =~ s/\s$//;
  272.         ($rparen = $lparen) =~ tr/</>/;
  273.         push(@stack, [ $cmd, $lparen, $rparen, $name, $line, [ ] ]);
  274.     }
  275.     elsif (defined $3) {
  276.         $rparen = $3;
  277.         $rparen =~ s/^\s+//;
  278.         if ($rparen eq $stack[-1]->[RPAREN]) {
  279.         $cmd = $TEXTSEQ->new(pop(@stack))
  280.             || return $self->error($TEXTSEQ->error());
  281.         push(@{ $stack[-1]->[CONTENT] }, $cmd);
  282.         }
  283.         else {
  284.         $self->warning((scalar @stack > 1 
  285.                   ? "expected '$stack[-1]->[RPAREN]' not '$rparen'"
  286.                   : "spurious '$rparen'"), $name, $line);
  287.         push(@{ $stack[-1]->[CONTENT] }, $rparen);
  288.         }
  289.     }
  290.     elsif (defined $4) {
  291.         $plain = $4;
  292.         push(@{ $stack[-1]->[CONTENT] }, $plain);
  293.         $line += ($plain =~ tr/\n//);
  294.     }
  295.     else {
  296.         $self->warning("unexpected end of input", $name, $line);
  297.         last;
  298.     }
  299.     }
  300.  
  301.     while (@stack > 1) {
  302.     $cmd = pop @stack;
  303.     $self->warning("unterminated '$cmd->[CMD]$cmd->[LPAREN]' starting", 
  304.                $name, $cmd->[LINE]);
  305.     $cmd = $TEXTSEQ->new($cmd)
  306.         || $self->error($TEXTSEQ->error());
  307.     push(@{ $stack[-1]->[CONTENT] }, $cmd);
  308.     }
  309.  
  310.     return $TEXTSEQ->new(pop(@stack))
  311.     || $self->error($TEXTSEQ->error());
  312. }
  313.  
  314.  
  315. #------------------------------------------------------------------------
  316. # default_view($viewer)
  317. #
  318. # Accessor method to return or update the $DEFVIEW package variable,
  319. # loading the module for any package name specified.
  320. #------------------------------------------------------------------------
  321.  
  322. sub default_view {
  323.     my ($self, $viewer) = @_;
  324.     return $DEFAULT_VIEW unless $viewer;
  325.     unless (ref $viewer) {
  326.     my $file = $viewer;
  327.     $file =~ s[::][/]g;
  328.     $file .= '.pm';
  329.     eval { require $file };
  330.     return $self->error($@) if $@;
  331.     }
  332.  
  333.     return ($DEFAULT_VIEW = $viewer);
  334. }
  335.  
  336.  
  337. #------------------------------------------------------------------------
  338. # warning($msg, $file, $line)
  339. #
  340. # Appends a string of the form " at $file line $line" to $msg if 
  341. # $file is specified and then stores $msg in the internals 
  342. # WARNINGS list.  If the WARN option is set then the warning is
  343. # raised, either via warn(), or by dispatching to a subroutine
  344. # when WARN is defined as such.
  345. #------------------------------------------------------------------------
  346.  
  347. sub warning {
  348.     my ($self, $msg, $file, $line) = @_;
  349.     my $warn = $self->{ WARN };
  350.     $line = 'unknown' unless defined $line && length $line;
  351.     $msg .= " at $file line $line" if $file;
  352.  
  353.     push(@{ $self->{ WARNINGS } }, $msg);
  354.  
  355.     if (ref $warn eq 'CODE') {
  356.     &$warn($msg);
  357.     }
  358.     elsif ($warn) {
  359.     warn($msg, "\n");
  360.     }
  361. }
  362.  
  363.  
  364. #------------------------------------------------------------------------
  365. # warnings()
  366. #
  367. # Returns a reference to the (possibly empty) list of warnings raised by
  368. # the most recent call to any of the parse_XXX() methods
  369. #------------------------------------------------------------------------
  370.  
  371. sub warnings {
  372.     my $self = shift;
  373.     return wantarray ? @{ $self->{ WARNINGS } } : $self->{ WARNINGS };
  374. }
  375.  
  376.  
  377. #------------------------------------------------------------------------
  378. # error($msg)
  379. #
  380. # Sets the internal ERROR member and returns undef when called with an
  381. # argument(s), returns the current value when called without.
  382. #------------------------------------------------------------------------
  383.  
  384. sub error {
  385.     my $self = shift;
  386.     my $errvar;
  387.  
  388.     { 
  389.     no strict qw( refs );
  390.     if (ref $self) {
  391.         $errvar = \$self->{ ERROR };
  392.     }
  393.     else {
  394.         $errvar = \${"$self\::ERROR"};
  395.     }
  396.     }
  397.     if (@_) {
  398.     $$errvar = ref($_[0]) ? shift : join('', @_);
  399.     return undef;
  400.     }
  401.     else {
  402.     return $$errvar;
  403.     }
  404. }
  405.  
  406.  
  407.  
  408. sub DEBUG {
  409.     print STDERR "DEBUG: ", @_ if $DEBUG;
  410. }
  411.  
  412. 1;
  413.  
  414. __END__
  415.  
  416. =head1 NAME
  417.  
  418. Pod::POM - POD Object Model
  419.  
  420. =head1 SYNOPSIS
  421.  
  422.     use Pod::POM;
  423.  
  424.     my $parser = Pod::POM->new(\%options);
  425.  
  426.     # parse from a text string
  427.     my $pom = $parser->parse_text($text)
  428.         || die $parser->error();
  429.  
  430.     # parse from a file specified by name or filehandle
  431.     my $pom = $parser->parse_text($file)
  432.         || die $parser->error();
  433.  
  434.     # parse from text or file 
  435.     my $pom = $parser->parse($text_or_file)
  436.         || die $parser->error();
  437.  
  438.     # examine any warnings raised
  439.     foreach my $warning ($parser->warnings()) {
  440.     warn $warning, "\n";
  441.     }
  442.  
  443.     # print table of contents using each =head1 title
  444.     foreach my $head1 ($pom->head1()) {
  445.     print $head1->title(), "\n";
  446.     }
  447.  
  448.     # print each section
  449.     foreach my $head1 ($pom->head1()) {
  450.     print $head1->title(), "\n";
  451.         print $head1->content();
  452.     }
  453.  
  454.     # print the entire document as HTML
  455.     use Pod::POM::View::HTML;
  456.     print Pod::POM::View::HTML->print($pom);
  457.  
  458.     # create custom view
  459.     package My::View;
  460.     use base qw( Pod::POM::View::HTML );
  461.  
  462.     sub view_head1 {
  463.     my ($self, $item) = @_;
  464.     return '<h1>', 
  465.            $item->title->present($self), 
  466.                "</h1>\n",
  467.            $item->content->present($self);
  468.     }
  469.     
  470.     package main;
  471.     print My::View->print($pom);
  472.  
  473. =head1 DESCRIPTION
  474.  
  475. This module implements a parser to convert Pod documents into a simple
  476. object model form known hereafter as the Pod Object Model.  The object
  477. model is generated as a hierarchical tree of nodes, each of which
  478. represents a different element of the original document.  The tree can
  479. be walked manually and the nodes examined, printed or otherwise
  480. manipulated.  In addition, Pod::POM supports and provides view objects
  481. which can automatically traverse the tree, or section thereof, and
  482. generate an output representation in one form or another.
  483.  
  484. Let's look at a typical Pod document by way of example.
  485.  
  486.     =head1 NAME
  487.  
  488.     My::Module - just another My::Module
  489.  
  490.     =head1 DESCRIPTION
  491.  
  492.     This is My::Module, a deeply funky piece of Perl code.
  493.  
  494.     =head2 METHODS
  495.  
  496.     My::Module implements the following methods
  497.  
  498.     =over 4
  499.  
  500.     =item new(\%config)
  501.  
  502.     This is the constructor method.  It accepts the following 
  503.     configuration options:
  504.  
  505.     =over 4
  506.  
  507.     =item name
  508.  
  509.     The name of the thingy.
  510.  
  511.     =item colour
  512.  
  513.     The colour of the thingy.
  514.  
  515.     =back
  516.  
  517.     =item print()
  518.  
  519.     This prints the thingy.
  520.  
  521.     =back
  522.  
  523.     =head1 AUTHOR
  524.  
  525.     My::Module was written by me E<lt>me@here.orgE<gt>
  526.  
  527. This document contains 3 main sections, NAME, DESCRIPTION and 
  528. AUTHOR, each of which is delimited by an opening C<=head1> tag.
  529. NAME and AUTHOR each contain only a single line of text, but 
  530. DESCRIPTION is more interesting.  It contains a line of text
  531. followed by the C<=head2> subsection, METHODS.  This contains
  532. a line of text and a list extending from the C<=over 4> to the 
  533. final C<=back> just before the AUTHOR section starts.  The list
  534. contains 2 items, C<new(\%config)>, which itself contains some 
  535. text and a list of 2 items, and C<print()>.
  536.  
  537. Presented as plain text and using indentation to indicate the element 
  538. nesting, the model then looks something like this :
  539.  
  540.     NAME
  541.         My::Module - just another My::Module
  542.  
  543.     DESCRIPTION
  544.     This is My::Module, a deeply funky piece of Perl code.
  545.  
  546.         METHODS
  547.         My::Module implements the following methods
  548.  
  549.         * new(\%config)
  550.             This is the constructor method.  It accepts the 
  551.             following configuration options:
  552.  
  553.             * name
  554.             The name of the thingy.
  555.  
  556.                 * colour
  557.             The colour of the thingy.
  558.  
  559.         * item print()
  560.             This prints the thingy.
  561.  
  562.     AUTHOR
  563.         My::Myodule was written by me <me@here.org>
  564.  
  565. Those of you familiar with XML may prefer to think of it in the
  566. following way:
  567.  
  568.     <pod>
  569.       <head1 title="NAME">
  570.         <p>My::Module - just another My::Module</p>
  571.       </head1>
  572.  
  573.       <head1 title="DESCRIPTION">
  574.         <p>This is My::Module, a deeply funky piece of 
  575.            Perl code.</p>
  576.  
  577.         <head2 title="METHODS">
  578.       <p>My::Module implements the following methods</p>
  579.  
  580.       <over indent=4>
  581.         <item title="item new(\%config)">
  582.           <p>This is the constructor method.  It accepts
  583.              the following configuration options:</p>
  584.  
  585.           <over indent=4>
  586.         <item title="name">
  587.               <p>The name of the thingy.</p>
  588.             </item>
  589.  
  590.             <item title="colour">
  591.               <p>The colour of the thingy.</p>
  592.             </item>
  593.               </over>
  594.             </item>
  595.  
  596.             <item title="print()">
  597.           <p>This prints the thingy.</p>
  598.         </item>
  599.           </over>
  600.         </head2>
  601.       </head1>
  602.  
  603.       <head1 title="AUTHOR">
  604.     <p>My::Myodule was written by me <me@here.org>
  605.       </head1>
  606.     </pod>
  607.  
  608. Notice how we can make certain assumptions about various elements.
  609. For example, we can assume that any C<=head1> section we find begins a
  610. new section and implicitly ends any previous section.  Similarly, we
  611. can assume an C<=item> ends when the next one begins, and so on.  In
  612. terms of the XML example shown above, we are saying that we're smart
  613. enough to add a C<E<lt>/head1E<gt>> element to terminate any
  614. previously opened C<E<lt>head1E<gt>> when we find a new C<=head1> tag
  615. in the input document.
  616.  
  617. However you like to visualise the content, it all comes down to the
  618. same underlying model.  The job of the Pod::POM module is to read an
  619. input Pod document and build an object model to represent it in this
  620. structured form. 
  621.  
  622. Each node in the tree (i.e. element in the document) is represented
  623. by a Pod::POM::Node::* object.  These encapsulate the attributes for
  624. an element (such as the title for a C<=head1> tag) and also act as
  625. containers for further Pod::POM::Node::* objects representing the
  626. content of the element.  Right down at the leaf nodes, we have simple
  627. object types to represent formatted and verbatim text paragraphs and
  628. other basic elements like these.
  629.  
  630. =head2 Parsing Pod
  631.  
  632. The Pod::POM module implements the methods parse_file($file),
  633. parse_text($text) and parse($file_or_text) to parse Pod files and
  634. input text.  They return a Pod::POM::Node::Pod object to represent the
  635. root of the Pod Object Model, effectively the C<E<lt>podE<gt>> element
  636. in the XML tree shown above.
  637.  
  638.     use Pod::POM;
  639.  
  640.     my $parser = Pod::POM->new();
  641.     my $pom = $parser->parse_file($filename)
  642.         || die $parser->error();
  643.  
  644. The parse(), parse_text() and parse_file() methods return
  645. undef on error.  The error() method can be called to retrieve the
  646. error message generated.  Parsing a document may also generate
  647. non-fatal warnings.  These can be retrieved via the warnings() method
  648. which returns a reference to a list when called in scalar context or a
  649. list of warnings when called in list context.
  650.  
  651.     foreach my $warn ($parser->warnings()) {
  652.     warn $warn, "\n";
  653.     }
  654.  
  655. Alternatively, the 'warn' configuration option can be set to have
  656. warnings automatically raised via C<warn()> as they are encountered.
  657.  
  658.     my $parser = Pod::POM->new( warn => 1 );
  659.  
  660. =head2 Walking the Object Model
  661.  
  662. Having parsed a document into an object model, we can then select 
  663. various items from it.  Each node implements methods (via AUTOLOAD)
  664. which correspond to the attributes and content elements permitted
  665. within in.
  666.  
  667. So to fetch the list of '=head1' sections within our parsed document,
  668. we would do the following:
  669.  
  670.     my $sections = $pom->head1();
  671.  
  672. Methods like this will return a list of further Pod::POM::Node::* 
  673. objects when called in list context or a reference to a list when 
  674. called in scalar context.  In the latter case, the list is blessed
  675. into the Pod::POM::Node::Content class which gives it certain 
  676. magical properties (more on that later).
  677.  
  678. Given the list of Pod::POM::Node::Head1 objects returned by the above,
  679. we can print the title attributes of each like this:
  680.  
  681.     foreach my $s (@$sections) {
  682.     print $s->title();
  683.     }
  684.  
  685. Let's look at the second section, DESCRIPTION.
  686.  
  687.     my $desc = $sections->[1];
  688.  
  689. We can print the title of each subsection within it:
  690.  
  691.     foreach my $ss ($desc->head2()) {
  692.     print $ss->title();
  693.     }
  694.  
  695. Hopefully you're getting the idea by now, so here's a more studly
  696. example to print the title for each item contained in the first list
  697. within the METHODS section:
  698.  
  699.     foreach my $item ($desc->head2->[0]->over->[0]->item) {
  700.     print $item->title(), "\n";
  701.     }
  702.  
  703. =head2 Element Content
  704.  
  705. This is all well and good if you know the precise structure of a 
  706. document in advance.  For those more common cases when you don't,
  707. each node that can contain other nodes provides a 'content' method
  708. to return a complete list of all the other nodes that it contains.
  709. The 'type' method can be called on any node to return its element
  710. type (e.g. 'head1', 'head2', 'over', item', etc).
  711.  
  712.     foreach my $item ($pom->content()) {
  713.     my $type = $item->type();
  714.     if ($type eq 'head1') {
  715.         ...
  716.     }
  717.     elsif ($type eq 'head2') {
  718.         ...
  719.     }
  720.     ...
  721.     }
  722.  
  723. The content for an element is represented by a reference to a list,
  724. blessed into the Pod::POM::Node::Content class.  This provides some
  725. magic in the form of an overloaded stringification operator which 
  726. will automatically print the contents of the list if you print 
  727. the object itself.  In plain English, or rather, in plain Perl,
  728. this means you can do things like the following:
  729.  
  730.     foreach my $head1 ($pom->head1()) {
  731.     print '<h1>', $head1->title(), "</h1>\n\n";
  732.     print $head1->content();
  733.     }
  734.  
  735.     # print all the root content
  736.     foreach my $item ($pom->content()) {
  737.     print $item;
  738.     }
  739.  
  740.     # same as above
  741.     print $pom->content();
  742.  
  743. In fact, all Pod::POM::Node::* objects provide this same magic, and
  744. will attempt to Do The Right Thing to present themselves in the
  745. appropriate manner when printed.  Thus, the following are all valid.
  746.  
  747.     print $pom;            # entire document
  748.     print $pom->content;    # content of document
  749.     print $pom->head1->[0];    # just first section
  750.     print $pom->head1;        # print all sections
  751.     foreach my $h1 ($pom->head1()) {
  752.     print $h1->head2();    # print all subsections
  753.     }
  754.  
  755. =head2 Output Views
  756.  
  757. To understand how the different elements go about presenting
  758. themselves in "the appropriate manner", we must introduce the concept
  759. of a view.  A view is quite simply a particular way of looking at the
  760. model.  In real terms, we can think of a view as being some kind of
  761. output type generated by a pod2whatever converter.  Notionally we can
  762. think in terms of reading in an input document, building a Pod Object
  763. Model, and then generating an HTML view of the document, and/or a
  764. LaTeX view, a plain text view, and so on.
  765.  
  766. A view is represented in this case by an object class which contains
  767. methods for displaying each of the different element types that could
  768. be encountered in any Pod document.  There's a method for displaying
  769. C<=head1> sections (view_head1()), another method for displaying
  770. C<=head2> sections (view_head2()), one for C<=over> (view_over()),
  771. another for C<=item> (view_item()) and so on.
  772.  
  773. If we happen to have a reference to a $node and we know it's a 'head1'
  774. node, then we can directly call the right view method to have it
  775. displayed properly:
  776.  
  777.     $view = 'Pod::POM::View::HTML';
  778.     $view->view_head1($node);
  779.  
  780. Thus our earlier example can be modified to be I<slightly> less laborious
  781. and I<marginally> more flexible.
  782.  
  783.     foreach my $node ($pom->content) {
  784.     my $type = $node->type();
  785.     if ($type eq 'head1') {
  786.         print $view->view_head1($node);
  787.     }
  788.     elsif ($type eq 'head2') {
  789.         print $view->view_head2($node);
  790.     }
  791.     ...
  792.     }
  793.  
  794. However, this is still far from ideal.  To make life easier, each
  795. Pod::POM::Node::* class inherits (or possibly redefines) a
  796. C<present($view)> method from the Pod::POM::Node base class.  This method
  797. expects a reference to a view object passed as an argument, and it
  798. simply calls the appropriate view_xxx() method on the view object,
  799. passing itself back as an argument.  In object parlance, this is known
  800. as "double dispatch".  The beauty of it is that you don't need to know
  801. what kind of node you have to be able to print it.  You simply pass
  802. it a view object and leave it to work out the rest.
  803.  
  804.     foreach my $node ($pom->content) {
  805.     print $node->present($view);
  806.     }
  807.  
  808. If $node is a Pod::POM::Node::Head1 object, then the view_head1($node)
  809. method gets called against the $view object.  Otherwise, if it's a
  810. Pod::POM::Node::Head2 object, then the view_head2($node) method is
  811. dispatched.  And so on, and so on, with each node knowing what it is
  812. and where it's going as if determined by some genetically pre-programmed
  813. instinct.  Fullfilling their destinies, so to speak.
  814.  
  815. Double dispatch allows us to do away with all the explicit type
  816. checking and other nonsense and have the node objects themselves worry
  817. about where they should be routed to.  At the cost of an extra method
  818. call per node, we get programmer convenience, and that's usually 
  819. a Good Thing.
  820.  
  821. Let's have a look at how the view and node classes might be
  822. implemented.
  823.  
  824.     package Pod::POM::View::HTML;
  825.  
  826.     sub view_pod {
  827.     my ($self, $node) = @_;
  828.     return $node->content->present($self);
  829.     }
  830.  
  831.     sub view_head1 {
  832.     my ($self, $node) = @_;
  833.     return "<h1>", $node->title->present($self), "</h1>\n\n"
  834.          . $node->content->present($self);
  835.     }
  836.  
  837.     sub view_head2 {
  838.     my ($self, $node) = @_;
  839.     return "<h2>", $node->title->present($self), "</h2>\n\n"
  840.          . $node->content->present($self);
  841.     }
  842.  
  843.     ...
  844.  
  845.     package Pod::POM::Node::Pod;
  846.  
  847.     sub present {
  848.     my ($self, $view) = @_;
  849.     $view->view_pod($self);
  850.     }
  851.  
  852.     package Pod::POM::Node::Head1;
  853.  
  854.     sub present {
  855.     my ($self, $view) = @_;
  856.     $view->view_head1($self);
  857.     }
  858.  
  859.     package Pod::POM::Node::Head2;
  860.  
  861.     sub present {
  862.     my ($self, $view) = @_;
  863.     $view->view_head2($self);
  864.     }
  865.  
  866.     ...
  867.  
  868. Some of the view_xxx methods make calls back against the node objects
  869. to display their attributes and/or content.  This is shown in, for
  870. example, the view_head1() method above, where the method prints the
  871. section title in C<E<lt>h1E<gt>>...C<E<lt>h1E<gt>> tags, followed by
  872. the remaining section content.
  873.  
  874. Note that the title() attribute is printed by calling its present()
  875. method, passing on the reference to the current view.  Similarly,
  876. the content present() method is called giving it a chance to Do
  877. The Right Thing to present itself correctly via the view object.
  878.  
  879. There's a good chance that the title attribute is going to be regular
  880. text, so we might be tempted to simply print the title rather than 
  881. call its present method.
  882.  
  883.     sub view_head1 {
  884.     my ($self, $node) = @_;
  885.     # not recommended, prefer $node->title->present($self)
  886.     return "<h1>", $node->title(), "</h1>\n\n", ...
  887.     }
  888.  
  889. However, it is entirely valid for titles and other element attributes,
  890. as well as regular, formatted text blocks to contain code sequences,
  891. such like C<BE<lt>thisE<gt>> and C<IE<lt>thisE<gt>>.  These are used
  892. to indicate different markup styles, mark external references or index
  893. items, and so on.  What's more, they can be C<BE<lt>nested
  894. IE<lt>indefinatelyE<gt>E<gt>>.  Pod::POM takes care of all this by
  895. parsing such text, along with any embedded sequences, into Yet Another
  896. Tree, the root node of which is a Pod::POM::Node::Text object,
  897. possibly containing other Pod::POM::Node::Sequence objects.  When the
  898. text is presented, the tree is automatically walked and relevant
  899. callbacks made against the view for the different sequence types.  The
  900. methods called against the view are all prefixed 'view_seq_', e.g.
  901. 'view_seq_bold', 'view_seq_italic'.
  902.  
  903. Now the real magic comes into effect.  You can define one view to
  904. render bold/italic text in one style:
  905.  
  906.     package My::View::Text;
  907.     use base qw( Pod::POM::View::Text );
  908.  
  909.     sub view_seq_bold {
  910.     my ($self, $text) = @_;
  911.     return "*$text*";
  912.     }
  913.  
  914.     sub view_seq_italic {
  915.     my ($self, $text) = @_;
  916.     return "_$text_";
  917.     }
  918.  
  919. And another view to render it in a different style:
  920.  
  921.     package My::View::HTML;
  922.     use base qw( Pod::POM::View::HTML );
  923.  
  924.     sub view_seq_bold {
  925.     my ($self, $text) = @_;
  926.     return "<b>$text</b>";
  927.     }
  928.  
  929.     sub view_seq_italic {
  930.     my ($self, $text) = @_;
  931.     return "<i>$text</i>";
  932.     }
  933.  
  934. Then, you can easily view a Pod Object Model in either style:
  935.  
  936.     my $text = 'My::View::Text';
  937.     my $html = 'My::View::HTML';
  938.  
  939.     print $pom->present($text);
  940.     print $pom->present($html);
  941.  
  942. And you can apply this technique to any node within the object
  943. model.
  944.  
  945.     print $pom->head1->[0]->present($text);
  946.     print $pom->head1->[0]->present($html);
  947.  
  948. In these examples, the view passed to the present() method has 
  949. been a class name.  Thus, the view_xxx methods get called as 
  950. class methods, as if written:
  951.  
  952.     My::View::Text->view_head1(...);
  953.  
  954. If your view needs to maintain state then you can create a view object
  955. and pass that to the present() method.  
  956.  
  957.     my $view = My::View->new();
  958.     $node->present($view);
  959.  
  960. In this case the view_xxx methods get called as object methods.
  961.  
  962.     sub view_head1 {
  963.     my ($self, $node) = @_;
  964.     my $title = $node->title();
  965.     if ($title eq 'NAME' && ref $self) {
  966.         $self->{ title } = $title();
  967.     }
  968.     $self->SUPER::view_head1($node);
  969.     }
  970.  
  971. Whenever you print a Pod::POM::Node::* object, or do anything to cause
  972. Perl to stringify it (such as including it another quoted string "like
  973. $this"), then its present() method is automatically called.  When
  974. called without a view argument, the present() method uses the default
  975. view specified in $Pod::POM::DEFAULT_VIEW, which is, by default,
  976. 'Pod::POM::View::Pod'.  This view regenerates the original Pod
  977. document, although it should be noted that the output generated may
  978. not be exactly the same as the input.  The parser is smart enough to
  979. detect some common errors (e.g. not terminating an C<=over> with a C<=back>)
  980. and correct them automatically.  Thus you might find a C<=back>
  981. correctly placed in the output, even if you forgot to add it to the 
  982. input.  Such corrections raise non-fatal warnings which can later
  983. be examined via the warnings() method.
  984.  
  985. You can update the $Pod::POM::DEFAULT_VIEW package variable to set the 
  986. default view, or call the default_view() method.  The default_view() 
  987. method will automatically load any package you specify.  If setting
  988. the package variable directly, you should ensure that any packages
  989. required have been pre-loaded.
  990.  
  991.     use My::View::HTML;
  992.     $Pod::POM::DEFAULT_VIEW = 'My::View::HTML';
  993.  
  994. or
  995.  
  996.     Pod::POM->default_view('My::View::HTML');
  997.  
  998. =head2 Template Toolkit Views
  999.  
  1000. One of the motivations for writing this module was to make it easier
  1001. to customise Pod documentation to your own look and feel or local
  1002. formatting conventions.  By clearly separating the content
  1003. (represented by the Pod Object Model) from the presentation style
  1004. (represented by one or more views) it becomes much easier to achieve
  1005. this.
  1006.  
  1007. The latest version of the Template Toolkit (2.06 at the time of
  1008. writing) provides a Pod plugin to interface to this module.  It also
  1009. implements a new (but experimental) VIEW directive which can be used
  1010. to build different presentation styles for converting Pod to other
  1011. formats.  The Template Toolkit is available from CPAN:
  1012.  
  1013.     http://www.cpan.org/modules/by-module/Template/
  1014.  
  1015. Template Toolkit views are similar to the Pod::POM::View objects
  1016. described above, except that they allow the presentation style for
  1017. each Pod component to be written as a template file or block rather
  1018. than an object method.  The precise syntax and structure of the VIEW
  1019. directive is subject to change (given that it's still experimental),
  1020. but at present it can be used to define a view something like this:
  1021.  
  1022.     [% VIEW myview %]
  1023.  
  1024.        [% BLOCK view_head1 %]
  1025.           <h1>[% item.title.present(view) %]</h1>
  1026.           [% item.content.present(view) %]
  1027.        [% END %]
  1028.  
  1029.        [% BLOCK view_head2 %]
  1030.           <h2>[% item.title.present(view) %]</h2>
  1031.           [% item.content.present(view) %]
  1032.        [% END %]
  1033.  
  1034.        ...
  1035.  
  1036.     [% END %]
  1037.  
  1038. A plugin is provided to interface to the Pod::POM module:
  1039.  
  1040.     [% USE pod %]
  1041.     [% pom = pod.parse('/path/to/podfile') %]
  1042.  
  1043. The returned Pod Object Model instance can then be navigated and
  1044. presented via the view in almost any way imaginable:
  1045.  
  1046.     <h1>Table of Contents</h1>
  1047.     <ul>
  1048.     [% FOREACH section = pom.head1 %]
  1049.        <li>[% section.title.present(view) %]
  1050.     [% END %]
  1051.     </ul>
  1052.  
  1053.     <hr>
  1054.  
  1055.     [% FOREACH section = pom.head1 %]
  1056.        [% section.present(myview) %]
  1057.     [% END %]
  1058.  
  1059. You can either pass a reference to the VIEW (myview) to the 
  1060. present() method of a Pod::POM node:
  1061.  
  1062.     [% pom.present(myview) %]        # present entire document
  1063.  
  1064. Or alternately call the print() method on the VIEW, passing the 
  1065. Pod::POM node as an argument:
  1066.  
  1067.     [% myview.print(pom) %]
  1068.  
  1069. Internally, the view calls the present() method on the node,
  1070. passing itself as an argument.  Thus it is equivalent to the 
  1071. previous example.
  1072.  
  1073. The Pod::POM node and the view conspire to "Do The Right Thing" to 
  1074. process the right template block for the node.  A reference to the
  1075. node is available within the template as the 'item' variable.
  1076.  
  1077.    [% BLOCK view_head2 %]
  1078.       <h2>[% item.title.present(view) %]</h2>
  1079.       [% item.content.present(view) %]
  1080.    [% END %]
  1081.  
  1082. The Template Toolkit documentation contains further information on
  1083. defining and using views.  However, as noted above, this may be
  1084. subject to change or incomplete pending further development of the 
  1085. VIEW directive.
  1086.  
  1087. =head1 METHODS
  1088.  
  1089. =head2 new(\%config)
  1090.  
  1091. Constructor method which instantiates and returns a new Pod::POM 
  1092. parser object.  
  1093.  
  1094.     use Pod::POM;
  1095.  
  1096.     my $parser = Pod::POM->new();
  1097.  
  1098. A reference to a hash array of configuration options may be passed as
  1099. an argument.
  1100.  
  1101.     my $parser = Pod::POM->new( { warn => 1 } );
  1102.  
  1103. For convenience, configuration options can also be passed as a list of
  1104. (key =E<gt> value) pairs.
  1105.  
  1106.     my $parser = Pod::POM->new( warn => 1 );
  1107.  
  1108. The following configuration options are defined:
  1109.  
  1110. =over 4
  1111.  
  1112. =item code
  1113.  
  1114. This option can be set to have all non-Pod parts of the input document
  1115. stored within the object model as 'code' elements, represented by 
  1116. objects of the Pod::POM::Node::Code class.  It is disabled by default
  1117. and code sections are ignored.  
  1118.  
  1119.     my $parser = Pod::POM->new( code => 1 );
  1120.     my $podpom = $parser->parse(\*DATA);
  1121.  
  1122.     foreach my $code ($podpom->code()) {
  1123.     print "<pre>$code</pre>\n";
  1124.     }
  1125.  
  1126.     __DATA__
  1127.     This is some program code.
  1128.  
  1129.     =head1 NAME
  1130.  
  1131.     ...
  1132.  
  1133. This will generate the output:
  1134.  
  1135.     <pre>This is some program code.</pre>
  1136.  
  1137. Note that code elements are stored within the POM element in which
  1138. they are encountered.  For example, the code element below embedded
  1139. within between Pod sections is stored in the array which can be
  1140. retrieved by calling C<$podpom-E<gt>head1-E<gt>[0]-E<gt>code()>.
  1141.  
  1142.     =head1 NAME
  1143.  
  1144.     My::Module::Name;
  1145.  
  1146.     =cut
  1147.  
  1148.     Some program code embedded in Pod.
  1149.  
  1150.     =head1 SYNOPSIS
  1151.  
  1152.     ...
  1153.  
  1154. =item warn
  1155.  
  1156. Non-fatal warnings encountered while parsing a Pod document are stored 
  1157. internally and subsequently available via the warnings() method.
  1158.  
  1159.     my $parser = Pod::POM->new();
  1160.     my $podpom = $parser->parse_file($filename);
  1161.  
  1162.     foreach my $warning ($parser->warnings()) {
  1163.     warn $warning, "\n";
  1164.     }
  1165.  
  1166. The 'warn' option can be set to have warnings raised automatically 
  1167. via C<warn()> as and when they are encountered.
  1168.  
  1169.     my $parser = Pod::POM->new( warn => 1 );
  1170.     my $podpom = $parser->parse_file($filename);
  1171.  
  1172. If the configuration value is specified as a subroutine reference then
  1173. the code will be called each time a warning is raised, passing the
  1174. warning message as an argument.
  1175.  
  1176.     sub my_warning {
  1177.     my $msg = shift;
  1178.     warn $msg, "\n";
  1179.     };
  1180.  
  1181.     my $parser = Pod::POM->new( warn => \&my_warning );
  1182.     my $podpom = $parser->parse_file($filename);
  1183.  
  1184. =item meta
  1185.  
  1186. The 'meta' option can be set to allow C<=meta> tags within the Pod
  1187. document.  
  1188.  
  1189.     my $parser = Pod::POM->new( meta => 1 );
  1190.     my $podpom = $parser->parse_file($filename);
  1191.  
  1192. This is an experimental feature which is not part of standard
  1193. POD.  For example:
  1194.  
  1195.     =meta author Andy Wardley
  1196.  
  1197. These are made available as metadata items within the root
  1198. node of the parsed POM.
  1199.  
  1200.     my $author = $podpom->metadata('author');
  1201.  
  1202. See the L<METADATA|METADATA> section below for further information.
  1203.  
  1204. =back
  1205.  
  1206. =head2 parse_file($file)
  1207.  
  1208. Parses the file specified by name or reference to a file handle.
  1209. Returns a reference to a Pod::POM::Node::Pod object which represents
  1210. the root node of the Pod Object Model on success.  On error, undef
  1211. is returned and the error message generated can be retrieved by calling
  1212. error().
  1213.  
  1214.     my $podpom = $parser->parse_file($filename)
  1215.         || die $parser->error();
  1216.  
  1217.     my $podpom = $parser->parse_file(\*STDIN)
  1218.         || die $parser->error();
  1219.  
  1220. Any warnings encountered can be examined by calling the 
  1221. warnings() method.
  1222.  
  1223.     foreach my $warn ($parser->warnings()) {
  1224.     warn $warn, "\n";
  1225.     }
  1226.  
  1227. =head2 parse_text($text)
  1228.  
  1229. Parses the Pod text string passed as an argument into a Pod Object
  1230. Model, as per parse_file().
  1231.  
  1232. =head2 parse($text_or_$file)
  1233.  
  1234. General purpose method which attempts to Do The Right Thing in calling
  1235. parse_file() or parse_text() according to the argument passed.  
  1236.  
  1237. A hash reference can be passed as an argument that contains a 'text'
  1238. or 'file' key and corresponding value. 
  1239.  
  1240.     my $podpom = $parser->parse({ file => $filename })
  1241.         || die $parser->error();
  1242.  
  1243. Otherwise, the argument can be a reference to an input handle which is
  1244. passed off to parse_file().  
  1245.  
  1246.     my $podpom = $parser->parse(\*DATA)
  1247.         || die $parser->error();
  1248.  
  1249. If the argument is a text string that looks like Pod text (i.e. it
  1250. contains '=' at the start of any line) then it is passed to parse_text().
  1251.  
  1252.     my $podpom = $parser->parse($podtext)
  1253.         || die $parser->error();
  1254.  
  1255. Otherwise it is assumed to be a filename and is passed to parse_file().
  1256.  
  1257.     my $podpom = $parser->parse($podfile)
  1258.         || die $parser->error();
  1259.  
  1260. =head1 NODE TYPES, ATTRIBUTES AND ELEMENTS
  1261.  
  1262. This section lists the different nodes that may be present in a Pod Object
  1263. Model.  These are implemented as Pod::POM::Node::* object instances 
  1264. (e.g. head1 =E<gt> Pod::POM::Node::Head1).  To present a node, a view should
  1265. implement a method which corresponds to the node name prefixed by 'view_'
  1266. (e.g. head1 =E<gt> view_head1()).
  1267.  
  1268. =over 4
  1269.  
  1270. =item pod
  1271.  
  1272. The C<pod> node is used to represent the root node of the Pod Object Model.
  1273.  
  1274. Content elements: head1, head2, head3, head4, over, begin, for,
  1275. verbatim, text, code.
  1276.  
  1277. =item head1
  1278.  
  1279. A C<head1> node contains the Pod content from a C<=head1> tag up to the 
  1280. next C<=head1> tag or the end of the file.
  1281.  
  1282. Attributes: title
  1283.  
  1284. Content elements: head2, head3, head4, over, begin, for, verbatim, text, code.
  1285.  
  1286. =item head2
  1287.  
  1288. A C<head2> node contains the Pod content from a C<=head2> tag up to the 
  1289. next C<=head1> or C<=head2> tag or the end of the file.
  1290.  
  1291. Attributes: title
  1292.  
  1293. Content elements: head3, head4, over, begin, for, verbatim, text, code.
  1294.  
  1295. =item head3
  1296.  
  1297. A C<head3> node contains the Pod content from a C<=head3> tag up to the 
  1298. next C<=head1>, C<=head2> or C<=head3> tag or the end of the file.
  1299.  
  1300. Attributes: title
  1301.  
  1302. Content elements: head4, over, begin, for, verbatim, text, code.
  1303.  
  1304. =item head4
  1305.  
  1306. A C<head4> node contains the Pod content from a C<=head4> tag up to the 
  1307. next C<=head1>, C<=head2>, C<=head3> or C<=head4> tag or the end of the file.
  1308.  
  1309. Attributes: title
  1310.  
  1311. Content elements: over, begin, for, verbatim, text, code.
  1312.  
  1313. =item over
  1314.  
  1315. The C<over> node encloses the Pod content in a list starting at an C<=over> 
  1316. tag and continuing up to the matching C<=back> tag.  Lists may be nested 
  1317. indefinately.
  1318.  
  1319. Attributes: indent (default: 4)
  1320.  
  1321. Content elements: over, item, begin, for, verbatim, text, code.
  1322.  
  1323. =item item
  1324.  
  1325. The C<item> node encloses the Pod content in a list item starting at an 
  1326. C<=item> tag and continuing up to the next C<=item> tag or a C<=back> tag
  1327. which terminates the list.
  1328.  
  1329. Attributes: title (default: *)
  1330.  
  1331. Content elements: over, begin, for, verbatim, text, code.
  1332.  
  1333. =item begin
  1334.  
  1335. A C<begin> node encloses the Pod content in a conditional block starting 
  1336. with a C<=begin> tag and continuing up to the next C<=end> tag.
  1337.  
  1338. Attributes: format
  1339.  
  1340. Content elements: verbatim, text, code.
  1341.  
  1342. =item for
  1343.  
  1344. A C<for> node contains a single paragraph containing text relevant to a 
  1345. particular format.
  1346.  
  1347. Attributes: format, text
  1348.  
  1349. =item verbatim
  1350.  
  1351. A C<verbatim> node contains a verbatim text paragraph which is prefixed by
  1352. whitespace in the source Pod document (i.e. indented).
  1353.  
  1354. Attributes: text
  1355.  
  1356. =item text
  1357.  
  1358. A C<text> node contains a regular text paragraph.  This may include 
  1359. embedded inline sequences.
  1360.  
  1361. Attributes: text
  1362.  
  1363. =item code
  1364.  
  1365. A C<code> node contains Perl code which is by default, not considered to be 
  1366. part of a Pod document.  The C<code> configuration option must be set for
  1367. Pod::POM to generate code blocks, otherwise they are ignored.
  1368.  
  1369. Attributes: text
  1370.  
  1371. =back
  1372.  
  1373. =head1 INLINE SEQUENCES
  1374.  
  1375. Embedded sequences are permitted within regular text blocks (i.e. not
  1376. verbatim) and title attributes.  To present these sequences, a view
  1377. should implement methods corresponding to the sequence name, prefixed
  1378. by 'view_seq_' (e.g. bold =E<gt> view_seq_bold()).
  1379.  
  1380. =over 4
  1381.  
  1382. =item code
  1383.  
  1384. Code extract, e.g. CE<lt>my codeE<gt>
  1385.  
  1386. =item bold
  1387.  
  1388. Bold text, e.g. BE<lt>bold textE<gt>
  1389.  
  1390. =item italic
  1391.  
  1392. Italic text, e.g. IE<lt>italic textE<gt>
  1393.  
  1394. =item link
  1395.  
  1396. A link (cross reference), e.g. LE<lt>My::ModuleE<gt>
  1397.  
  1398. =item space
  1399.  
  1400. Text contains non-breaking space, e.g.SE<lt>Buffy The Vampire SlayerE<gt>
  1401.  
  1402. =item file
  1403.  
  1404. A filename, e.g. FE<lt>/etc/lilo.confE<gt>
  1405.  
  1406. =item index
  1407.  
  1408. An index entry, e.g. XE<lt>AngelE<gt>
  1409.  
  1410. =item zero
  1411.  
  1412. A zero-width character, e.g. ZE<lt>E<gt>
  1413.  
  1414. =item entity
  1415.  
  1416. An entity escape, e.g. EE<lt>ltE<gt>
  1417.  
  1418. =back
  1419.  
  1420. =head1 BUNDLED MODULES AND TOOLS
  1421.  
  1422. The Pod::POM module distribution includes a number of sample view
  1423. objects for rendering Pod Object Models into particular formats.  These
  1424. are incomplete and may require some further work, but serve at present to 
  1425. illustrate the principal and can be used as the basis for your own view
  1426. objects.
  1427.  
  1428. =over 4
  1429.  
  1430. =item Pod::POM::View::Pod
  1431.  
  1432. Regenerates the model as Pod.
  1433.  
  1434. =item Pod::POM::View::Text
  1435.  
  1436. Presents the model as plain text.
  1437.  
  1438. =item Pod::POM::View::HTML
  1439.  
  1440. Presents the model as HTML.
  1441.  
  1442. =back
  1443.  
  1444. A script is provided for converting Pod documents to other format by
  1445. using the view objects provided.  The C<pom2> script should be called 
  1446. with two arguments, the first specifying the output format, the second
  1447. the input filename.  e.g.
  1448.  
  1449.     $ pom2 text My/Module.pm > README
  1450.     $ pom2 html My/Module.pm > ~/public_html/My/Module.html
  1451.  
  1452. You can also create symbolic links to the script if you prefer and 
  1453. leave it to determine the output format from its own name.
  1454.  
  1455.     $ ln -s pom2 pom2text    
  1456.     $ ln -s pom2 pom2html
  1457.     $ pom2text My/Module.pm > README
  1458.     $ pom2html My/Module.pm > ~/public_html/My/Module.html
  1459.  
  1460. The distribution also contains a trivial script, C<podlint>
  1461. (previously C<pomcheck>), which checks a Pod document for
  1462. well-formedness by simply parsing it into a Pod Object Model with
  1463. warnings enabled.  Warnings are printed to STDERR.
  1464.  
  1465.     $ podlint My/Module.pm
  1466.  
  1467. The C<-f> option can be set to have the script attempt to fix any problems
  1468. it encounters.  The regenerated Pod output is printed to STDOUT.
  1469.  
  1470.     $ podlint -f My/Module.pm > newfile
  1471.  
  1472. =head1 METADATA
  1473.  
  1474. This module includes support for an experimental new C<=meta> tag.  This
  1475. is disabled by default but can be enabled by loading Pod::POM with the 
  1476. C<meta> option.
  1477.  
  1478.     use Pod::POM qw( meta );
  1479.  
  1480. Alternately, you can specify the C<meta> option to be any true value when 
  1481. you instantiate a Pod::POM parser:
  1482.  
  1483.     my $parser = Pod::POM->new( meta => 1 );
  1484.     my $pom    = $parser->parse_file($filename);
  1485.  
  1486. Any C<=meta> tags in the document will be stored as metadata items in the 
  1487. root node of the Pod model created.  
  1488.  
  1489. For example:
  1490.  
  1491.     =meta module Foo::Bar
  1492.  
  1493.     =meta author Andy Wardley
  1494.  
  1495. You can then access these items via the metadata() method.
  1496.  
  1497.     print "module: ", $pom->metadata('module'), "\n";
  1498.     print "author: ", $pom->metadata('author'), "\n";
  1499.  
  1500. or
  1501.  
  1502.     my $metadata = $pom->metadata();
  1503.     print "module: $metadata->{ module }\n";
  1504.     print "author: $metadata->{ author }\n";
  1505.  
  1506. Please note that this is an experimental feature which is not supported by
  1507. other POD processors and is therefore likely to be most incompatible.  Use
  1508. carefully.
  1509.  
  1510. =head1 AUTHOR
  1511.  
  1512. Andy Wardley E<lt>abw@kfs.orgE<gt>
  1513.  
  1514. =head1 VERSION
  1515.  
  1516. This is version 0.15 of the Pod::POM module.
  1517.  
  1518. =head1 COPYRIGHT
  1519.  
  1520. Copyright (C) 2000-2002 Andy Wardley.  All Rights Reserved.
  1521.  
  1522. This module is free software; you can redistribute it and/or
  1523. modify it under the same terms as Perl itself.
  1524.  
  1525. =head1 SEE ALSO
  1526.  
  1527. For the definitive reference on Pod, see L<perlpod>.
  1528.  
  1529. For an overview of Pod::POM internals and details relating to subclassing
  1530. of POM nodes, see L<Pod::POM::Node>.
  1531.  
  1532. There are numerous other fine Pod modules available from CPAN which
  1533. perform conversion from Pod to other formats.  In many cases these are
  1534. likely to be faster and quite possibly more reliable and/or complete
  1535. than this module.  But as far as I know, there aren't any that offer
  1536. the same kind of flexibility in being able to customise the generated
  1537. output.  But don't take my word for it - see your local CPAN site for
  1538. further details:
  1539.  
  1540.     http://www.cpan.org/modules/by-module/Pod/
  1541.  
  1542.