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