Merge lp:~percona-toolkit-dev/percona-toolkit/fatpack-pod2rst into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.1

Proposed by Brian Fraser
Status: Merged
Merged at revision: 570
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fatpack-pod2rst
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.1
Diff against target: 5861 lines (+5799/-7)
4 files modified
docs/dev/how-to-fatpack-pod2rst (+21/-0)
util/pod2rst-fixed (+0/-2)
util/pod2rst-fixed.packed (+5771/-0)
util/write-user-docs (+7/-5)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fatpack-pod2rst
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Brian Fraser Pending
Review via email: mp+153584@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'docs/dev/how-to-fatpack-pod2rst'
2--- docs/dev/how-to-fatpack-pod2rst 1970-01-01 00:00:00 +0000
3+++ docs/dev/how-to-fatpack-pod2rst 2013-03-15 15:55:33 +0000
4@@ -0,0 +1,21 @@
5+$ cpanm App::FatPacker
6+$ mkdir /tmp/pod2rst
7+$ cp util/pod2rst-fixed /tmp/pod2rst/
8+$ cd /tmp/pod2rst
9+$ mkdir lib
10+$ fatpack trace pod2rst-fixed
11+$ fatpack packlists-for `cat fatpacker.trace` >packlists
12+$ fatpack tree `cat packlists`
13+$ (echo "#!/usr/bin/env perl"; fatpack file; cat pod2rst-fixed) > pod2rst-fixed.packed
14+$ cp pod2rst-fixed.packed ~/percona-toolkit/util/
15+$ cd ~/
16+$ rm -rf /tmp/pod2rst
17+
18+
19+Notes:
20+1. Don't do this from the root of the bzr repo. fatpack tries to be clever
21+ and inlines everything under lib/
22+2. mkdir lib/ is to get around a bug(?) in fatpack
23+3. these two lines are safe to ignore:
24+File /tmp/pod2rst/fatlib/darwin-thread-multi-2level/auto/HTML/Parser/Parser.bs isn't a .pm file - can't pack this and if you hoped we were going to things may not be what you expected later
25+File /tmp/pod2rst/fatlib/darwin-thread-multi-2level/auto/HTML/Parser/Parser.bundle isn't a .pm file - can't pack this and if you hoped we were going to things may not be what you expected later
26
27=== modified file 'util/pod2rst-fixed'
28--- util/pod2rst-fixed 2012-12-06 18:03:54 +0000
29+++ util/pod2rst-fixed 2013-03-15 15:55:33 +0000
30@@ -6,8 +6,6 @@
31
32 use IO::File;
33
34-use HTML::Entities;
35-
36 use File::Basename qw(basename);
37 use Pod::POM::View::Restructured;
38
39
40=== added file 'util/pod2rst-fixed.packed'
41--- util/pod2rst-fixed.packed 1970-01-01 00:00:00 +0000
42+++ util/pod2rst-fixed.packed 2013-03-15 15:55:33 +0000
43@@ -0,0 +1,5771 @@
44+#!/usr/bin/env perl
45+
46+# This chunk of stuff was generated by App::FatPacker. To find the original
47+# file's code, look for the end of this BEGIN block or the string 'FATPACK'
48+BEGIN {
49+my %fatpacked;
50+
51+$fatpacked{"Pod/POM.pm"} = <<'POD_POM';
52+ #============================================================= -*-Perl-*-
53+ #
54+ # Pod::POM
55+ #
56+ # DESCRIPTION
57+ # Parses POD from a file or text string and builds a tree structure,
58+ # hereafter known as the POD Object Model (POM).
59+ #
60+ # AUTHOR
61+ # Andy Wardley <abw@wardley.org>
62+ #
63+ # Andrew Ford <A.Ford@ford-mason.co.uk> (co-maintainer as of 03/2009)
64+ #
65+ # COPYRIGHT
66+ # Copyright (C) 2000-2009 Andy Wardley. All Rights Reserved.
67+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
68+ #
69+ # This module is free software; you can redistribute it and/or
70+ # modify it under the same terms as Perl itself.
71+ #
72+ # REVISION
73+ # $Id: POM.pm 88 2010-04-02 13:37:41Z ford $
74+ #
75+ #========================================================================
76+
77+ package Pod::POM;
78+
79+ require 5.004;
80+
81+ use strict;
82+ use Pod::POM::Constants qw( :all );
83+ use Pod::POM::Nodes;
84+ use Pod::POM::View::Pod;
85+
86+ use vars qw( $VERSION $DEBUG $ERROR $ROOT $TEXTSEQ $DEFAULT_VIEW );
87+ use base qw( Exporter );
88+
89+ $VERSION = '0.27';
90+ $DEBUG = 0 unless defined $DEBUG;
91+ $ROOT = 'Pod::POM::Node::Pod'; # root node class
92+ $TEXTSEQ = 'Pod::POM::Node::Sequence'; # text sequence class
93+ $DEFAULT_VIEW = 'Pod::POM::View::Pod'; # default view class
94+
95+
96+ #------------------------------------------------------------------------
97+ # allow 'meta' to be specified as a load option to activate =meta tags
98+ #------------------------------------------------------------------------
99+
100+ use vars qw( @EXPORT_FAIL @EXPORT_OK $ALLOW_META );
101+ @EXPORT_OK = qw( meta );
102+ @EXPORT_FAIL = qw( meta );
103+ $ALLOW_META = 0;
104+
105+ sub export_fail {
106+ my $class = shift;
107+ my $meta = shift;
108+ return ($meta, @_) unless $meta eq 'meta';
109+ $ALLOW_META++;
110+ return @_;
111+ }
112+
113+
114+
115+ #------------------------------------------------------------------------
116+ # new(\%options)
117+ #------------------------------------------------------------------------
118+
119+ sub new {
120+ my $class = shift;
121+ my $config = ref $_[0] eq 'HASH' ? shift : { @_ };
122+
123+ bless {
124+ CODE => $config->{ code } || 0,
125+ WARN => $config->{ warn } || 0,
126+ META => $config->{ meta } || $ALLOW_META,
127+ WARNINGS => [ ],
128+ FILENAME => '',
129+ ERROR => '',
130+ }, $class;
131+ }
132+
133+
134+ #------------------------------------------------------------------------
135+ # parse($text_or_file)
136+ #
137+ # General purpose parse method which attempts to Do The Right Thing in
138+ # calling parse_file() or parse_text() according to the argument
139+ # passed. A hash reference can be specified that contains a 'text'
140+ # or 'file' key and corresponding value. Otherwise, the argument can
141+ # be a reference to an input handle which is passed off to parse_file().
142+ # If the argument is a text string that contains '=' at the start of
143+ # any line then it is treated as Pod text and passed to parse_text(),
144+ # otherwise it is assumed to be a filename and passed to parse_file().
145+ #------------------------------------------------------------------------
146+
147+ sub parse {
148+ my ($self, $input) = @_;
149+ my $result;
150+
151+ if (ref $input eq 'HASH') {
152+ if ($input = $input->{ text }) {
153+ $result = $self->parse_text($input, $input->{ name });
154+ }
155+ elsif ($input = $input->{ file }) {
156+ $result = $self->parse_file($input);
157+ }
158+ else {
159+ $result = $self->error("no 'text' or 'file' specified");
160+ }
161+ }
162+ elsif (ref $input || $input !~ /^=/m) { # doesn't look like POD text
163+ $result = $self->parse_file($input);
164+ }
165+ else { # looks like POD text
166+ $result = $self->parse_text($input);
167+ }
168+
169+ return $result;
170+ }
171+
172+
173+ #------------------------------------------------------------------------
174+ # parse_file($filename_or_handle)
175+ #
176+ # Reads the content of a Pod file specified by name or file handle, and
177+ # passes it to parse_text() for parsing.
178+ #------------------------------------------------------------------------
179+
180+ sub parse_file {
181+ my ($self, $file) = @_;
182+ my ($text, $name);
183+
184+ if (ref $file) { # assume open filehandle
185+ local $/ = undef;
186+ $name = '<filehandle>';
187+ $text = <$file>;
188+ }
189+ else { # a file which must be opened
190+ local *FP;
191+ local $/ = undef;
192+ $name = ( $file eq '-' ? '<standard input>' : $file );
193+ open(FP, $file) || return $self->error("$file: $!");
194+ $text = <FP>;
195+ close(FP);
196+ }
197+
198+ $self->parse_text($text, $name);
199+ }
200+
201+
202+ #------------------------------------------------------------------------
203+ # parse_text($text, $name)
204+ #
205+ # Main parser method. Scans the input text for Pod sections and splits
206+ # them into paragraphs. Builds a tree of Pod::POM::Node::* objects
207+ # to represent the Pod document in object model form.
208+ #------------------------------------------------------------------------
209+
210+ sub parse_text {
211+ my ($self, $text, $name) = @_;
212+ my ($para, $paralen, $gap, $type, $line, $inpod, $code, $result, $verbatim);
213+ my $warn = $self->{ WARNINGS } = [ ];
214+
215+ my @stack = ( );
216+ my $item = $ROOT->new($self);
217+ return $self->error($ROOT->error())
218+ unless defined $item;
219+ push(@stack, $item);
220+
221+ $name = '<input text>' unless defined $name;
222+ $self->{ FILENAME } = $name;
223+
224+ $code = $self->{ CODE };
225+ $line = \$self->{ LINE };
226+ $$line = 1;
227+ $inpod = 0;
228+
229+ my @encchunks = split /^(=encoding.*)/m, $text;
230+ $text = shift @encchunks;
231+ while (@encchunks) {
232+ my($encline,$chunk) = splice @encchunks, 0, 2;
233+ require Encode;
234+ my($encoding) = $encline =~ /^=encoding\s+(\S+)/;
235+ Encode::from_to($chunk, $encoding, "utf8");
236+ Encode::_utf8_on($chunk);
237+ # $text .= "xxx$encline";
238+ $text .= $chunk;
239+ }
240+
241+ # patch from JJ
242+ # while ($text =~ /(?:(.*?)(\n{2,}))|(.+$)/sg) {
243+ while ($text =~ /(?:(.*?)((?:\s*\n){2,}))|(.+$)/sg) {
244+ ($para, $gap) = defined $1 ? ($1, $2) : ($3, '');
245+
246+ if ($para =~ s/^==?(\w+)\s*//) {
247+ $type = $1;
248+ # switch on for =pod or any other =cmd, switch off for =cut
249+ if ($type eq 'pod') { $inpod = 1; next }
250+ elsif ($type eq 'cut') { $inpod = 0; next }
251+ else { $inpod = 1 };
252+
253+ if ($type eq 'meta') {
254+ $self->{ META }
255+ ? $stack[0]->metadata(split(/\s+/, $para, 2))
256+ : $self->warning("metadata not allowed", $name, $$line);
257+ next;
258+ }
259+ }
260+ elsif (! $inpod) {
261+ next unless $code;
262+ $type = 'code';
263+ $para .= $gap;
264+ $gap = '';
265+ }
266+ elsif ($para =~ /^\s+/) {
267+ $verbatim .= $para;
268+ $verbatim .= $gap;
269+ next;
270+ }
271+ else {
272+ $type = 'text';
273+ chomp($para); # catches last line in file
274+ }
275+
276+ if ($verbatim) {
277+ while(@stack) {
278+ $verbatim =~ s/\s+$//s;
279+ $result = $stack[-1]->add($self, 'verbatim', $verbatim);
280+
281+ if (! defined $result) {
282+ $self->warning($stack[-1]->error(), $name, $$line);
283+ undef $verbatim;
284+ last;
285+ }
286+ elsif (ref $result) {
287+ push(@stack, $result);
288+ undef $verbatim;
289+ last;
290+ }
291+ elsif ($result == REDUCE) {
292+ pop @stack;
293+ undef $verbatim;
294+ last;
295+ }
296+ elsif ($result == REJECT) {
297+ $self->warning($stack[-1]->error(), $name, $$line);
298+ pop @stack;
299+ }
300+ elsif (@stack == 1) {
301+ $self->warning("unexpected $type", $name, $$line);
302+ undef $verbatim;
303+ last;
304+ }
305+ else {
306+ pop @stack;
307+ }
308+ }
309+ }
310+
311+ while(@stack) {
312+ $result = $stack[-1]->add($self, $type, $para);
313+
314+ if (! defined $result) {
315+ $self->warning($stack[-1]->error(), $name, $$line);
316+ last;
317+ }
318+ elsif (ref $result) {
319+ push(@stack, $result);
320+ last;
321+ }
322+ elsif ($result == REDUCE) {
323+ pop @stack;
324+ last;
325+ }
326+ elsif ($result == REJECT) {
327+ $self->warning($stack[-1]->error(), $name, $$line);
328+ pop @stack;
329+ }
330+ elsif (@stack == 1) {
331+ $self->warning("unexpected $type", $name, $$line);
332+ last;
333+ }
334+ else {
335+ pop @stack;
336+ }
337+ }
338+ }
339+ continue {
340+ $$line += ($para =~ tr/\n//);
341+ $$line += ($gap =~ tr/\n//);
342+ }
343+
344+ if ($verbatim) {
345+ while(@stack) {
346+ $verbatim =~ s/\s+$//s;
347+ $result = $stack[-1]->add($self, 'verbatim', $verbatim);
348+
349+ if (! defined $result) {
350+ $self->warning($stack[-1]->error(), $name, $$line);
351+ undef $verbatim;
352+ last;
353+ }
354+ elsif (ref $result) {
355+ push(@stack, $result);
356+ undef $verbatim;
357+ last;
358+ }
359+ elsif ($result == REDUCE) {
360+ pop @stack;
361+ undef $verbatim;
362+ last;
363+ }
364+ elsif ($result == REJECT) {
365+ $self->warning($stack[-1]->error(), $name, $$line);
366+ pop @stack;
367+ }
368+ elsif (@stack == 1) {
369+ $self->warning("unexpected $type", $name, $$line);
370+ undef $verbatim;
371+ last;
372+ }
373+ else {
374+ pop @stack;
375+ }
376+ }
377+ }
378+
379+ return $stack[0];
380+ }
381+
382+
383+ #------------------------------------------------------------------------
384+ # parse_sequence($text)
385+ #
386+ # Parse a text paragraph to identify internal sequences (e.g. B<foo>)
387+ # which may be nested within each other. Returns a simple scalar (no
388+ # embedded sequences) or a reference to a Pod::POM::Text object.
389+ #------------------------------------------------------------------------
390+
391+ sub parse_sequence {
392+ my ($self, $text) = @_;
393+ my ($cmd, $lparen, $rparen, $plain);
394+ my ($name, $line, $warn) = @$self{ qw( FILENAME LINE WARNINGS ) };
395+ my @stack;
396+
397+ push(@stack, [ '', '', 'EOF', $name, $line, [ ] ] );
398+
399+ while ($text =~ /
400+ (?: ([A-Z]) (< (?:<+\s)?) ) # open
401+ | ( (?:\s>+)? > ) # or close
402+ | (?: (.+?) # or text...
403+ (?= # ...up to
404+ (?: [A-Z]< ) # open
405+ | (?: (?: \s>+)? > ) # or close
406+ | $ # or EOF
407+ )
408+ )
409+ /gxs) {
410+ if (defined $1) {
411+ ($cmd, $lparen) = ($1, $2);
412+ $lparen =~ s/\s$//;
413+ ($rparen = $lparen) =~ tr/</>/;
414+ push(@stack, [ $cmd, $lparen, $rparen, $name, $line, [ ] ]);
415+ }
416+ elsif (defined $3) {
417+ $rparen = $3;
418+ $rparen =~ s/^\s+//;
419+ if ($rparen eq $stack[-1]->[RPAREN]) {
420+ $cmd = $TEXTSEQ->new(pop(@stack))
421+ || return $self->error($TEXTSEQ->error());
422+ push(@{ $stack[-1]->[CONTENT] }, $cmd);
423+ }
424+ else {
425+ $self->warning((scalar @stack > 1
426+ ? "expected '$stack[-1]->[RPAREN]' not '$rparen'"
427+ : "spurious '$rparen'"), $name, $line);
428+ push(@{ $stack[-1]->[CONTENT] }, $rparen);
429+ }
430+ }
431+ elsif (defined $4) {
432+ $plain = $4;
433+ push(@{ $stack[-1]->[CONTENT] }, $plain);
434+ $line += ($plain =~ tr/\n//);
435+ }
436+ else {
437+ $self->warning("unexpected end of input", $name, $line);
438+ last;
439+ }
440+ }
441+
442+ while (@stack > 1) {
443+ $cmd = pop @stack;
444+ $self->warning("unterminated '$cmd->[CMD]$cmd->[LPAREN]' starting",
445+ $name, $cmd->[LINE]);
446+ $cmd = $TEXTSEQ->new($cmd)
447+ || $self->error($TEXTSEQ->error());
448+ push(@{ $stack[-1]->[CONTENT] }, $cmd);
449+ }
450+
451+ return $TEXTSEQ->new(pop(@stack))
452+ || $self->error($TEXTSEQ->error());
453+ }
454+
455+
456+ #------------------------------------------------------------------------
457+ # default_view($viewer)
458+ #
459+ # Accessor method to return or update the $DEFVIEW package variable,
460+ # loading the module for any package name specified.
461+ #------------------------------------------------------------------------
462+
463+ sub default_view {
464+ my ($self, $viewer) = @_;
465+ return $DEFAULT_VIEW unless $viewer;
466+ unless (ref $viewer) {
467+ my $file = $viewer;
468+ $file =~ s[::][/]g;
469+ $file .= '.pm';
470+ eval { require $file };
471+ return $self->error($@) if $@;
472+ }
473+
474+ return ($DEFAULT_VIEW = $viewer);
475+ }
476+
477+
478+ #------------------------------------------------------------------------
479+ # warning($msg, $file, $line)
480+ #
481+ # Appends a string of the form " at $file line $line" to $msg if
482+ # $file is specified and then stores $msg in the internals
483+ # WARNINGS list. If the WARN option is set then the warning is
484+ # raised, either via warn(), or by dispatching to a subroutine
485+ # when WARN is defined as such.
486+ #------------------------------------------------------------------------
487+
488+ sub warning {
489+ my ($self, $msg, $file, $line) = @_;
490+ my $warn = $self->{ WARN };
491+ $line = 'unknown' unless defined $line && length $line;
492+ $msg .= " at $file line $line" if $file;
493+
494+ push(@{ $self->{ WARNINGS } }, $msg);
495+
496+ if (ref $warn eq 'CODE') {
497+ &$warn($msg);
498+ }
499+ elsif ($warn) {
500+ warn($msg, "\n");
501+ }
502+ }
503+
504+
505+ #------------------------------------------------------------------------
506+ # warnings()
507+ #
508+ # Returns a reference to the (possibly empty) list of warnings raised by
509+ # the most recent call to any of the parse_XXX() methods
510+ #------------------------------------------------------------------------
511+
512+ sub warnings {
513+ my $self = shift;
514+ return wantarray ? @{ $self->{ WARNINGS } } : $self->{ WARNINGS };
515+ }
516+
517+
518+ #------------------------------------------------------------------------
519+ # error($msg)
520+ #
521+ # Sets the internal ERROR member and returns undef when called with an
522+ # argument(s), returns the current value when called without.
523+ #------------------------------------------------------------------------
524+
525+ sub error {
526+ my $self = shift;
527+ my $errvar;
528+
529+ {
530+ no strict qw( refs );
531+ if (ref $self) {
532+ $errvar = \$self->{ ERROR };
533+ }
534+ else {
535+ $errvar = \${"$self\::ERROR"};
536+ }
537+ }
538+ if (@_) {
539+ $$errvar = ref($_[0]) ? shift : join('', @_);
540+ return undef;
541+ }
542+ else {
543+ return $$errvar;
544+ }
545+ }
546+
547+
548+
549+ sub DEBUG {
550+ print STDERR "DEBUG: ", @_ if $DEBUG;
551+ }
552+
553+ 1;
554+
555+ __END__
556+
557+ =head1 NAME
558+
559+ Pod::POM - POD Object Model
560+
561+ =head1 SYNOPSIS
562+
563+ use Pod::POM;
564+
565+ my $parser = Pod::POM->new(\%options);
566+
567+ # parse from a text string
568+ my $pom = $parser->parse_text($text)
569+ || die $parser->error();
570+
571+ # parse from a file specified by name or filehandle
572+ my $pom = $parser->parse_file($file)
573+ || die $parser->error();
574+
575+ # parse from text or file
576+ my $pom = $parser->parse($text_or_file)
577+ || die $parser->error();
578+
579+ # examine any warnings raised
580+ foreach my $warning ($parser->warnings()) {
581+ warn $warning, "\n";
582+ }
583+
584+ # print table of contents using each =head1 title
585+ foreach my $head1 ($pom->head1()) {
586+ print $head1->title(), "\n";
587+ }
588+
589+ # print each section
590+ foreach my $head1 ($pom->head1()) {
591+ print $head1->title(), "\n";
592+ print $head1->content();
593+ }
594+
595+ # print the entire document as HTML
596+ use Pod::POM::View::HTML;
597+ print Pod::POM::View::HTML->print($pom);
598+
599+ # create custom view
600+ package My::View;
601+ use base qw( Pod::POM::View::HTML );
602+
603+ sub view_head1 {
604+ my ($self, $item) = @_;
605+ return '<h1>',
606+ $item->title->present($self),
607+ "</h1>\n",
608+ $item->content->present($self);
609+ }
610+
611+ package main;
612+ print My::View->print($pom);
613+
614+ =head1 DESCRIPTION
615+
616+ This module implements a parser to convert Pod documents into a simple
617+ object model form known hereafter as the Pod Object Model. The object
618+ model is generated as a hierarchical tree of nodes, each of which
619+ represents a different element of the original document. The tree can
620+ be walked manually and the nodes examined, printed or otherwise
621+ manipulated. In addition, Pod::POM supports and provides view objects
622+ which can automatically traverse the tree, or section thereof, and
623+ generate an output representation in one form or another.
624+
625+ Let's look at a typical Pod document by way of example.
626+
627+ =head1 NAME
628+
629+ My::Module - just another My::Module
630+
631+ =head1 DESCRIPTION
632+
633+ This is My::Module, a deeply funky piece of Perl code.
634+
635+ =head2 METHODS
636+
637+ My::Module implements the following methods
638+
639+ =over 4
640+
641+ =item new(\%config)
642+
643+ This is the constructor method. It accepts the following
644+ configuration options:
645+
646+ =over 4
647+
648+ =item name
649+
650+ The name of the thingy.
651+
652+ =item colour
653+
654+ The colour of the thingy.
655+
656+ =back
657+
658+ =item print()
659+
660+ This prints the thingy.
661+
662+ =back
663+
664+ =head1 AUTHOR
665+
666+ My::Module was written by me E<lt>me@here.orgE<gt>
667+
668+ This document contains 3 main sections, NAME, DESCRIPTION and
669+ AUTHOR, each of which is delimited by an opening C<=head1> tag.
670+ NAME and AUTHOR each contain only a single line of text, but
671+ DESCRIPTION is more interesting. It contains a line of text
672+ followed by the C<=head2> subsection, METHODS. This contains
673+ a line of text and a list extending from the C<=over 4> to the
674+ final C<=back> just before the AUTHOR section starts. The list
675+ contains 2 items, C<new(\%config)>, which itself contains some
676+ text and a list of 2 items, and C<print()>.
677+
678+ Presented as plain text and using indentation to indicate the element
679+ nesting, the model then looks something like this :
680+
681+ NAME
682+ My::Module - just another My::Module
683+
684+ DESCRIPTION
685+ This is My::Module, a deeply funky piece of Perl code.
686+
687+ METHODS
688+ My::Module implements the following methods
689+
690+ * new(\%config)
691+ This is the constructor method. It accepts the
692+ following configuration options:
693+
694+ * name
695+ The name of the thingy.
696+
697+ * colour
698+ The colour of the thingy.
699+
700+ * item print()
701+ This prints the thingy.
702+
703+ AUTHOR
704+ My::Myodule was written by me <me@here.org>
705+
706+ Those of you familiar with XML may prefer to think of it in the
707+ following way:
708+
709+ <pod>
710+ <head1 title="NAME">
711+ <p>My::Module - just another My::Module</p>
712+ </head1>
713+
714+ <head1 title="DESCRIPTION">
715+ <p>This is My::Module, a deeply funky piece of
716+ Perl code.</p>
717+
718+ <head2 title="METHODS">
719+ <p>My::Module implements the following methods</p>
720+
721+ <over indent=4>
722+ <item title="item new(\%config)">
723+ <p>This is the constructor method. It accepts
724+ the following configuration options:</p>
725+
726+ <over indent=4>
727+ <item title="name">
728+ <p>The name of the thingy.</p>
729+ </item>
730+
731+ <item title="colour">
732+ <p>The colour of the thingy.</p>
733+ </item>
734+ </over>
735+ </item>
736+
737+ <item title="print()">
738+ <p>This prints the thingy.</p>
739+ </item>
740+ </over>
741+ </head2>
742+ </head1>
743+
744+ <head1 title="AUTHOR">
745+ <p>My::Myodule was written by me &lt;me@here.org&gt;
746+ </head1>
747+ </pod>
748+
749+ Notice how we can make certain assumptions about various elements.
750+ For example, we can assume that any C<=head1> section we find begins a
751+ new section and implicitly ends any previous section. Similarly, we
752+ can assume an C<=item> ends when the next one begins, and so on. In
753+ terms of the XML example shown above, we are saying that we're smart
754+ enough to add a C<E<lt>/head1E<gt>> element to terminate any
755+ previously opened C<E<lt>head1E<gt>> when we find a new C<=head1> tag
756+ in the input document.
757+
758+ However you like to visualise the content, it all comes down to the
759+ same underlying model. The job of the Pod::POM module is to read an
760+ input Pod document and build an object model to represent it in this
761+ structured form.
762+
763+ Each node in the tree (i.e. element in the document) is represented
764+ by a Pod::POM::Node::* object. These encapsulate the attributes for
765+ an element (such as the title for a C<=head1> tag) and also act as
766+ containers for further Pod::POM::Node::* objects representing the
767+ content of the element. Right down at the leaf nodes, we have simple
768+ object types to represent formatted and verbatim text paragraphs and
769+ other basic elements like these.
770+
771+ =head2 Parsing Pod
772+
773+ The Pod::POM module implements the methods parse_file($file),
774+ parse_text($text) and parse($file_or_text) to parse Pod files and
775+ input text. They return a Pod::POM::Node::Pod object to represent the
776+ root of the Pod Object Model, effectively the C<E<lt>podE<gt>> element
777+ in the XML tree shown above.
778+
779+ use Pod::POM;
780+
781+ my $parser = Pod::POM->new();
782+ my $pom = $parser->parse_file($filename)
783+ || die $parser->error();
784+
785+ The parse(), parse_text() and parse_file() methods return
786+ undef on error. The error() method can be called to retrieve the
787+ error message generated. Parsing a document may also generate
788+ non-fatal warnings. These can be retrieved via the warnings() method
789+ which returns a reference to a list when called in scalar context or a
790+ list of warnings when called in list context.
791+
792+ foreach my $warn ($parser->warnings()) {
793+ warn $warn, "\n";
794+ }
795+
796+ Alternatively, the 'warn' configuration option can be set to have
797+ warnings automatically raised via C<warn()> as they are encountered.
798+
799+ my $parser = Pod::POM->new( warn => 1 );
800+
801+ =head2 Walking the Object Model
802+
803+ Having parsed a document into an object model, we can then select
804+ various items from it. Each node implements methods (via AUTOLOAD)
805+ which correspond to the attributes and content elements permitted
806+ within in.
807+
808+ So to fetch the list of '=head1' sections within our parsed document,
809+ we would do the following:
810+
811+ my $sections = $pom->head1();
812+
813+ Methods like this will return a list of further Pod::POM::Node::*
814+ objects when called in list context or a reference to a list when
815+ called in scalar context. In the latter case, the list is blessed
816+ into the Pod::POM::Node::Content class which gives it certain
817+ magical properties (more on that later).
818+
819+ Given the list of Pod::POM::Node::Head1 objects returned by the above,
820+ we can print the title attributes of each like this:
821+
822+ foreach my $s (@$sections) {
823+ print $s->title();
824+ }
825+
826+ Let's look at the second section, DESCRIPTION.
827+
828+ my $desc = $sections->[1];
829+
830+ We can print the title of each subsection within it:
831+
832+ foreach my $ss ($desc->head2()) {
833+ print $ss->title();
834+ }
835+
836+ Hopefully you're getting the idea by now, so here's a more studly
837+ example to print the title for each item contained in the first list
838+ within the METHODS section:
839+
840+ foreach my $item ($desc->head2->[0]->over->[0]->item) {
841+ print $item->title(), "\n";
842+ }
843+
844+ =head2 Element Content
845+
846+ This is all well and good if you know the precise structure of a
847+ document in advance. For those more common cases when you don't,
848+ each node that can contain other nodes provides a 'content' method
849+ to return a complete list of all the other nodes that it contains.
850+ The 'type' method can be called on any node to return its element
851+ type (e.g. 'head1', 'head2', 'over', item', etc).
852+
853+ foreach my $item ($pom->content()) {
854+ my $type = $item->type();
855+ if ($type eq 'head1') {
856+ ...
857+ }
858+ elsif ($type eq 'head2') {
859+ ...
860+ }
861+ ...
862+ }
863+
864+ The content for an element is represented by a reference to a list,
865+ blessed into the Pod::POM::Node::Content class. This provides some
866+ magic in the form of an overloaded stringification operator which
867+ will automatically print the contents of the list if you print
868+ the object itself. In plain English, or rather, in plain Perl,
869+ this means you can do things like the following:
870+
871+ foreach my $head1 ($pom->head1()) {
872+ print '<h1>', $head1->title(), "</h1>\n\n";
873+ print $head1->content();
874+ }
875+
876+ # print all the root content
877+ foreach my $item ($pom->content()) {
878+ print $item;
879+ }
880+
881+ # same as above
882+ print $pom->content();
883+
884+ In fact, all Pod::POM::Node::* objects provide this same magic, and
885+ will attempt to Do The Right Thing to present themselves in the
886+ appropriate manner when printed. Thus, the following are all valid.
887+
888+ print $pom; # entire document
889+ print $pom->content; # content of document
890+ print $pom->head1->[0]; # just first section
891+ print $pom->head1; # print all sections
892+ foreach my $h1 ($pom->head1()) {
893+ print $h1->head2(); # print all subsections
894+ }
895+
896+ =head2 Output Views
897+
898+ To understand how the different elements go about presenting
899+ themselves in "the appropriate manner", we must introduce the concept
900+ of a view. A view is quite simply a particular way of looking at the
901+ model. In real terms, we can think of a view as being some kind of
902+ output type generated by a pod2whatever converter. Notionally we can
903+ think in terms of reading in an input document, building a Pod Object
904+ Model, and then generating an HTML view of the document, and/or a
905+ LaTeX view, a plain text view, and so on.
906+
907+ A view is represented in this case by an object class which contains
908+ methods for displaying each of the different element types that could
909+ be encountered in any Pod document. There's a method for displaying
910+ C<=head1> sections (view_head1()), another method for displaying
911+ C<=head2> sections (view_head2()), one for C<=over> (view_over()),
912+ another for C<=item> (view_item()) and so on.
913+
914+ If we happen to have a reference to a $node and we know it's a 'head1'
915+ node, then we can directly call the right view method to have it
916+ displayed properly:
917+
918+ $view = 'Pod::POM::View::HTML';
919+ $view->view_head1($node);
920+
921+ Thus our earlier example can be modified to be I<slightly> less laborious
922+ and I<marginally> more flexible.
923+
924+ foreach my $node ($pom->content) {
925+ my $type = $node->type();
926+ if ($type eq 'head1') {
927+ print $view->view_head1($node);
928+ }
929+ elsif ($type eq 'head2') {
930+ print $view->view_head2($node);
931+ }
932+ ...
933+ }
934+
935+ However, this is still far from ideal. To make life easier, each
936+ Pod::POM::Node::* class inherits (or possibly redefines) a
937+ C<present($view)> method from the Pod::POM::Node base class. This method
938+ expects a reference to a view object passed as an argument, and it
939+ simply calls the appropriate view_xxx() method on the view object,
940+ passing itself back as an argument. In object parlance, this is known
941+ as "double dispatch". The beauty of it is that you don't need to know
942+ what kind of node you have to be able to print it. You simply pass
943+ it a view object and leave it to work out the rest.
944+
945+ foreach my $node ($pom->content) {
946+ print $node->present($view);
947+ }
948+
949+ If $node is a Pod::POM::Node::Head1 object, then the view_head1($node)
950+ method gets called against the $view object. Otherwise, if it's a
951+ Pod::POM::Node::Head2 object, then the view_head2($node) method is
952+ dispatched. And so on, and so on, with each node knowing what it is
953+ and where it's going as if determined by some genetically pre-programmed
954+ instinct. Fullfilling their destinies, so to speak.
955+
956+ Double dispatch allows us to do away with all the explicit type
957+ checking and other nonsense and have the node objects themselves worry
958+ about where they should be routed to. At the cost of an extra method
959+ call per node, we get programmer convenience, and that's usually
960+ a Good Thing.
961+
962+ Let's have a look at how the view and node classes might be
963+ implemented.
964+
965+ package Pod::POM::View::HTML;
966+
967+ sub view_pod {
968+ my ($self, $node) = @_;
969+ return $node->content->present($self);
970+ }
971+
972+ sub view_head1 {
973+ my ($self, $node) = @_;
974+ return "<h1>", $node->title->present($self), "</h1>\n\n"
975+ . $node->content->present($self);
976+ }
977+
978+ sub view_head2 {
979+ my ($self, $node) = @_;
980+ return "<h2>", $node->title->present($self), "</h2>\n\n"
981+ . $node->content->present($self);
982+ }
983+
984+ ...
985+
986+ package Pod::POM::Node::Pod;
987+
988+ sub present {
989+ my ($self, $view) = @_;
990+ $view->view_pod($self);
991+ }
992+
993+ package Pod::POM::Node::Head1;
994+
995+ sub present {
996+ my ($self, $view) = @_;
997+ $view->view_head1($self);
998+ }
999+
1000+ package Pod::POM::Node::Head2;
1001+
1002+ sub present {
1003+ my ($self, $view) = @_;
1004+ $view->view_head2($self);
1005+ }
1006+
1007+ ...
1008+
1009+ Some of the view_xxx methods make calls back against the node objects
1010+ to display their attributes and/or content. This is shown in, for
1011+ example, the view_head1() method above, where the method prints the
1012+ section title in C<E<lt>h1E<gt>>...C<E<lt>h1E<gt>> tags, followed by
1013+ the remaining section content.
1014+
1015+ Note that the title() attribute is printed by calling its present()
1016+ method, passing on the reference to the current view. Similarly,
1017+ the content present() method is called giving it a chance to Do
1018+ The Right Thing to present itself correctly via the view object.
1019+
1020+ There's a good chance that the title attribute is going to be regular
1021+ text, so we might be tempted to simply print the title rather than
1022+ call its present method.
1023+
1024+ sub view_head1 {
1025+ my ($self, $node) = @_;
1026+ # not recommended, prefer $node->title->present($self)
1027+ return "<h1>", $node->title(), "</h1>\n\n", ...
1028+ }
1029+
1030+ However, it is entirely valid for titles and other element attributes,
1031+ as well as regular, formatted text blocks to contain code sequences,
1032+ such like C<BE<lt>thisE<gt>> and C<IE<lt>thisE<gt>>. These are used
1033+ to indicate different markup styles, mark external references or index
1034+ items, and so on. What's more, they can be C<BE<lt>nested
1035+ IE<lt>indefinatelyE<gt>E<gt>>. Pod::POM takes care of all this by
1036+ parsing such text, along with any embedded sequences, into Yet Another
1037+ Tree, the root node of which is a Pod::POM::Node::Text object,
1038+ possibly containing other Pod::POM::Node::Sequence objects. When the
1039+ text is presented, the tree is automatically walked and relevant
1040+ callbacks made against the view for the different sequence types. The
1041+ methods called against the view are all prefixed 'view_seq_', e.g.
1042+ 'view_seq_bold', 'view_seq_italic'.
1043+
1044+ Now the real magic comes into effect. You can define one view to
1045+ render bold/italic text in one style:
1046+
1047+ package My::View::Text;
1048+ use base qw( Pod::POM::View::Text );
1049+
1050+ sub view_seq_bold {
1051+ my ($self, $text) = @_;
1052+ return "*$text*";
1053+ }
1054+
1055+ sub view_seq_italic {
1056+ my ($self, $text) = @_;
1057+ return "_$text_";
1058+ }
1059+
1060+ And another view to render it in a different style:
1061+
1062+ package My::View::HTML;
1063+ use base qw( Pod::POM::View::HTML );
1064+
1065+ sub view_seq_bold {
1066+ my ($self, $text) = @_;
1067+ return "<b>$text</b>";
1068+ }
1069+
1070+ sub view_seq_italic {
1071+ my ($self, $text) = @_;
1072+ return "<i>$text</i>";
1073+ }
1074+
1075+ Then, you can easily view a Pod Object Model in either style:
1076+
1077+ my $text = 'My::View::Text';
1078+ my $html = 'My::View::HTML';
1079+
1080+ print $pom->present($text);
1081+ print $pom->present($html);
1082+
1083+ And you can apply this technique to any node within the object
1084+ model.
1085+
1086+ print $pom->head1->[0]->present($text);
1087+ print $pom->head1->[0]->present($html);
1088+
1089+ In these examples, the view passed to the present() method has
1090+ been a class name. Thus, the view_xxx methods get called as
1091+ class methods, as if written:
1092+
1093+ My::View::Text->view_head1(...);
1094+
1095+ If your view needs to maintain state then you can create a view object
1096+ and pass that to the present() method.
1097+
1098+ my $view = My::View->new();
1099+ $node->present($view);
1100+
1101+ In this case the view_xxx methods get called as object methods.
1102+
1103+ sub view_head1 {
1104+ my ($self, $node) = @_;
1105+ my $title = $node->title();
1106+ if ($title eq 'NAME' && ref $self) {
1107+ $self->{ title } = $title();
1108+ }
1109+ $self->SUPER::view_head1($node);
1110+ }
1111+
1112+ Whenever you print a Pod::POM::Node::* object, or do anything to cause
1113+ Perl to stringify it (such as including it another quoted string "like
1114+ $this"), then its present() method is automatically called. When
1115+ called without a view argument, the present() method uses the default
1116+ view specified in $Pod::POM::DEFAULT_VIEW, which is, by default,
1117+ 'Pod::POM::View::Pod'. This view regenerates the original Pod
1118+ document, although it should be noted that the output generated may
1119+ not be exactly the same as the input. The parser is smart enough to
1120+ detect some common errors (e.g. not terminating an C<=over> with a C<=back>)
1121+ and correct them automatically. Thus you might find a C<=back>
1122+ correctly placed in the output, even if you forgot to add it to the
1123+ input. Such corrections raise non-fatal warnings which can later
1124+ be examined via the warnings() method.
1125+
1126+ You can update the $Pod::POM::DEFAULT_VIEW package variable to set the
1127+ default view, or call the default_view() method. The default_view()
1128+ method will automatically load any package you specify. If setting
1129+ the package variable directly, you should ensure that any packages
1130+ required have been pre-loaded.
1131+
1132+ use My::View::HTML;
1133+ $Pod::POM::DEFAULT_VIEW = 'My::View::HTML';
1134+
1135+ or
1136+
1137+ Pod::POM->default_view('My::View::HTML');
1138+
1139+ =head2 Template Toolkit Views
1140+
1141+ One of the motivations for writing this module was to make it easier
1142+ to customise Pod documentation to your own look and feel or local
1143+ formatting conventions. By clearly separating the content
1144+ (represented by the Pod Object Model) from the presentation style
1145+ (represented by one or more views) it becomes much easier to achieve
1146+ this.
1147+
1148+ The latest version of the Template Toolkit (2.06 at the time of
1149+ writing) provides a Pod plugin to interface to this module. It also
1150+ implements a new (but experimental) VIEW directive which can be used
1151+ to build different presentation styles for converting Pod to other
1152+ formats. The Template Toolkit is available from CPAN:
1153+
1154+ http://www.cpan.org/modules/by-module/Template/
1155+
1156+ Template Toolkit views are similar to the Pod::POM::View objects
1157+ described above, except that they allow the presentation style for
1158+ each Pod component to be written as a template file or block rather
1159+ than an object method. The precise syntax and structure of the VIEW
1160+ directive is subject to change (given that it's still experimental),
1161+ but at present it can be used to define a view something like this:
1162+
1163+ [% VIEW myview %]
1164+
1165+ [% BLOCK view_head1 %]
1166+ <h1>[% item.title.present(view) %]</h1>
1167+ [% item.content.present(view) %]
1168+ [% END %]
1169+
1170+ [% BLOCK view_head2 %]
1171+ <h2>[% item.title.present(view) %]</h2>
1172+ [% item.content.present(view) %]
1173+ [% END %]
1174+
1175+ ...
1176+
1177+ [% END %]
1178+
1179+ A plugin is provided to interface to the Pod::POM module:
1180+
1181+ [% USE pod %]
1182+ [% pom = pod.parse('/path/to/podfile') %]
1183+
1184+ The returned Pod Object Model instance can then be navigated and
1185+ presented via the view in almost any way imaginable:
1186+
1187+ <h1>Table of Contents</h1>
1188+ <ul>
1189+ [% FOREACH section = pom.head1 %]
1190+ <li>[% section.title.present(view) %]
1191+ [% END %]
1192+ </ul>
1193+
1194+ <hr>
1195+
1196+ [% FOREACH section = pom.head1 %]
1197+ [% section.present(myview) %]
1198+ [% END %]
1199+
1200+ You can either pass a reference to the VIEW (myview) to the
1201+ present() method of a Pod::POM node:
1202+
1203+ [% pom.present(myview) %] # present entire document
1204+
1205+ Or alternately call the print() method on the VIEW, passing the
1206+ Pod::POM node as an argument:
1207+
1208+ [% myview.print(pom) %]
1209+
1210+ Internally, the view calls the present() method on the node,
1211+ passing itself as an argument. Thus it is equivalent to the
1212+ previous example.
1213+
1214+ The Pod::POM node and the view conspire to "Do The Right Thing" to
1215+ process the right template block for the node. A reference to the
1216+ node is available within the template as the 'item' variable.
1217+
1218+ [% BLOCK view_head2 %]
1219+ <h2>[% item.title.present(view) %]</h2>
1220+ [% item.content.present(view) %]
1221+ [% END %]
1222+
1223+ The Template Toolkit documentation contains further information on
1224+ defining and using views. However, as noted above, this may be
1225+ subject to change or incomplete pending further development of the
1226+ VIEW directive.
1227+
1228+ =head1 METHODS
1229+
1230+ =head2 new(\%config)
1231+
1232+ Constructor method which instantiates and returns a new Pod::POM
1233+ parser object.
1234+
1235+ use Pod::POM;
1236+
1237+ my $parser = Pod::POM->new();
1238+
1239+ A reference to a hash array of configuration options may be passed as
1240+ an argument.
1241+
1242+ my $parser = Pod::POM->new( { warn => 1 } );
1243+
1244+ For convenience, configuration options can also be passed as a list of
1245+ (key =E<gt> value) pairs.
1246+
1247+ my $parser = Pod::POM->new( warn => 1 );
1248+
1249+ The following configuration options are defined:
1250+
1251+ =over 4
1252+
1253+ =item code
1254+
1255+ This option can be set to have all non-Pod parts of the input document
1256+ stored within the object model as 'code' elements, represented by
1257+ objects of the Pod::POM::Node::Code class. It is disabled by default
1258+ and code sections are ignored.
1259+
1260+ my $parser = Pod::POM->new( code => 1 );
1261+ my $podpom = $parser->parse(\*DATA);
1262+
1263+ foreach my $code ($podpom->code()) {
1264+ print "<pre>$code</pre>\n";
1265+ }
1266+
1267+ __DATA__
1268+ This is some program code.
1269+
1270+ =head1 NAME
1271+
1272+ ...
1273+
1274+ This will generate the output:
1275+
1276+ <pre>This is some program code.</pre>
1277+
1278+ Note that code elements are stored within the POM element in which
1279+ they are encountered. For example, the code element below embedded
1280+ within between Pod sections is stored in the array which can be
1281+ retrieved by calling C<$podpom-E<gt>head1-E<gt>[0]-E<gt>code()>.
1282+
1283+ =head1 NAME
1284+
1285+ My::Module::Name;
1286+
1287+ =cut
1288+
1289+ Some program code embedded in Pod.
1290+
1291+ =head1 SYNOPSIS
1292+
1293+ ...
1294+
1295+ =item warn
1296+
1297+ Non-fatal warnings encountered while parsing a Pod document are stored
1298+ internally and subsequently available via the warnings() method.
1299+
1300+ my $parser = Pod::POM->new();
1301+ my $podpom = $parser->parse_file($filename);
1302+
1303+ foreach my $warning ($parser->warnings()) {
1304+ warn $warning, "\n";
1305+ }
1306+
1307+ The 'warn' option can be set to have warnings raised automatically
1308+ via C<warn()> as and when they are encountered.
1309+
1310+ my $parser = Pod::POM->new( warn => 1 );
1311+ my $podpom = $parser->parse_file($filename);
1312+
1313+ If the configuration value is specified as a subroutine reference then
1314+ the code will be called each time a warning is raised, passing the
1315+ warning message as an argument.
1316+
1317+ sub my_warning {
1318+ my $msg = shift;
1319+ warn $msg, "\n";
1320+ };
1321+
1322+ my $parser = Pod::POM->new( warn => \&my_warning );
1323+ my $podpom = $parser->parse_file($filename);
1324+
1325+ =item meta
1326+
1327+ The 'meta' option can be set to allow C<=meta> tags within the Pod
1328+ document.
1329+
1330+ my $parser = Pod::POM->new( meta => 1 );
1331+ my $podpom = $parser->parse_file($filename);
1332+
1333+ This is an experimental feature which is not part of standard
1334+ POD. For example:
1335+
1336+ =meta author Andy Wardley
1337+
1338+ These are made available as metadata items within the root
1339+ node of the parsed POM.
1340+
1341+ my $author = $podpom->metadata('author');
1342+
1343+ See the L<METADATA|METADATA> section below for further information.
1344+
1345+ =back
1346+
1347+ =head2 parse_file($file)
1348+
1349+ Parses the file specified by name or reference to a file handle.
1350+ Returns a reference to a Pod::POM::Node::Pod object which represents
1351+ the root node of the Pod Object Model on success. On error, undef
1352+ is returned and the error message generated can be retrieved by calling
1353+ error().
1354+
1355+ my $podpom = $parser->parse_file($filename)
1356+ || die $parser->error();
1357+
1358+ my $podpom = $parser->parse_file(\*STDIN)
1359+ || die $parser->error();
1360+
1361+ Any warnings encountered can be examined by calling the
1362+ warnings() method.
1363+
1364+ foreach my $warn ($parser->warnings()) {
1365+ warn $warn, "\n";
1366+ }
1367+
1368+ =head2 parse_text($text)
1369+
1370+ Parses the Pod text string passed as an argument into a Pod Object
1371+ Model, as per parse_file().
1372+
1373+ =head2 parse($text_or_$file)
1374+
1375+ General purpose method which attempts to Do The Right Thing in calling
1376+ parse_file() or parse_text() according to the argument passed.
1377+
1378+ A hash reference can be passed as an argument that contains a 'text'
1379+ or 'file' key and corresponding value.
1380+
1381+ my $podpom = $parser->parse({ file => $filename })
1382+ || die $parser->error();
1383+
1384+ Otherwise, the argument can be a reference to an input handle which is
1385+ passed off to parse_file().
1386+
1387+ my $podpom = $parser->parse(\*DATA)
1388+ || die $parser->error();
1389+
1390+ If the argument is a text string that looks like Pod text (i.e. it
1391+ contains '=' at the start of any line) then it is passed to parse_text().
1392+
1393+ my $podpom = $parser->parse($podtext)
1394+ || die $parser->error();
1395+
1396+ Otherwise it is assumed to be a filename and is passed to parse_file().
1397+
1398+ my $podpom = $parser->parse($podfile)
1399+ || die $parser->error();
1400+
1401+ =head1 NODE TYPES, ATTRIBUTES AND ELEMENTS
1402+
1403+ This section lists the different nodes that may be present in a Pod Object
1404+ Model. These are implemented as Pod::POM::Node::* object instances
1405+ (e.g. head1 =E<gt> Pod::POM::Node::Head1). To present a node, a view should
1406+ implement a method which corresponds to the node name prefixed by 'view_'
1407+ (e.g. head1 =E<gt> view_head1()).
1408+
1409+ =over 4
1410+
1411+ =item pod
1412+
1413+ The C<pod> node is used to represent the root node of the Pod Object Model.
1414+
1415+ Content elements: head1, head2, head3, head4, over, begin, for,
1416+ verbatim, text, code.
1417+
1418+ =item head1
1419+
1420+ A C<head1> node contains the Pod content from a C<=head1> tag up to the
1421+ next C<=head1> tag or the end of the file.
1422+
1423+ Attributes: title
1424+
1425+ Content elements: head2, head3, head4, over, begin, for, verbatim, text, code.
1426+
1427+ =item head2
1428+
1429+ A C<head2> node contains the Pod content from a C<=head2> tag up to the
1430+ next C<=head1> or C<=head2> tag or the end of the file.
1431+
1432+ Attributes: title
1433+
1434+ Content elements: head3, head4, over, begin, for, verbatim, text, code.
1435+
1436+ =item head3
1437+
1438+ A C<head3> node contains the Pod content from a C<=head3> tag up to the
1439+ next C<=head1>, C<=head2> or C<=head3> tag or the end of the file.
1440+
1441+ Attributes: title
1442+
1443+ Content elements: head4, over, begin, for, verbatim, text, code.
1444+
1445+ =item head4
1446+
1447+ A C<head4> node contains the Pod content from a C<=head4> tag up to the
1448+ next C<=head1>, C<=head2>, C<=head3> or C<=head4> tag or the end of the file.
1449+
1450+ Attributes: title
1451+
1452+ Content elements: over, begin, for, verbatim, text, code.
1453+
1454+ =item over
1455+
1456+ The C<over> node encloses the Pod content in a list starting at an C<=over>
1457+ tag and continuing up to the matching C<=back> tag. Lists may be nested
1458+ indefinately.
1459+
1460+ Attributes: indent (default: 4)
1461+
1462+ Content elements: over, item, begin, for, verbatim, text, code.
1463+
1464+ =item item
1465+
1466+ The C<item> node encloses the Pod content in a list item starting at an
1467+ C<=item> tag and continuing up to the next C<=item> tag or a C<=back> tag
1468+ which terminates the list.
1469+
1470+ Attributes: title (default: *)
1471+
1472+ Content elements: over, begin, for, verbatim, text, code.
1473+
1474+ =item begin
1475+
1476+ A C<begin> node encloses the Pod content in a conditional block starting
1477+ with a C<=begin> tag and continuing up to the next C<=end> tag.
1478+
1479+ Attributes: format
1480+
1481+ Content elements: verbatim, text, code.
1482+
1483+ =item for
1484+
1485+ A C<for> node contains a single paragraph containing text relevant to a
1486+ particular format.
1487+
1488+ Attributes: format, text
1489+
1490+ =item verbatim
1491+
1492+ A C<verbatim> node contains a verbatim text paragraph which is prefixed by
1493+ whitespace in the source Pod document (i.e. indented).
1494+
1495+ Attributes: text
1496+
1497+ =item text
1498+
1499+ A C<text> node contains a regular text paragraph. This may include
1500+ embedded inline sequences.
1501+
1502+ Attributes: text
1503+
1504+ =item code
1505+
1506+ A C<code> node contains Perl code which is by default, not considered to be
1507+ part of a Pod document. The C<code> configuration option must be set for
1508+ Pod::POM to generate code blocks, otherwise they are ignored.
1509+
1510+ Attributes: text
1511+
1512+ =back
1513+
1514+ =head1 INLINE SEQUENCES
1515+
1516+ Embedded sequences are permitted within regular text blocks (i.e. not
1517+ verbatim) and title attributes. To present these sequences, a view
1518+ should implement methods corresponding to the sequence name, prefixed
1519+ by 'view_seq_' (e.g. bold =E<gt> view_seq_bold()).
1520+
1521+ =over 4
1522+
1523+ =item code
1524+
1525+ Code extract, e.g. CE<lt>my codeE<gt>
1526+
1527+ =item bold
1528+
1529+ Bold text, e.g. BE<lt>bold textE<gt>
1530+
1531+ =item italic
1532+
1533+ Italic text, e.g. IE<lt>italic textE<gt>
1534+
1535+ =item link
1536+
1537+ A link (cross reference), e.g. LE<lt>My::ModuleE<gt>
1538+
1539+ =item space
1540+
1541+ Text contains non-breaking space, e.g.SE<lt>Buffy The Vampire SlayerE<gt>
1542+
1543+ =item file
1544+
1545+ A filename, e.g. FE<lt>/etc/lilo.confE<gt>
1546+
1547+ =item index
1548+
1549+ An index entry, e.g. XE<lt>AngelE<gt>
1550+
1551+ =item zero
1552+
1553+ A zero-width character, e.g. ZE<lt>E<gt>
1554+
1555+ =item entity
1556+
1557+ An entity escape, e.g. EE<lt>ltE<gt>
1558+
1559+ =back
1560+
1561+ =head1 BUNDLED MODULES AND TOOLS
1562+
1563+ The Pod::POM module distribution includes a number of sample view
1564+ objects for rendering Pod Object Models into particular formats. These
1565+ are incomplete and may require some further work, but serve at present to
1566+ illustrate the principal and can be used as the basis for your own view
1567+ objects.
1568+
1569+ =over 4
1570+
1571+ =item Pod::POM::View::Pod
1572+
1573+ Regenerates the model as Pod.
1574+
1575+ =item Pod::POM::View::Text
1576+
1577+ Presents the model as plain text.
1578+
1579+ =item Pod::POM::View::HTML
1580+
1581+ Presents the model as HTML.
1582+
1583+ =back
1584+
1585+ A script is provided for converting Pod documents to other format by
1586+ using the view objects provided. The C<pom2> script should be called
1587+ with two arguments, the first specifying the output format, the second
1588+ the input filename. e.g.
1589+
1590+ $ pom2 text My/Module.pm > README
1591+ $ pom2 html My/Module.pm > ~/public_html/My/Module.html
1592+
1593+ You can also create symbolic links to the script if you prefer and
1594+ leave it to determine the output format from its own name.
1595+
1596+ $ ln -s pom2 pom2text
1597+ $ ln -s pom2 pom2html
1598+ $ pom2text My/Module.pm > README
1599+ $ pom2html My/Module.pm > ~/public_html/My/Module.html
1600+
1601+ The distribution also contains a trivial script, C<podlint>
1602+ (previously C<pomcheck>), which checks a Pod document for
1603+ well-formedness by simply parsing it into a Pod Object Model with
1604+ warnings enabled. Warnings are printed to STDERR.
1605+
1606+ $ podlint My/Module.pm
1607+
1608+ The C<-f> option can be set to have the script attempt to fix any problems
1609+ it encounters. The regenerated Pod output is printed to STDOUT.
1610+
1611+ $ podlint -f My/Module.pm > newfile
1612+
1613+ =head1 METADATA
1614+
1615+ This module includes support for an experimental new C<=meta> tag. This
1616+ is disabled by default but can be enabled by loading Pod::POM with the
1617+ C<meta> option.
1618+
1619+ use Pod::POM qw( meta );
1620+
1621+ Alternately, you can specify the C<meta> option to be any true value when
1622+ you instantiate a Pod::POM parser:
1623+
1624+ my $parser = Pod::POM->new( meta => 1 );
1625+ my $pom = $parser->parse_file($filename);
1626+
1627+ Any C<=meta> tags in the document will be stored as metadata items in the
1628+ root node of the Pod model created.
1629+
1630+ For example:
1631+
1632+ =meta module Foo::Bar
1633+
1634+ =meta author Andy Wardley
1635+
1636+ You can then access these items via the metadata() method.
1637+
1638+ print "module: ", $pom->metadata('module'), "\n";
1639+ print "author: ", $pom->metadata('author'), "\n";
1640+
1641+ or
1642+
1643+ my $metadata = $pom->metadata();
1644+ print "module: $metadata->{ module }\n";
1645+ print "author: $metadata->{ author }\n";
1646+
1647+ Please note that this is an experimental feature which is not supported by
1648+ other POD processors and is therefore likely to be most incompatible. Use
1649+ carefully.
1650+
1651+ =head1 AUTHOR
1652+
1653+ Andy Wardley E<lt>abw@kfs.orgE<gt>
1654+
1655+ Andrew Ford E<lt>A.Ford@ford-mason.co.ukE<gt> (co-maintainer as of 03/2009)
1656+
1657+ =head1 VERSION
1658+
1659+ This is version 0.25 of the Pod::POM module.
1660+
1661+ =head1 COPYRIGHT
1662+
1663+ Copyright (C) 2000-2009 Andy Wardley. All Rights Reserved.
1664+
1665+ This module is free software; you can redistribute it and/or
1666+ modify it under the same terms as Perl itself.
1667+
1668+ =head1 SEE ALSO
1669+
1670+ For the definitive reference on Pod, see L<perlpod>.
1671+
1672+ For an overview of Pod::POM internals and details relating to subclassing
1673+ of POM nodes, see L<Pod::POM::Node>.
1674+
1675+ There are numerous other fine Pod modules available from CPAN which
1676+ perform conversion from Pod to other formats. In many cases these are
1677+ likely to be faster and quite possibly more reliable and/or complete
1678+ than this module. But as far as I know, there aren't any that offer
1679+ the same kind of flexibility in being able to customise the generated
1680+ output. But don't take my word for it - see your local CPAN site for
1681+ further details:
1682+
1683+ http://www.cpan.org/modules/by-module/Pod/
1684+
1685+POD_POM
1686+
1687+$fatpacked{"Pod/POM/Constants.pm"} = <<'POD_POM_CONSTANTS';
1688+ #============================================================= -*-Perl-*-
1689+ #
1690+ # Pod::POM::Constants
1691+ #
1692+ # DESCRIPTION
1693+ # Constants used by Pod::POM.
1694+ #
1695+ # AUTHOR
1696+ # Andy Wardley <abw@kfs.org>
1697+ # Andrew Ford <a.ford@ford-mason.co.uk>
1698+ #
1699+ # COPYRIGHT
1700+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
1701+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
1702+ #
1703+ # This module is free software; you can redistribute it and/or
1704+ # modify it under the same terms as Perl itself.
1705+ #
1706+ # REVISION
1707+ # $Id: Constants.pm 78 2009-08-20 20:44:53Z ford $
1708+ #
1709+ #========================================================================
1710+
1711+ package Pod::POM::Constants;
1712+
1713+ require 5.004;
1714+
1715+ use strict;
1716+
1717+ use vars qw( $VERSION @SEQUENCE @STATUS @EXPORT_OK %EXPORT_TAGS );
1718+ use parent qw( Exporter );
1719+
1720+ $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
1721+ @SEQUENCE = qw( CMD LPAREN RPAREN FILE LINE CONTENT );
1722+ @STATUS = qw( IGNORE REDUCE REJECT );
1723+ @EXPORT_OK = ( @SEQUENCE, @STATUS );
1724+ %EXPORT_TAGS = (
1725+ status => [ @STATUS ],
1726+ seq => [ @SEQUENCE ],
1727+ all => [ @STATUS, @SEQUENCE ],
1728+ );
1729+
1730+ # sequence items
1731+ use constant CMD => 0;
1732+ use constant LPAREN => 1;
1733+ use constant RPAREN => 2;
1734+ use constant FILE => 3;
1735+ use constant LINE => 4;
1736+ use constant CONTENT => 5;
1737+
1738+ # node add return values
1739+ use constant IGNORE => 0;
1740+ use constant REDUCE => 1;
1741+ use constant REJECT => 2;
1742+
1743+
1744+ 1;
1745+
1746+ =head1 NAME
1747+
1748+ Pod::POM::Constants
1749+
1750+ =head1 DESCRIPTION
1751+
1752+ Constants used by Pod::POM.
1753+
1754+ =head1 AUTHOR
1755+
1756+ Andy Wardley E<lt>abw@kfs.orgE<gt>
1757+
1758+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
1759+
1760+ =head1 COPYRIGHT AND LICENSE
1761+
1762+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
1763+
1764+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
1765+
1766+ This module is free software; you can redistribute it and/or
1767+ modify it under the same terms as Perl itself.
1768+
1769+ =cut
1770+POD_POM_CONSTANTS
1771+
1772+$fatpacked{"Pod/POM/Node.pm"} = <<'POD_POM_NODE';
1773+ #============================================================= -*-Perl-*-
1774+ #
1775+ # Pod::POM::Node
1776+ #
1777+ # DESCRIPTION
1778+ # Base class for a node in a Pod::POM tree.
1779+ #
1780+ # AUTHOR
1781+ # Andy Wardley <abw@wardley.org>
1782+ #
1783+ # COPYRIGHT
1784+ # Copyright (C) 2000-2003 Andy Wardley. All Rights Reserved.
1785+ #
1786+ # This module is free software; you can redistribute it and/or
1787+ # modify it under the same terms as Perl itself.
1788+ #
1789+ # REVISION
1790+ # $Id: Node.pm 88 2010-04-02 13:37:41Z ford $
1791+ #
1792+ #========================================================================
1793+
1794+ package Pod::POM::Node;
1795+
1796+ require 5.004;
1797+
1798+ use strict;
1799+ use Pod::POM::Nodes;
1800+ use Pod::POM::Constants qw( :all );
1801+ use vars qw( $VERSION $DEBUG $ERROR $NODES $NAMES $AUTOLOAD );
1802+ use constant DUMP_LINE_LENGTH => 80;
1803+
1804+ $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
1805+ $DEBUG = 0 unless defined $DEBUG;
1806+ $NODES = {
1807+ pod => 'Pod::POM::Node::Pod',
1808+ head1 => 'Pod::POM::Node::Head1',
1809+ head2 => 'Pod::POM::Node::Head2',
1810+ head3 => 'Pod::POM::Node::Head3',
1811+ head4 => 'Pod::POM::Node::Head4',
1812+ over => 'Pod::POM::Node::Over',
1813+ item => 'Pod::POM::Node::Item',
1814+ begin => 'Pod::POM::Node::Begin',
1815+ for => 'Pod::POM::Node::For',
1816+ text => 'Pod::POM::Node::Text',
1817+ code => 'Pod::POM::Node::Code',
1818+ verbatim => 'Pod::POM::Node::Verbatim',
1819+ };
1820+ $NAMES = {
1821+ map { ( $NODES->{ $_ } => $_ ) } keys %$NODES,
1822+ };
1823+
1824+ # overload stringification to present node via a view
1825+ use overload
1826+ '""' => 'present',
1827+ fallback => 1,
1828+ 'bool' => sub { 1 };
1829+
1830+ # alias meta() to metadata()
1831+ *meta = \*metadata;
1832+
1833+
1834+ #------------------------------------------------------------------------
1835+ # new($pom, @attr)
1836+ #
1837+ # Constructor method. Returns a new Pod::POM::Node::* object or undef
1838+ # on error. First argument is the Pod::POM parser object, remaining
1839+ # arguments are node attributes as specified in %ATTRIBS in derived class
1840+ # package.
1841+ #------------------------------------------------------------------------
1842+
1843+ sub new {
1844+ my $class = shift;
1845+ my $pom = shift;
1846+ my ($type, $attribs, $accept, $key, $value, $default);
1847+
1848+ $type = $NAMES->{ $class };
1849+
1850+ {
1851+ no strict qw( refs );
1852+ $attribs = \%{"$class\::ATTRIBS"} || [ ];
1853+ $accept = \@{"$class\::ACCEPT"} || [ ];
1854+ unless (%{"$class\::ACCEPT"}) {
1855+ %{"$class\::ACCEPT"} = (
1856+ map { ( $_ => $NODES->{ $_ } ) } @$accept,
1857+ );
1858+ }
1859+ }
1860+
1861+ # create object with slots for each acceptable child and overall content
1862+ my $self = bless {
1863+ type => $type,
1864+ content => bless([ ], 'Pod::POM::Node::Content'),
1865+ map { ($_ => bless([ ], 'Pod::POM::Node::Content')) }
1866+ (@$accept, 'code'),
1867+ }, $class;
1868+
1869+ # set attributes from arguments
1870+ keys %$attribs; # reset hash iterator
1871+ while(my ($key, $default) = each %$attribs) {
1872+ $value = shift || $default;
1873+ return $class->error("$type expected a $key")
1874+ unless $value;
1875+ $self->{ $key } = $value;
1876+ }
1877+
1878+ return $self;
1879+ }
1880+
1881+
1882+ #------------------------------------------------------------------------
1883+ # add($pom, $type, @attr)
1884+ #
1885+ # Adds a new node as a child element (content) of the current node.
1886+ # First argument is the Pod::POM parser object. Second argument is the
1887+ # child node type specified by name (e.g. 'head1') which is mapped via
1888+ # the $NODES hash to a class name against which new() can be called.
1889+ # Remaining arguments are attributes passed to the child node constructor.
1890+ # Returns a reference to the new node (child was accepted) or one of the
1891+ # constants REDUCE (child terminated node, e.g. '=back' terminates an
1892+ # '=over' node), REJECT (child rejected, e.g. '=back' expected to terminate
1893+ # '=over' but something else found instead) or IGNORE (node didn't expect
1894+ # child and is implicitly terminated).
1895+ #------------------------------------------------------------------------
1896+
1897+ sub add {
1898+ my $self = shift;
1899+ my $pom = shift;
1900+ my $type = shift;
1901+ my $class = ref $self;
1902+ my ($name, $attribs, $accept, $expect, $nodeclass, $node);
1903+
1904+ $name = $NAMES->{ $class }
1905+ || return $self->error("no name for $class");
1906+ {
1907+ no strict qw( refs );
1908+ $accept = \%{"$class\::ACCEPT"};
1909+ $expect = ${"$class\::EXPECT"};
1910+ }
1911+
1912+ # SHIFT: accept indicates child nodes that can be accepted; a
1913+ # new node is created, added it to content list and node specific
1914+ # list, then returned by reference.
1915+
1916+ if ($nodeclass = $accept->{ $type }) {
1917+ defined($node = $nodeclass->new($pom, @_))
1918+ || return $self->error($nodeclass->error())
1919+ unless defined $node;
1920+ push(@{ $self->{ $type } }, $node);
1921+ push(@{ $self->{ content } }, $node);
1922+ $pom->{in_begin} = 1 if $nodeclass eq 'Pod::POM::Node::Begin';
1923+ return $node;
1924+ }
1925+
1926+ # REDUCE: expect indicates the token that should terminate this node
1927+ if (defined $expect && ($type eq $expect)) {
1928+ DEBUG("$name terminated by expected $type\n");
1929+ $pom->{in_begin} = 0 if $name eq 'begin';
1930+ return REDUCE;
1931+ }
1932+
1933+ # REJECT: expected terminating node was not found
1934+ if (defined $expect) {
1935+ DEBUG("$name rejecting $type, expecting a terminating $expect\n");
1936+ $self->error("$name expected a terminating $expect");
1937+ return REJECT;
1938+ }
1939+
1940+ # IGNORE: don't know anything about this node
1941+ DEBUG("$name ignoring $type\n");
1942+ return IGNORE;
1943+ }
1944+
1945+
1946+ #------------------------------------------------------------------------
1947+ # present($view)
1948+ #
1949+ # Present the node by making a callback on the appropriate method against
1950+ # the view object passed as an argument. $Pod::POM::DEFAULT_VIEW is used
1951+ # if $view is unspecified.
1952+ #------------------------------------------------------------------------
1953+
1954+ sub present {
1955+ my ($self, $view, @args) = @_;
1956+ $view ||= $Pod::POM::DEFAULT_VIEW;
1957+ my $type = $self->{ type };
1958+ my $method = "view_$type";
1959+ DEBUG("presenting method $method to $view\n");
1960+ my $txt = $view->$method($self, @args);
1961+ if ($view->can("encode")){
1962+ return $view->encode($txt);
1963+ } else {
1964+ return $txt;
1965+ }
1966+ }
1967+
1968+
1969+ #------------------------------------------------------------------------
1970+ # metadata()
1971+ # metadata($key)
1972+ # metadata($key, $value)
1973+ #
1974+ # Returns the metadata hash when called without any arguments. Returns
1975+ # the value of a metadata item when called with a single argument.
1976+ # Sets a metadata item to a value when called with two arguments.
1977+ #------------------------------------------------------------------------
1978+
1979+ sub metadata {
1980+ my ($self, $key, $value) = @_;
1981+ my $metadata = $self->{ METADATA } ||= { };
1982+
1983+ return $metadata unless defined $key;
1984+
1985+ if (defined $value) {
1986+ $metadata->{ $key } = $value;
1987+ }
1988+ else {
1989+ $value = $self->{ METADATA }->{ $key };
1990+ return defined $value ? $value
1991+ : $self->error("no such metadata item: $key");
1992+ }
1993+ }
1994+
1995+
1996+ #------------------------------------------------------------------------
1997+ # error()
1998+ # error($msg, ...)
1999+ #
2000+ # May be called as a class or object method to set or retrieve the
2001+ # package variable $ERROR (class method) or internal member
2002+ # $self->{ _ERROR } (object method). The presence of parameters indicates
2003+ # that the error value should be set. Undef is then returned. In the
2004+ # abscence of parameters, the current error value is returned.
2005+ #------------------------------------------------------------------------
2006+
2007+ sub error {
2008+ my $self = shift;
2009+ my $errvar;
2010+ # use Carp;
2011+
2012+ {
2013+ no strict qw( refs );
2014+ if (ref $self) {
2015+ # my ($pkg, $file, $line) = caller();
2016+ # print STDERR "called from $file line $line\n";
2017+ # croak "cannot get/set error in non-hash: $self\n"
2018+ # unless UNIVERSAL::isa($self, 'HASH');
2019+ $errvar = \$self->{ ERROR };
2020+ }
2021+ else {
2022+ $errvar = \${"$self\::ERROR"};
2023+ }
2024+ }
2025+ if (@_) {
2026+ $$errvar = ref($_[0]) ? shift : join('', @_);
2027+ return undef;
2028+ }
2029+ else {
2030+ return $$errvar;
2031+ }
2032+ }
2033+
2034+
2035+ #------------------------------------------------------------------------
2036+ # dump()
2037+ #
2038+ # Returns a representation of the element and all its children in a
2039+ # format useful only for debugging. The structure of the document is
2040+ # shown by indentation (inspired by HTML::Element).
2041+ #------------------------------------------------------------------------
2042+
2043+ sub dump {
2044+ my($self, $depth) = @_;
2045+ my $output;
2046+ $depth = 0 unless defined $depth;
2047+ my $nodepkg = ref $self;
2048+ if ($self->isa('REF')) {
2049+ $self = $$self;
2050+ my $cmd = $self->[CMD];
2051+ my @content = @{ $self->[CONTENT] };
2052+ if ($cmd) {
2053+ $output .= (" " x $depth) . $cmd . $self->[LPAREN] . "\n";
2054+ }
2055+ foreach my $item (@content) {
2056+ if (ref $item) {
2057+ $output .= $item->dump($depth+1); # recurse
2058+ }
2059+ else { # text node
2060+ $output .= _dump_text($item, $depth+1);
2061+ }
2062+ }
2063+ if ($cmd) {
2064+ $output .= (" " x $depth) . $self->[RPAREN] . "\n", ;
2065+ }
2066+ }
2067+ else {
2068+ no strict 'refs';
2069+ my @attrs = sort keys %{"*${nodepkg}::ATTRIBS"};
2070+ $output .= (" " x $depth) . $self->type . "\n";
2071+ foreach my $attr (@attrs) {
2072+ if (my $value = $self->{$attr}) {
2073+ $output .= (" " x ($depth+1)) . "\@$attr\n";
2074+
2075+ if (ref $value) {
2076+ $output .= $value->dump($depth+1);
2077+ }
2078+ else {
2079+ $output .= _dump_text($value, $depth+2);
2080+ }
2081+ }
2082+ }
2083+ foreach my $item (@{$self->{content}}) {
2084+ if (ref $item) { # element
2085+ $output .= $item->dump($depth+1); # recurse
2086+ }
2087+ else { # text node
2088+ $output .= _dump_text($item, $depth+1);
2089+ }
2090+ }
2091+ }
2092+
2093+ return $output;
2094+ }
2095+
2096+ sub _dump_text {
2097+ my ($text, $depth) = @_;
2098+
2099+ my $output = "";
2100+ my $padding = " " x $depth;
2101+ my $max_text_len = DUMP_LINE_LENGTH - length($depth) - 2;
2102+
2103+ foreach my $line (split(/\n/, $text)) {
2104+ $output .= $padding;
2105+ if (length($line) > $max_text_len or $line =~ m<[\x00-\x1F]>) {
2106+ # it needs prettyin' up somehow or other
2107+ my $x = (length($line) <= $max_text_len) ? $_ : (substr($line, 0, $max_text_len) . '...');
2108+ $x =~ s<([\x00-\x1F])>
2109+ <'\\x'.(unpack("H2",$1))>eg;
2110+ $output .= qq{"$x"\n};
2111+ } else {
2112+ $output .= qq{"$line"\n};
2113+ }
2114+ }
2115+ return $output;
2116+ }
2117+
2118+
2119+ #------------------------------------------------------------------------
2120+ # AUTOLOAD
2121+ #------------------------------------------------------------------------
2122+
2123+ sub AUTOLOAD {
2124+ my $self = shift;
2125+ my $name = $AUTOLOAD;
2126+ my $item;
2127+
2128+ $name =~ s/.*:://;
2129+ return if $name eq 'DESTROY';
2130+
2131+ # my ($pkg, $file, $line) = caller();
2132+ # print STDERR "called from $file line $line to return ", ref($item), "\n";
2133+
2134+ return $self->error("can't manipulate \$self")
2135+ unless UNIVERSAL::isa($self, 'HASH');
2136+ return $self->error("no such member: $name")
2137+ unless defined ($item = $self->{ $name });
2138+
2139+ return wantarray ? ( UNIVERSAL::isa($item, 'ARRAY') ? @$item : $item )
2140+ : $item;
2141+ }
2142+
2143+
2144+ #------------------------------------------------------------------------
2145+ # DEBUG(@msg)
2146+ #------------------------------------------------------------------------
2147+
2148+ sub DEBUG {
2149+ print STDERR "DEBUG: ", @_ if $DEBUG;
2150+ }
2151+
2152+ 1;
2153+
2154+
2155+
2156+ =head1 NAME
2157+
2158+ Pod::POM::Node - base class for a POM node
2159+
2160+ =head1 SYNOPSIS
2161+
2162+ package Pod::POM::Node::Over;
2163+ use base qw( Pod::POM::Node );
2164+ use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );
2165+
2166+ %ATTRIBS = ( indent => 4 );
2167+ @ACCEPT = qw( over item begin for text verbatim );
2168+ $EXPECT = q( back );
2169+
2170+ package main;
2171+ my $list = Pod::POM::Node::Over->new(8);
2172+ $list->add('item', 'First Item');
2173+ $list->add('item', 'Second Item');
2174+ ...
2175+
2176+ =head1 DESCRIPTION
2177+
2178+ This documentation describes the inner workings of the Pod::POM::Node
2179+ module and gives a brief overview of the relationship between it and
2180+ its derived classes. It is intended more as a guide to the internals
2181+ for interested hackers than as general user documentation. See
2182+ L<Pod::POM> for information on using the modules.
2183+
2184+ This module implements a base class node which is subclassed to
2185+ represent different elements within a Pod Object Model.
2186+
2187+ package Pod::POM::Node::Over;
2188+ use base qw( Pod::POM::Node );
2189+
2190+ The base class implements the new() constructor method to instantiate
2191+ new node objects.
2192+
2193+ my $list = Pod::POM::Node::Over->new();
2194+
2195+ The characteristics of a node can be specified by defining certain
2196+ variables in the derived class package. The C<%ATTRIBS> hash can be
2197+ used to denote attributes that the node should accept. In the case of
2198+ an C<=over> node, for example, an C<indent> attribute can be specified
2199+ which otherwise defaults to 4.
2200+
2201+ package Pod::POM::Node::Over;
2202+ use base qw( Pod::POM::Node );
2203+ use vars qw( %ATTRIBS $ERROR );
2204+
2205+ %ATTRIBS = ( indent => 4 );
2206+
2207+ The new() method will now expect an argument to set the indent value,
2208+ or will use 4 as the default if no argument is provided.
2209+
2210+ my $list = Pod::POM::Node::Over->new(8); # indent: 8
2211+ my $list = Pod::POM::Node::Over->new( ); # indent: 4
2212+
2213+ If the default value is undefined then the argument is mandatory.
2214+
2215+ package Pod::POM::Node::Head1;
2216+ use base qw( Pod::POM::Node );
2217+ use vars qw( %ATTRIBS $ERROR );
2218+
2219+ %ATTRIBS = ( title => undef );
2220+
2221+ package main;
2222+ my $head = Pod::POM::Node::Head1->new('My Title');
2223+
2224+ If a mandatory argument isn't provided then the constructor will
2225+ return undef to indicate failure. The $ERROR variable in the derived
2226+ class package is set to contain a string of the form "$type expected a
2227+ $attribute".
2228+
2229+ # dies with error: "head1 expected a title"
2230+ my $head = Pod::POM::Node::Head1->new()
2231+ || die $Pod::POM::Node::Head1::ERROR;
2232+
2233+ For convenience, the error() subroutine can be called as a class
2234+ method to retrieve this value.
2235+
2236+ my $type = 'Pod::POM::Node::Head1';
2237+ my $head = $type->new()
2238+ || die $type->error();
2239+
2240+ The C<@ACCEPT> package variable can be used to indicate the node types
2241+ that are permitted as children of a node.
2242+
2243+ package Pod::POM::Node::Head1;
2244+ use base qw( Pod::POM::Node );
2245+ use vars qw( %ATTRIBS @ACCEPT $ERROR );
2246+
2247+ %ATTRIBS = ( title => undef );
2248+ @ACCEPT = qw( head2 over begin for text verbatim );
2249+
2250+ The add() method can then be called against a node to add a new child
2251+ node as part of its content.
2252+
2253+ $head->add('over', 8);
2254+
2255+ The first argument indicates the node type. The C<@ACCEPT> list is
2256+ examined to ensure that the child node type is acceptable for the
2257+ parent node. If valid, the constructor for the relevant child node
2258+ class is called passing any remaining arguments as attributes. The
2259+ new node is then returned.
2260+
2261+ my $list = $head->add('over', 8);
2262+
2263+ The error() method can be called against the I<parent> node to retrieve
2264+ any constructor error generated by the I<child> node.
2265+
2266+ my $list = $head->add('over', 8);
2267+ die $head->error() unless defined $list;
2268+
2269+ If the child node is not acceptable to the parent then the add()
2270+ method returns one of the constants IGNORE, REDUCE or REJECT, as
2271+ defined in Pod::POM::Constants. These return values are used by the
2272+ Pod::POM parser module to implement a simple shift/reduce parser.
2273+
2274+ In the most common case, IGNORE is returned to indicate that the
2275+ parent node doesn't know anything about the new child node. The
2276+ parser uses this as an indication that it should back up through the
2277+ parse stack until it finds a node which I<will> accept this child node.
2278+ Through this mechanism, the parser is able to implicitly terminate
2279+ certain POD blocks. For example, a list item initiated by a C<=item>
2280+ tag will I<not> accept another C<=item> tag, but will instead return IGNORE.
2281+ The parser will back out until it finds the enclosing C<=over> node
2282+ which I<will> accept it. Thus, a new C<=item> implicitly terminates any
2283+ previous C<=item>.
2284+
2285+ The C<$EXPECT> package variable can be used to indicate a node type
2286+ which a parent expects to terminate itself. An C<=over> node, for
2287+ example, should always be terminated by a matching C<=back>. When
2288+ such a match is made, the add() method returns REDUCE to indicate
2289+ successful termination.
2290+
2291+ package Pod::POM::Node::Over;
2292+ use base qw( Pod::POM::Node );
2293+ use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );
2294+
2295+ %ATTRIBS = ( indent => 4 );
2296+ @ACCEPT = qw( over item begin for text verbatim );
2297+ $EXPECT = q( back );
2298+
2299+ package main;
2300+ my $list = Pod::POM::Node::Over->new();
2301+ my $item = $list->add('item');
2302+ $list->add('back'); # returns REDUCE
2303+
2304+ If a child node isn't specified in the C<@ACCEPT> list or doesn't match
2305+ any C<$EXPECT> specified then REJECT is returned. The parent node sets
2306+ an internal error of the form "$type expected a terminating $expect".
2307+ The parser uses this to detect missing POD tags. In nearly all cases
2308+ the parser is smart enough to fix the incorrect structure and downgrades
2309+ any errors to warnings.
2310+
2311+ # dies with error 'over expected terminating back'
2312+ ref $list->add('head1', 'My Title') # returns REJECT
2313+ || die $list->error();
2314+
2315+ Each node contains a 'type' field which contains a simple string
2316+ indicating the node type, e.g. 'head1', 'over', etc. The $NODES and
2317+ $NAMES package variables (in the base class) reference hash arrays
2318+ which map these names to and from package names (e.g. head1 E<lt>=E<gt>
2319+ Pod::POM::Node::Head1).
2320+
2321+ print $list->{ type }; # 'over'
2322+
2323+ An AUTOLOAD method is provided to access to such internal items for
2324+ those who don't like violating an object's encapsulation.
2325+
2326+ print $list->type();
2327+
2328+ Nodes also contain a 'content' list, blessed into the
2329+ Pod::POM::Node::Content class, which contains the content (child
2330+ elements) for the node. The AUTOLOAD method returns this as a list
2331+ reference or as a list of items depending on the context in which it
2332+ is called.
2333+
2334+ my $items = $list->content();
2335+ my @items = $list->content();
2336+
2337+ Each node also contains a content list for each individual child node
2338+ type that it may accept.
2339+
2340+ my @items = $list->item();
2341+ my @text = $list->text();
2342+ my @vtext = $list->verbatim();
2343+
2344+ The present() method is used to present a node through a particular view.
2345+ This simply maps the node type to a method which is then called against the
2346+ view object. This is known as 'double dispatch'.
2347+
2348+ my $view = 'Pod::POM::View::HTML';
2349+ print $list->present($view);
2350+
2351+ The method name is constructed from the node type prefixed by 'view_'.
2352+ Thus the following are roughly equivalent.
2353+
2354+ $list->present($view);
2355+
2356+ $view->view_list($list);
2357+
2358+ The benefit of the former over the latter is, of course, that the
2359+ caller doesn't need to know or determine the type of the node. The
2360+ node itself is in the best position to determine what type it is.
2361+
2362+ =head1 AUTHOR
2363+
2364+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2365+
2366+ =head1 COPYRIGHT
2367+
2368+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2369+
2370+ This module is free software; you can redistribute it and/or
2371+ modify it under the same terms as Perl itself.
2372+
2373+ =head1 SEE ALSO
2374+
2375+ Consult L<Pod::POM> for a general overview and examples of use.
2376+
2377+POD_POM_NODE
2378+
2379+$fatpacked{"Pod/POM/Node/Begin.pm"} = <<'POD_POM_NODE_BEGIN';
2380+ #============================================================= -*-Perl-*-
2381+ #
2382+ # Pod::POM::Node::Begin
2383+ #
2384+ # DESCRIPTION
2385+ # Module implementing specific nodes in a Pod::POM, subclassed from
2386+ # Pod::POM::Node.
2387+ #
2388+ # AUTHOR
2389+ # Andy Wardley <abw@kfs.org>
2390+ # Andrew Ford <a.ford@ford-mason.co.uk>
2391+ #
2392+ # COPYRIGHT
2393+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2394+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2395+ #
2396+ # This module is free software; you can redistribute it and/or
2397+ # modify it under the same terms as Perl itself.
2398+ #
2399+ # REVISION
2400+ # $Id: Begin.pm 76 2009-08-20 20:41:33Z ford $
2401+ #
2402+ #========================================================================
2403+
2404+ package Pod::POM::Node::Begin;
2405+
2406+ use strict;
2407+
2408+ use parent qw( Pod::POM::Node );
2409+ use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );
2410+
2411+ %ATTRIBS = ( format => undef );
2412+ @ACCEPT = qw( text verbatim code );
2413+ $EXPECT = 'end';
2414+
2415+ 1;
2416+
2417+ =head1 NAME
2418+
2419+ Pod::POM::Node::Begin - POM '=begin' node class
2420+
2421+ =head1 SYNOPSIS
2422+
2423+ =head1 DESCRIPTION
2424+
2425+ This module implements a specialization of the node class to represent '=begin' elements.
2426+
2427+ =head1 AUTHOR
2428+
2429+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
2430+
2431+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2432+
2433+ =head1 COPYRIGHT
2434+
2435+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2436+
2437+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2438+
2439+ This module is free software; you can redistribute it and/or
2440+ modify it under the same terms as Perl itself.
2441+
2442+ =head1 SEE ALSO
2443+
2444+ Consult L<Pod::POM::Node> for a discussion of nodes.
2445+POD_POM_NODE_BEGIN
2446+
2447+$fatpacked{"Pod/POM/Node/Code.pm"} = <<'POD_POM_NODE_CODE';
2448+ #============================================================= -*-Perl-*-
2449+ #
2450+ # Pod::POM::Node::Code
2451+ #
2452+ # DESCRIPTION
2453+ # Module implementing specific nodes in a Pod::POM, subclassed from
2454+ # Pod::POM::Node.
2455+ #
2456+ # AUTHOR
2457+ # Andy Wardley <abw@kfs.org>
2458+ # Andrew Ford <a.ford@ford-mason.co.uk>
2459+ #
2460+ # COPYRIGHT
2461+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2462+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2463+ #
2464+ # This module is free software; you can redistribute it and/or
2465+ # modify it under the same terms as Perl itself.
2466+ #
2467+ # REVISION
2468+ # $Id: Code.pm 76 2009-08-20 20:41:33Z ford $
2469+ #
2470+ #========================================================================
2471+
2472+ package Pod::POM::Node::Code;
2473+
2474+ use strict;
2475+
2476+ use parent qw( Pod::POM::Node );
2477+ use vars qw( %ATTRIBS $ERROR );
2478+
2479+ %ATTRIBS = ( text => '' );
2480+
2481+ sub present {
2482+ my ($self, $view) = @_;
2483+ $view ||= $Pod::POM::DEFAULT_VIEW;
2484+ return $view->view_code($self->{ text });
2485+ }
2486+
2487+ 1;
2488+
2489+ =head1 NAME
2490+
2491+ Pod::POM::Node::Code -
2492+
2493+ =head1 SYNOPSIS
2494+
2495+ =head1 DESCRIPTION
2496+
2497+ This module implements a specialization of the node class to represent code elements.
2498+
2499+ =head1 AUTHOR
2500+
2501+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
2502+
2503+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2504+
2505+ =head1 COPYRIGHT
2506+
2507+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2508+
2509+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2510+
2511+ This module is free software; you can redistribute it and/or
2512+ modify it under the same terms as Perl itself.
2513+
2514+ =head1 SEE ALSO
2515+
2516+ Consult L<Pod::POM::Node> for a discussion of nodes.
2517+POD_POM_NODE_CODE
2518+
2519+$fatpacked{"Pod/POM/Node/Content.pm"} = <<'POD_POM_NODE_CONTENT';
2520+ #============================================================= -*-Perl-*-
2521+ #
2522+ # Pod::POM::Node::Content
2523+ #
2524+ # DESCRIPTION
2525+ # Module implementing specific nodes in a Pod::POM, subclassed from
2526+ # Pod::POM::Node.
2527+ #
2528+ # AUTHOR
2529+ # Andy Wardley <abw@kfs.org>
2530+ # Andrew Ford <a.ford@ford-mason.co.uk>
2531+ #
2532+ # COPYRIGHT
2533+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2534+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2535+ #
2536+ # This module is free software; you can redistribute it and/or
2537+ # modify it under the same terms as Perl itself.
2538+ #
2539+ # REVISION
2540+ # $Id: Content.pm 76 2009-08-20 20:41:33Z ford $
2541+ #
2542+ #========================================================================
2543+
2544+ package Pod::POM::Node::Content;
2545+
2546+ use strict;
2547+
2548+ use Pod::POM::Constants qw( :all );
2549+ use parent qw( Pod::POM::Node );
2550+
2551+ sub new {
2552+ my $class = shift;
2553+ return bless [ @_ ], $class;
2554+ }
2555+
2556+ sub present {
2557+ my ($self, $view) = @_;
2558+ $view ||= $Pod::POM::DEFAULT_VIEW;
2559+ return join('', map { ref $_ ? $_->present($view) : $_ } @$self);
2560+ }
2561+
2562+
2563+ 1;
2564+
2565+
2566+ =head1 NAME
2567+
2568+ Pod::POM::Node::Content -
2569+
2570+ =head1 SYNOPSIS
2571+
2572+ use Pod::POM::Nodes;
2573+
2574+ =head1 DESCRIPTION
2575+
2576+ This module implements a specialization of the node class to represent
2577+
2578+ =head1 AUTHOR
2579+
2580+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
2581+
2582+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2583+
2584+ =head1 COPYRIGHT
2585+
2586+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2587+
2588+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2589+
2590+ This module is free software; you can redistribute it and/or
2591+ modify it under the same terms as Perl itself.
2592+
2593+ =head1 SEE ALSO
2594+
2595+ Consult L<Pod::POM::Node> for a discussion of nodes.
2596+POD_POM_NODE_CONTENT
2597+
2598+$fatpacked{"Pod/POM/Node/For.pm"} = <<'POD_POM_NODE_FOR';
2599+ #============================================================= -*-Perl-*-
2600+ #
2601+ # Pod::POM::Nodes
2602+ #
2603+ # DESCRIPTION
2604+ # Module implementing specific nodes in a Pod::POM, subclassed from
2605+ # Pod::POM::Node.
2606+ #
2607+ # AUTHOR
2608+ # Andy Wardley <abw@kfs.org>
2609+ # Andrew Ford <a.ford@ford-mason.co.uk>
2610+ #
2611+ # COPYRIGHT
2612+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2613+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2614+ #
2615+ # This module is free software; you can redistribute it and/or
2616+ # modify it under the same terms as Perl itself.
2617+ #
2618+ # REVISION
2619+ # $Id: For.pm 76 2009-08-20 20:41:33Z ford $
2620+ #
2621+ #========================================================================
2622+
2623+ package Pod::POM::Node::For;
2624+
2625+ use strict;
2626+
2627+ use parent qw( Pod::POM::Node );
2628+ use vars qw( %ATTRIBS $ERROR );
2629+
2630+ %ATTRIBS = ( format => undef, text => '' );
2631+
2632+ sub new {
2633+ my $class = shift;
2634+ my $pom = shift;
2635+ my $text = shift;
2636+ return $class->SUPER::new($pom, split(/\s+/, $text, 2));
2637+ }
2638+
2639+ 1;
2640+
2641+ =head1 NAME
2642+
2643+ Pod::POM::Node::For -
2644+
2645+ =head1 SYNOPSIS
2646+
2647+ use Pod::POM::Nodes;
2648+
2649+ =head1 DESCRIPTION
2650+
2651+ This module implements a specialization of the node class to represent C<=for> elements.
2652+
2653+ =head1 AUTHOR
2654+
2655+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
2656+
2657+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2658+
2659+ =head1 COPYRIGHT
2660+
2661+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2662+
2663+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2664+
2665+ This module is free software; you can redistribute it and/or
2666+ modify it under the same terms as Perl itself.
2667+
2668+ =head1 SEE ALSO
2669+
2670+ Consult L<Pod::POM::Node> for a discussion of nodes.
2671+POD_POM_NODE_FOR
2672+
2673+$fatpacked{"Pod/POM/Node/Head1.pm"} = <<'POD_POM_NODE_HEAD1';
2674+ #============================================================= -*-Perl-*-
2675+ #
2676+ # Pod::POM::Node::Head1
2677+ #
2678+ # DESCRIPTION
2679+ # Module implementing specific nodes in a Pod::POM, subclassed from
2680+ # Pod::POM::Node.
2681+ #
2682+ # AUTHOR
2683+ # Andy Wardley <abw@kfs.org>
2684+ # Andrew Ford <a.ford@ford-mason.co.uk>
2685+ #
2686+ # COPYRIGHT
2687+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2688+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2689+ #
2690+ # This module is free software; you can redistribute it and/or
2691+ # modify it under the same terms as Perl itself.
2692+ #
2693+ # REVISION
2694+ # $Id: Head1.pm 76 2009-08-20 20:41:33Z ford $
2695+ #
2696+ #========================================================================
2697+
2698+ package Pod::POM::Node::Head1;
2699+
2700+ use strict;
2701+
2702+ use parent qw( Pod::POM::Node );
2703+ use vars qw( %ATTRIBS @ACCEPT $ERROR );
2704+
2705+ %ATTRIBS = ( title => undef );
2706+ @ACCEPT = qw( head2 head3 head4 over begin for text verbatim code );
2707+
2708+ sub new {
2709+ my ($class, $pom, $title) = @_;
2710+ $title = $pom->parse_sequence($title)
2711+ || return $class->error($pom->error())
2712+ if length $title;
2713+ return $class->SUPER::new($pom, $title);
2714+ }
2715+
2716+ 1;
2717+
2718+ =head1 NAME
2719+
2720+ Pod::POM::Node::Head1 -
2721+
2722+ =head1 SYNOPSIS
2723+
2724+ use Pod::POM::Nodes;
2725+
2726+ =head1 DESCRIPTION
2727+
2728+ This module implements a specialization of the node class to represent C<=head1> elements.
2729+
2730+ =head1 AUTHOR
2731+
2732+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
2733+
2734+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2735+
2736+ =head1 COPYRIGHT
2737+
2738+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2739+
2740+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2741+
2742+ This module is free software; you can redistribute it and/or
2743+ modify it under the same terms as Perl itself.
2744+
2745+ =head1 SEE ALSO
2746+
2747+ Consult L<Pod::POM::Node> for a discussion of nodes.
2748+POD_POM_NODE_HEAD1
2749+
2750+$fatpacked{"Pod/POM/Node/Head2.pm"} = <<'POD_POM_NODE_HEAD2';
2751+ #============================================================= -*-Perl-*-
2752+ #
2753+ # Pod::POM::Node::Head2
2754+ #
2755+ # DESCRIPTION
2756+ # Module implementing specific nodes in a Pod::POM, subclassed from
2757+ # Pod::POM::Node.
2758+ #
2759+ # AUTHOR
2760+ # Andy Wardley <abw@kfs.org>
2761+ # Andrew Ford <a.ford@ford-mason.co.uk>
2762+ #
2763+ # COPYRIGHT
2764+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2765+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2766+ #
2767+ # This module is free software; you can redistribute it and/or
2768+ # modify it under the same terms as Perl itself.
2769+ #
2770+ # REVISION
2771+ # $Id: Head2.pm 76 2009-08-20 20:41:33Z ford $
2772+ #
2773+ #========================================================================
2774+
2775+ package Pod::POM::Node::Head2;
2776+
2777+ use strict;
2778+
2779+ use parent qw( Pod::POM::Node );
2780+ use vars qw( %ATTRIBS @ACCEPT $ERROR );
2781+
2782+ %ATTRIBS = ( title => undef );
2783+ @ACCEPT = qw( head3 head4 over begin for text verbatim code );
2784+
2785+ sub new {
2786+ my ($class, $pom, $title) = @_;
2787+ $title = $pom->parse_sequence($title)
2788+ || return $class->error($pom->error())
2789+ if length $title;
2790+ return $class->SUPER::new($pom, $title);
2791+ }
2792+
2793+ 1;
2794+
2795+ =head1 NAME
2796+
2797+ Pod::POM::Node::Head2 -
2798+
2799+ =head1 SYNOPSIS
2800+
2801+ use Pod::POM::Nodes;
2802+
2803+ =head1 DESCRIPTION
2804+
2805+ This module implements a specialization of the node class to represent C<=head2> elements.
2806+
2807+ =head1 AUTHOR
2808+
2809+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
2810+
2811+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2812+
2813+ =head1 COPYRIGHT
2814+
2815+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2816+
2817+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2818+
2819+ This module is free software; you can redistribute it and/or
2820+ modify it under the same terms as Perl itself.
2821+
2822+ =head1 SEE ALSO
2823+
2824+ Consult L<Pod::POM::Node> for a discussion of nodes.
2825+POD_POM_NODE_HEAD2
2826+
2827+$fatpacked{"Pod/POM/Node/Head3.pm"} = <<'POD_POM_NODE_HEAD3';
2828+ #============================================================= -*-Perl-*-
2829+ #
2830+ # Pod::POM::Node::Head3
2831+ #
2832+ # DESCRIPTION
2833+ # Module implementing specific nodes in a Pod::POM, subclassed from
2834+ # Pod::POM::Node.
2835+ #
2836+ # AUTHOR
2837+ # Andy Wardley <abw@kfs.org>
2838+ # Andrew Ford <a.ford@ford-mason.co.uk>
2839+ #
2840+ # COPYRIGHT
2841+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2842+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2843+ #
2844+ # This module is free software; you can redistribute it and/or
2845+ # modify it under the same terms as Perl itself.
2846+ #
2847+ # REVISION
2848+ # $Id: Head3.pm 76 2009-08-20 20:41:33Z ford $
2849+ #
2850+ #========================================================================
2851+
2852+ package Pod::POM::Node::Head3;
2853+
2854+ use strict;
2855+
2856+ use parent qw( Pod::POM::Node );
2857+ use vars qw( %ATTRIBS @ACCEPT $ERROR );
2858+
2859+ %ATTRIBS = ( title => undef );
2860+ @ACCEPT = qw( head4 over begin for text verbatim code );
2861+
2862+ sub new {
2863+ my ($class, $pom, $title) = @_;
2864+ $title = $pom->parse_sequence($title)
2865+ || return $class->error($pom->error())
2866+ if length $title;
2867+ return $class->SUPER::new($pom, $title);
2868+ }
2869+
2870+ 1;
2871+
2872+ =head1 NAME
2873+
2874+ Pod::POM::Node::Head3 -
2875+
2876+ =head1 SYNOPSIS
2877+
2878+ use Pod::POM::Nodes;
2879+
2880+ =head1 DESCRIPTION
2881+
2882+ This module implements a specialization of the node class to represent C<=head3> elements.
2883+
2884+ =head1 AUTHOR
2885+
2886+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
2887+
2888+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2889+
2890+ =head1 COPYRIGHT
2891+
2892+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2893+
2894+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2895+
2896+ This module is free software; you can redistribute it and/or
2897+ modify it under the same terms as Perl itself.
2898+
2899+ =head1 SEE ALSO
2900+
2901+ Consult L<Pod::POM::Node> for a discussion of nodes.
2902+POD_POM_NODE_HEAD3
2903+
2904+$fatpacked{"Pod/POM/Node/Head4.pm"} = <<'POD_POM_NODE_HEAD4';
2905+ #============================================================= -*-Perl-*-
2906+ #
2907+ # Pod::POM::Node::Head4
2908+ #
2909+ # DESCRIPTION
2910+ # Module implementing specific nodes in a Pod::POM, subclassed from
2911+ # Pod::POM::Node.
2912+ #
2913+ # AUTHOR
2914+ # Andy Wardley <abw@kfs.org>
2915+ # Andrew Ford <a.ford@ford-mason.co.uk>
2916+ #
2917+ # COPYRIGHT
2918+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2919+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2920+ #
2921+ # This module is free software; you can redistribute it and/or
2922+ # modify it under the same terms as Perl itself.
2923+ #
2924+ # REVISION
2925+ # $Id: Head4.pm 76 2009-08-20 20:41:33Z ford $
2926+ #
2927+ #========================================================================
2928+
2929+ package Pod::POM::Node::Head4;
2930+
2931+ use strict;
2932+
2933+ use parent qw( Pod::POM::Node );
2934+ use vars qw( %ATTRIBS @ACCEPT $ERROR );
2935+
2936+ %ATTRIBS = ( title => undef );
2937+ @ACCEPT = qw( over begin for text verbatim code );
2938+
2939+ sub new {
2940+ my ($class, $pom, $title) = @_;
2941+ $title = $pom->parse_sequence($title)
2942+ || return $class->error($pom->error())
2943+ if length $title;
2944+ return $class->SUPER::new($pom, $title);
2945+ }
2946+
2947+ 1;
2948+
2949+ =head1 NAME
2950+
2951+ Pod::POM::Node::Head4 -
2952+
2953+ =head1 SYNOPSIS
2954+
2955+ use Pod::POM::Nodes;
2956+
2957+ =head1 DESCRIPTION
2958+
2959+ This module implements a specialization of the node class to represent C<=head4> elements.
2960+
2961+ =head1 AUTHOR
2962+
2963+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
2964+
2965+ Andy Wardley E<lt>abw@kfs.orgE<gt>
2966+
2967+ =head1 COPYRIGHT
2968+
2969+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2970+
2971+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2972+
2973+ This module is free software; you can redistribute it and/or
2974+ modify it under the same terms as Perl itself.
2975+
2976+ =head1 SEE ALSO
2977+
2978+ Consult L<Pod::POM::Node> for a discussion of nodes.
2979+POD_POM_NODE_HEAD4
2980+
2981+$fatpacked{"Pod/POM/Node/Item.pm"} = <<'POD_POM_NODE_ITEM';
2982+ #============================================================= -*-Perl-*-
2983+ #
2984+ # Pod::POM::Nodes
2985+ #
2986+ # DESCRIPTION
2987+ # Module implementing specific nodes in a Pod::POM, subclassed from
2988+ # Pod::POM::Node.
2989+ #
2990+ # AUTHOR
2991+ # Andy Wardley <abw@kfs.org>
2992+ # Andrew Ford <a.ford@ford-mason.co.uk>
2993+ #
2994+ # COPYRIGHT
2995+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
2996+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
2997+ #
2998+ # This module is free software; you can redistribute it and/or
2999+ # modify it under the same terms as Perl itself.
3000+ #
3001+ # REVISION
3002+ # $Id: Item.pm 76 2009-08-20 20:41:33Z ford $
3003+ #
3004+ #========================================================================
3005+
3006+ package Pod::POM::Node::Item;
3007+
3008+ use strict;
3009+
3010+ use parent qw( Pod::POM::Node );
3011+ use vars qw( %ATTRIBS @ACCEPT $ERROR );
3012+
3013+ %ATTRIBS = ( title => '*' );
3014+ @ACCEPT = qw( over begin for text verbatim code );
3015+
3016+ sub new {
3017+ my ($class, $pom, $title) = @_;
3018+ $title = $pom->parse_sequence($title)
3019+ || return $class->error($pom->error())
3020+ if length $title;
3021+ return $class->SUPER::new($pom, $title);
3022+ }
3023+
3024+ 1;
3025+
3026+ =head1 NAME
3027+
3028+ Pod::POM::Node::Item -
3029+
3030+ =head1 SYNOPSIS
3031+
3032+ use Pod::POM::Nodes;
3033+
3034+ =head1 DESCRIPTION
3035+
3036+ This module implements a specialization of the node class to represent C<=item> elements.
3037+
3038+ =head1 AUTHOR
3039+
3040+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
3041+
3042+ Andy Wardley E<lt>abw@kfs.orgE<gt>
3043+
3044+ =head1 COPYRIGHT
3045+
3046+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3047+
3048+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3049+
3050+ This module is free software; you can redistribute it and/or
3051+ modify it under the same terms as Perl itself.
3052+
3053+ =head1 SEE ALSO
3054+
3055+ Consult L<Pod::POM::Node> for a discussion of nodes.
3056+POD_POM_NODE_ITEM
3057+
3058+$fatpacked{"Pod/POM/Node/Over.pm"} = <<'POD_POM_NODE_OVER';
3059+ #============================================================= -*-Perl-*-
3060+ #
3061+ # Pod::POM::Node::Over
3062+ #
3063+ # DESCRIPTION
3064+ # Module implementing specific nodes in a Pod::POM, subclassed from
3065+ # Pod::POM::Node.
3066+ #
3067+ # AUTHOR
3068+ # Andy Wardley <abw@kfs.org>
3069+ # Andrew Ford <a.ford@ford-mason.co.uk>
3070+ #
3071+ # COPYRIGHT
3072+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3073+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3074+ #
3075+ # This module is free software; you can redistribute it and/or
3076+ # modify it under the same terms as Perl itself.
3077+ #
3078+ # REVISION
3079+ # $Id: Over.pm 76 2009-08-20 20:41:33Z ford $
3080+ #
3081+ #========================================================================
3082+
3083+ package Pod::POM::Node::Over;
3084+
3085+ use strict;
3086+
3087+ use parent qw( Pod::POM::Node );
3088+ use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR );
3089+
3090+ %ATTRIBS = ( indent => 4 );
3091+ @ACCEPT = qw( over item begin for text verbatim code );
3092+ $EXPECT = 'back';
3093+
3094+ sub list_type {
3095+ my $self = shift;
3096+ my ($first, @rest) = $self->content;
3097+
3098+ my $first_type = $first->type;
3099+ return;
3100+ }
3101+
3102+
3103+ 1;
3104+
3105+ =head1 NAME
3106+
3107+ Pod::POM::Node::Over - POM '=over' node class
3108+
3109+ =head1 SYNOPSIS
3110+
3111+ use Pod::POM::Nodes;
3112+
3113+ =head1 DESCRIPTION
3114+
3115+ This class implements '=over' Pod nodes. As described by the L<perlpodspec> man page =over/=back regions are
3116+ used for various kinds of list-like structures (including blockquote paragraphs).
3117+
3118+ =item 1.
3119+
3120+ ordered list
3121+
3122+ =item *
3123+
3124+ text paragraph
3125+
3126+ unordered list
3127+
3128+ =item text
3129+
3130+ text paragraph
3131+
3132+ definition list
3133+
3134+
3135+
3136+ =head1 AUTHOR
3137+
3138+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
3139+
3140+ Andy Wardley E<lt>abw@kfs.orgE<gt>
3141+
3142+ =head1 COPYRIGHT
3143+
3144+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3145+
3146+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3147+
3148+ This module is free software; you can redistribute it and/or
3149+ modify it under the same terms as Perl itself.
3150+
3151+ =head1 SEE ALSO
3152+
3153+ Consult L<Pod::POM::Node> for a discussion of nodes.
3154+POD_POM_NODE_OVER
3155+
3156+$fatpacked{"Pod/POM/Node/Pod.pm"} = <<'POD_POM_NODE_POD';
3157+ #============================================================= -*-Perl-*-
3158+ #
3159+ # Pod::POM::Node::Pod
3160+ #
3161+ # DESCRIPTION
3162+ # Module implementing specific nodes in a Pod::POM, subclassed from
3163+ # Pod::POM::Node.
3164+ #
3165+ # AUTHOR
3166+ # Andy Wardley <abw@kfs.org>
3167+ # Andrew Ford <a.ford@ford-mason.co.uk>
3168+ #
3169+ # COPYRIGHT
3170+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3171+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3172+ #
3173+ # This module is free software; you can redistribute it and/or
3174+ # modify it under the same terms as Perl itself.
3175+ #
3176+ # REVISION
3177+ # $Id: Pod.pm 76 2009-08-20 20:41:33Z ford $
3178+ #
3179+ #========================================================================
3180+
3181+ package Pod::POM::Node::Pod;
3182+
3183+ use strict;
3184+
3185+ use parent qw( Pod::POM::Node );
3186+ use vars qw( @ACCEPT $ERROR );
3187+
3188+ @ACCEPT = qw( head1 head2 head3 head4 over begin for text verbatim code );
3189+
3190+ 1;
3191+
3192+ =head1 NAME
3193+
3194+ Pod::POM::Node::Pod -
3195+
3196+ =head1 SYNOPSIS
3197+
3198+ use Pod::POM::Nodes;
3199+
3200+ =head1 DESCRIPTION
3201+
3202+ This module implements a specialization of the node class to represent C<=pod> elements.
3203+
3204+ =head1 AUTHOR
3205+
3206+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
3207+
3208+ Andy Wardley E<lt>abw@kfs.orgE<gt>
3209+
3210+ =head1 COPYRIGHT
3211+
3212+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3213+
3214+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3215+
3216+ This module is free software; you can redistribute it and/or
3217+ modify it under the same terms as Perl itself.
3218+
3219+ =head1 SEE ALSO
3220+
3221+ Consult L<Pod::POM::Node> for a discussion of nodes.
3222+POD_POM_NODE_POD
3223+
3224+$fatpacked{"Pod/POM/Node/Sequence.pm"} = <<'POD_POM_NODE_SEQUENCE';
3225+ #============================================================= -*-Perl-*-
3226+ #
3227+ # Pod::POM::Node::Sequence
3228+ #
3229+ # DESCRIPTION
3230+ # Module implementing specific nodes in a Pod::POM, subclassed from
3231+ # Pod::POM::Node.
3232+ #
3233+ # AUTHOR
3234+ # Andy Wardley <abw@kfs.org>
3235+ # Andrew Ford <a.ford@ford-mason.co.uk>
3236+ #
3237+ # COPYRIGHT
3238+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3239+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3240+ #
3241+ # This module is free software; you can redistribute it and/or
3242+ # modify it under the same terms as Perl itself.
3243+ #
3244+ # REVISION
3245+ # $Id: Sequence.pm 76 2009-08-20 20:41:33Z ford $
3246+ #
3247+ #========================================================================
3248+
3249+ package Pod::POM::Node::Sequence;
3250+
3251+ use strict;
3252+
3253+ use Pod::POM::Constants qw( :all );
3254+ use parent qw( Pod::POM::Node );
3255+ use vars qw( %NAME );
3256+
3257+ %NAME = (
3258+ C => 'code',
3259+ B => 'bold',
3260+ I => 'italic',
3261+ L => 'link',
3262+ S => 'space',
3263+ F => 'file',
3264+ X => 'index',
3265+ Z => 'zero',
3266+ E => 'entity',
3267+ );
3268+
3269+ sub new {
3270+ my ($class, $self) = @_;
3271+ local $" = '] [';
3272+ return bless \$self, $class;
3273+ }
3274+
3275+ sub add {
3276+ return IGNORE;
3277+ }
3278+
3279+ sub present {
3280+ my ($self, $view) = @_;
3281+ my ($cmd, $method, $result);
3282+ $view ||= $Pod::POM::DEFAULT_VIEW;
3283+
3284+ $self = $$self;
3285+ return $self unless ref $self eq 'ARRAY';
3286+
3287+ my $text = join('',
3288+ map { ref $_ ? $_->present($view)
3289+ : $view->view_seq_text($_) }
3290+ @{ $self->[CONTENT] });
3291+
3292+ if ($cmd = $self->[CMD]) {
3293+ my $method = $NAME{ $cmd } || $cmd;
3294+ $method = "view_seq_$method";
3295+ return $view->$method($text);
3296+ }
3297+ else {
3298+ return $text;
3299+ }
3300+ }
3301+
3302+ 1;
3303+
3304+ =head1 NAME
3305+
3306+ Pod::POM::Node::Sequence -
3307+
3308+ =head1 SYNOPSIS
3309+
3310+ use Pod::POM::Nodes;
3311+
3312+ =head1 DESCRIPTION
3313+
3314+ This module implements a specialization of the node class to represent sequence elements.
3315+
3316+ =head1 AUTHOR
3317+
3318+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
3319+
3320+ Andy Wardley E<lt>abw@kfs.orgE<gt>
3321+
3322+ =head1 COPYRIGHT
3323+
3324+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3325+
3326+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3327+
3328+ This module is free software; you can redistribute it and/or
3329+ modify it under the same terms as Perl itself.
3330+
3331+ =head1 SEE ALSO
3332+
3333+ Consult L<Pod::POM::Node> for a discussion of nodes.
3334+POD_POM_NODE_SEQUENCE
3335+
3336+$fatpacked{"Pod/POM/Node/Text.pm"} = <<'POD_POM_NODE_TEXT';
3337+ #============================================================= -*-Perl-*-
3338+ #
3339+ # Pod::POM::Node::Text
3340+ #
3341+ # DESCRIPTION
3342+ # Module implementing specific nodes in a Pod::POM, subclassed from
3343+ # Pod::POM::Node.
3344+ #
3345+ # AUTHOR
3346+ # Andy Wardley <abw@kfs.org>
3347+ # Andrew Ford <a.ford@ford-mason.co.uk>
3348+ #
3349+ # COPYRIGHT
3350+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3351+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3352+ #
3353+ # This module is free software; you can redistribute it and/or
3354+ # modify it under the same terms as Perl itself.
3355+ #
3356+ # REVISION
3357+ # $Id: Text.pm 76 2009-08-20 20:41:33Z ford $
3358+ #
3359+ #========================================================================
3360+
3361+ package Pod::POM::Node::Text;
3362+
3363+ use strict;
3364+
3365+ use Pod::POM::Constants qw( :all );
3366+ use parent qw( Pod::POM::Node );
3367+ use vars qw( %ATTRIBS $ERROR );
3368+
3369+ %ATTRIBS = ( text => '' );
3370+
3371+ sub new {
3372+ my $class = shift;
3373+ my $pom = shift;
3374+ my $text = shift;
3375+ $text = $pom->parse_sequence($text)
3376+ || return $class->error($pom->error())
3377+ if length $text && ! $pom->{in_begin};
3378+ return $class->SUPER::new($pom, $text);
3379+ }
3380+
3381+ sub add {
3382+ return IGNORE;
3383+ }
3384+
3385+ sub present {
3386+ my ($self, $view) = @_;
3387+ my $text = $self->{ text };
3388+ $view ||= $Pod::POM::DEFAULT_VIEW;
3389+
3390+ $text = $text->present($view)
3391+ if ref $text;
3392+
3393+ return $view->view_textblock($text);
3394+ }
3395+
3396+ 1;
3397+
3398+ =head1 NAME
3399+
3400+ Pod::POM::Node::Text -
3401+
3402+ =head1 SYNOPSIS
3403+
3404+ use Pod::POM::Nodes;
3405+
3406+ =head1 DESCRIPTION
3407+
3408+ This module implements a specialization of the node class to represent text elements.
3409+
3410+ =head1 AUTHOR
3411+
3412+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
3413+
3414+ Andy Wardley E<lt>abw@kfs.orgE<gt>
3415+
3416+ =head1 COPYRIGHT
3417+
3418+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3419+
3420+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3421+
3422+ This module is free software; you can redistribute it and/or
3423+ modify it under the same terms as Perl itself.
3424+
3425+ =head1 SEE ALSO
3426+
3427+ Consult L<Pod::POM::Node> for a discussion of nodes.
3428+POD_POM_NODE_TEXT
3429+
3430+$fatpacked{"Pod/POM/Node/Verbatim.pm"} = <<'POD_POM_NODE_VERBATIM';
3431+ #============================================================= -*-Perl-*-
3432+ #
3433+ # Pod::POM::Node::Verbatim
3434+ #
3435+ # DESCRIPTION
3436+ # Module implementing specific nodes in a Pod::POM, subclassed from
3437+ # Pod::POM::Node.
3438+ #
3439+ # AUTHOR
3440+ # Andy Wardley <abw@kfs.org>
3441+ # Andrew Ford <a.ford@ford-mason.co.uk>
3442+ #
3443+ # COPYRIGHT
3444+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3445+ # Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3446+ #
3447+ # This module is free software; you can redistribute it and/or
3448+ # modify it under the same terms as Perl itself.
3449+ #
3450+ # REVISION
3451+ # $Id: Verbatim.pm 76 2009-08-20 20:41:33Z ford $
3452+ #
3453+ #========================================================================
3454+
3455+ package Pod::POM::Node::Verbatim;
3456+
3457+ use strict;
3458+
3459+ use parent qw( Pod::POM::Node );
3460+ use vars qw( %ATTRIBS $ERROR );
3461+
3462+ %ATTRIBS = ( text => '' );
3463+
3464+ sub present {
3465+ my ($self, $view) = @_;
3466+ $view ||= $Pod::POM::DEFAULT_VIEW;
3467+ return $view->view_verbatim($self->{ text });
3468+ }
3469+
3470+ 1;
3471+
3472+ =head1 NAME
3473+
3474+ Pod::POM::Node::Verbatim -
3475+
3476+ =head1 SYNOPSIS
3477+
3478+ use Pod::POM::Nodes;
3479+
3480+ =head1 DESCRIPTION
3481+
3482+ This module implements a specialization of the node class to represent verbatim elements.
3483+
3484+ =head1 AUTHOR
3485+
3486+ Andrew Ford E<lt>a.ford@ford-mason.co.ukE<gt>
3487+
3488+ Andy Wardley E<lt>abw@kfs.orgE<gt>
3489+
3490+ =head1 COPYRIGHT
3491+
3492+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3493+
3494+ Copyright (C) 2009 Andrew Ford. All Rights Reserved.
3495+
3496+ This module is free software; you can redistribute it and/or
3497+ modify it under the same terms as Perl itself.
3498+
3499+ =head1 SEE ALSO
3500+
3501+ Consult L<Pod::POM::Node> for a discussion of nodes.
3502+POD_POM_NODE_VERBATIM
3503+
3504+$fatpacked{"Pod/POM/Nodes.pm"} = <<'POD_POM_NODES';
3505+ #============================================================= -*-Perl-*-
3506+ #
3507+ # Pod::POM::Nodes
3508+ #
3509+ # DESCRIPTION
3510+ # Module implementing specific nodes in a Pod::POM, subclassed from
3511+ # Pod::POM::Node.
3512+ #
3513+ # AUTHOR
3514+ # Andy Wardley <abw@kfs.org>
3515+ #
3516+ # COPYRIGHT
3517+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3518+ #
3519+ # This module is free software; you can redistribute it and/or
3520+ # modify it under the same terms as Perl itself.
3521+ #
3522+ # REVISION
3523+ # $Id: Nodes.pm 76 2009-08-20 20:41:33Z ford $
3524+ #
3525+ #========================================================================
3526+
3527+ package Pod::POM::Nodes;
3528+
3529+ require 5.004;
3530+ require Exporter;
3531+
3532+ use strict;
3533+
3534+ use Pod::POM::Node::Pod;
3535+ use Pod::POM::Node::Head1;
3536+ use Pod::POM::Node::Head2;
3537+ use Pod::POM::Node::Head3;
3538+ use Pod::POM::Node::Head4;
3539+ use Pod::POM::Node::Over;
3540+ use Pod::POM::Node::Item;
3541+ use Pod::POM::Node::Begin;
3542+ use Pod::POM::Node::For;
3543+ use Pod::POM::Node::Verbatim;
3544+ use Pod::POM::Node::Code;
3545+ use Pod::POM::Node::Text;
3546+ use Pod::POM::Node::Sequence;
3547+ use Pod::POM::Node::Content;
3548+
3549+
3550+ use vars qw( $VERSION $DEBUG $ERROR @EXPORT_OK @EXPORT_FAIL );
3551+ use base qw( Exporter );
3552+
3553+ $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
3554+ $DEBUG = 0 unless defined $DEBUG;
3555+
3556+ 1;
3557+
3558+ =head1 NAME
3559+
3560+ Pod::POM::Nodes - convenience class to load all node classes
3561+
3562+ =head1 SYNOPSIS
3563+
3564+ use Pod::POM::Nodes;
3565+
3566+ =head1 DESCRIPTION
3567+
3568+ This module implements a convenience class that simply uses all of the subclasses of Pod::POM::Node.
3569+ (It used to include all the individual classes inline, but the node classes have been factored out
3570+ into individual modules.)
3571+
3572+ =head1 AUTHOR
3573+
3574+ Andy Wardley E<lt>abw@kfs.orgE<gt>
3575+
3576+ =head1 COPYRIGHT
3577+
3578+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3579+
3580+ This module is free software; you can redistribute it and/or
3581+ modify it under the same terms as Perl itself.
3582+
3583+ =head1 SEE ALSO
3584+
3585+ Consult L<Pod::POM> for a general overview and examples of use.
3586+
3587+POD_POM_NODES
3588+
3589+$fatpacked{"Pod/POM/Test.pm"} = <<'POD_POM_TEST';
3590+ #============================================================= -*-Perl-*-
3591+ #
3592+ # Pod::POM::Test
3593+ #
3594+ # DESCRIPTION
3595+ # Module implementing some useful subroutines for testing.
3596+ #
3597+ # AUTHOR
3598+ # Andy Wardley <abw@kfs.org>
3599+ #
3600+ # COPYRIGHT
3601+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3602+ #
3603+ # This module is free software; you can redistribute it and/or
3604+ # modify it under the same terms as Perl itself.
3605+ #
3606+ # REVISION
3607+ # $Id: Test.pm 14 2009-03-13 08:19:40Z ford $
3608+ #
3609+ #========================================================================
3610+
3611+ package Pod::POM::Test;
3612+
3613+ require 5.004;
3614+
3615+ use strict;
3616+ use Pod::POM;
3617+ use base qw( Exporter );
3618+ use vars qw( $VERSION @EXPORT );
3619+
3620+ $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
3621+ @EXPORT = qw( ntests ok match assert );
3622+
3623+ my $ok_count;
3624+
3625+ sub ntests {
3626+ my $ntests = shift;
3627+ $ok_count = 1;
3628+ print "1..$ntests\n";
3629+ }
3630+
3631+ sub ok {
3632+ my ($ok, $msg) = @_;
3633+ if ($ok) {
3634+ print "ok ", $ok_count++, "\n";
3635+ }
3636+ else {
3637+ print "FAILED $ok_count: $msg\n" if defined $msg;
3638+ print "not ok ", $ok_count++, "\n";
3639+ }
3640+ }
3641+
3642+ sub assert {
3643+ my ($ok, $err) = @_;
3644+ return ok(1) if $ok;
3645+
3646+ # failed
3647+ my ($pkg, $file, $line) = caller();
3648+ $err ||= "assert failed";
3649+ $err .= " at $file line $line\n";
3650+ ok(0);
3651+ die $err;
3652+ }
3653+
3654+
3655+ sub match {
3656+ my ($result, $expect) = @_;
3657+
3658+ # force stringification of $result to avoid 'no eq method' overload errors
3659+ $result = "$result" if ref $result;
3660+
3661+ if ($result eq $expect) {
3662+ ok(1);
3663+ }
3664+ else {
3665+ print "FAILED $ok_count:\n expect: [$expect]\n result: [$result]\n";
3666+ ok(0);
3667+ }
3668+ }
3669+
3670+
3671+ 1;
3672+POD_POM_TEST
3673+
3674+$fatpacked{"Pod/POM/View.pm"} = <<'POD_POM_VIEW';
3675+ #============================================================= -*-Perl-*-
3676+ #
3677+ # Pod::POM::View
3678+ #
3679+ # DESCRIPTION
3680+ # Visitor class for creating a view of all or part of a Pod Object
3681+ # Model.
3682+ #
3683+ # AUTHOR
3684+ # Andy Wardley <abw@kfs.org>
3685+ #
3686+ # COPYRIGHT
3687+ # Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3688+ #
3689+ # This module is free software; you can redistribute it and/or
3690+ # modify it under the same terms as Perl itself.
3691+ #
3692+ # REVISION
3693+ # $Id: View.pm 32 2009-03-17 21:08:25Z ford $
3694+ #
3695+ #========================================================================
3696+
3697+ package Pod::POM::View;
3698+
3699+ require 5.004;
3700+
3701+ use strict;
3702+ use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $INSTANCE );
3703+
3704+ $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
3705+ $DEBUG = 0 unless defined $DEBUG;
3706+
3707+
3708+ #------------------------------------------------------------------------
3709+ # new($pom)
3710+ #------------------------------------------------------------------------
3711+
3712+ sub new {
3713+ my $class = shift;
3714+ my $args = ref $_[0] eq 'HASH' ? shift : { @_ };
3715+ bless { %$args }, $class;
3716+ }
3717+
3718+
3719+ sub print {
3720+ my ($self, $item) = @_;
3721+ return UNIVERSAL::can($item, 'present')
3722+ ? $item->present($self) : $item;
3723+ }
3724+
3725+
3726+ sub view {
3727+ my ($self, $type, $node) = @_;
3728+ return $node;
3729+ }
3730+
3731+
3732+ sub instance {
3733+ my $self = shift;
3734+ my $class = ref $self || $self;
3735+
3736+ no strict 'refs';
3737+ my $instance = \${"$class\::_instance"};
3738+
3739+ defined $$instance
3740+ ? $$instance
3741+ : ($$instance = $class->new(@_));
3742+ }
3743+
3744+
3745+ sub visit {
3746+ my ($self, $place) = @_;
3747+ $self = $self->instance() unless ref $self;
3748+ my $visit = $self->{ VISIT } ||= [ ];
3749+ push(@$visit, $place);
3750+ return $place;
3751+ }
3752+
3753+
3754+ sub leave {
3755+ my ($self, $place) = @_;
3756+ $self = $self->instance() unless ref $self;
3757+ my $visit = $self->{ VISIT };
3758+ return $self->error('empty VISIT stack') unless @$visit;
3759+ pop(@$visit);
3760+ }
3761+
3762+
3763+ sub visiting {
3764+ my ($self, $place) = @_;
3765+ $self = $self->instance() unless ref $self;
3766+ my $visit = $self->{ VISIT };
3767+ return 0 unless $visit && @$visit;
3768+
3769+ foreach (reverse @$visit) {
3770+ return 1 if $_ eq $place;
3771+ }
3772+ return 0;
3773+ }
3774+
3775+
3776+ sub AUTOLOAD {
3777+ my $self = shift;
3778+ my $name = $AUTOLOAD;
3779+ my $item;
3780+
3781+ $name =~ s/.*:://;
3782+ return if $name eq 'DESTROY';
3783+
3784+ if ($name =~ s/^view_//) {
3785+ return $self->view($name, @_);
3786+ }
3787+ elsif (! ref $self) {
3788+ die "can't access $name in $self\n";
3789+ }
3790+ else {
3791+ die "no such method for $self: $name ($AUTOLOAD)"
3792+ unless defined ($item = $self->{ $name });
3793+
3794+ return wantarray ? ( ref $item eq 'ARRAY' ? @$item : $item ) : $item;
3795+ }
3796+ }
3797+
3798+
3799+ 1;
3800+
3801+ =head1 NAME
3802+
3803+ Pod::POM::View
3804+
3805+ =head1 DESCRIPTION
3806+
3807+ Visitor class for creating a view of all or part of a Pod Object Model.
3808+
3809+ =head1 METHODS
3810+
3811+ =over 4
3812+
3813+ =item C<new>
3814+
3815+ =item C<print>
3816+
3817+ =item C<view>
3818+
3819+ =item C<instance>
3820+
3821+ =item C<visit>
3822+
3823+ =item C<leave>
3824+
3825+ =item C<visiting>
3826+
3827+ =back
3828+
3829+ =head1 AUTHOR
3830+
3831+ Andy Wardley E<lt>abw@kfs.orgE<gt>
3832+
3833+ =head1 COPYRIGHT AND LICENSE
3834+
3835+ Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved.
3836+
3837+ This module is free software; you can redistribute it and/or
3838+ modify it under the same terms as Perl itself.
3839+
3840+ =cut
3841+POD_POM_VIEW
3842+
3843+$fatpacked{"Pod/POM/View/HTML.pm"} = <<'POD_POM_VIEW_HTML';
3844+ #============================================================= -*-Perl-*-
3845+ #
3846+ # Pod::POM::View::HTML
3847+ #
3848+ # DESCRIPTION
3849+ # HTML view of a Pod Object Model.
3850+ #
3851+ # AUTHOR
3852+ # Andy Wardley <abw@kfs.org>
3853+ #
3854+ # COPYRIGHT
3855+ # Copyright (C) 2000 Andy Wardley. All Rights Reserved.
3856+ #
3857+ # This module is free software; you can redistribute it and/or
3858+ # modify it under the same terms as Perl itself.
3859+ #
3860+ # REVISION
3861+ # $Id: HTML.pm 84 2009-08-20 21:07:00Z ford $
3862+ #
3863+ #========================================================================
3864+
3865+ package Pod::POM::View::HTML;
3866+
3867+ require 5.004;
3868+
3869+ use strict;
3870+ use Pod::POM::View;
3871+ use parent qw( Pod::POM::View );
3872+ use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD );
3873+ use Text::Wrap;
3874+
3875+ $VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);
3876+ $DEBUG = 0 unless defined $DEBUG;
3877+ my $HTML_PROTECT = 0;
3878+ my @OVER;
3879+
3880+ sub new {
3881+ my $class = shift;
3882+ my $self = $class->SUPER::new(@_)
3883+ || return;
3884+
3885+ # initalise stack for maintaining info for nested lists
3886+ $self->{ OVER } = [];
3887+
3888+ return $self;
3889+ }
3890+
3891+
3892+ sub view {
3893+ my ($self, $type, $item) = @_;
3894+
3895+ if ($type =~ s/^seq_//) {
3896+ return $item;
3897+ }
3898+ elsif (UNIVERSAL::isa($item, 'HASH')) {
3899+ if (defined $item->{ content }) {
3900+ return $item->{ content }->present($self);
3901+ }
3902+ elsif (defined $item->{ text }) {
3903+ my $text = $item->{ text };
3904+ return ref $text ? $text->present($self) : $text;
3905+ }
3906+ else {
3907+ return '';
3908+ }
3909+ }
3910+ elsif (! ref $item) {
3911+ return $item;
3912+ }
3913+ else {
3914+ return '';
3915+ }
3916+ }
3917+
3918+
3919+ sub view_pod {
3920+ my ($self, $pod) = @_;
3921+ return "<html>\n<body bgcolor=\"#ffffff\">\n"
3922+ . $pod->content->present($self)
3923+ . "</body>\n</html>\n";
3924+ }
3925+
3926+
3927+ sub view_head1 {
3928+ my ($self, $head1) = @_;
3929+ my $title = $head1->title->present($self);
3930+ return "<h1>$title</h1>\n\n"
3931+ . $head1->content->present($self);
3932+ }
3933+
3934+
3935+ sub view_head2 {
3936+ my ($self, $head2) = @_;
3937+ my $title = $head2->title->present($self);
3938+ return "<h2>$title</h2>\n"
3939+ . $head2->content->present($self);
3940+ }
3941+
3942+
3943+ sub view_head3 {
3944+ my ($self, $head3) = @_;
3945+ my $title = $head3->title->present($self);
3946+ return "<h3>$title</h3>\n"
3947+ . $head3->content->present($self);
3948+ }
3949+
3950+
3951+ sub view_head4 {
3952+ my ($self, $head4) = @_;
3953+ my $title = $head4->title->present($self);
3954+ return "<h4>$title</h4>\n"
3955+ . $head4->content->present($self);
3956+ }
3957+
3958+
3959+ sub view_over {
3960+ my ($self, $over) = @_;
3961+ my ($start, $end, $strip);
3962+ my $items = $over->item();
3963+
3964+ if (@$items) {
3965+
3966+ my $first_title = $items->[0]->title();
3967+
3968+ if ($first_title =~ /^\s*\*\s*/) {
3969+ # '=item *' => <ul>
3970+ $start = "<ul>\n";
3971+ $end = "</ul>\n";
3972+ $strip = qr/^\s*\*\s*/;
3973+ }
3974+ elsif ($first_title =~ /^\s*\d+\.?\s*/) {
3975+ # '=item 1.' or '=item 1 ' => <ol>
3976+ $start = "<ol>\n";
3977+ $end = "</ol>\n";
3978+ $strip = qr/^\s*\d+\.?\s*/;
3979+ }
3980+ else {
3981+ $start = "<ul>\n";
3982+ $end = "</ul>\n";
3983+ $strip = '';
3984+ }
3985+
3986+ my $overstack = ref $self ? $self->{ OVER } : \@OVER;
3987+ push(@$overstack, $strip);
3988+ my $content = $over->content->present($self);
3989+ pop(@$overstack);
3990+
3991+ return $start
3992+ . $content
3993+ . $end;
3994+ }
3995+ else {
3996+ return "<blockquote>\n"
3997+ . $over->content->present($self)
3998+ . "</blockquote>\n";
3999+ }
4000+ }
4001+
4002+
4003+ sub view_item {
4004+ my ($self, $item) = @_;
4005+
4006+ my $over = ref $self ? $self->{ OVER } : \@OVER;
4007+ my $title = $item->title();
4008+ my $strip = $over->[-1];
4009+
4010+ if (defined $title) {
4011+ $title = $title->present($self) if ref $title;
4012+ $title =~ s/$strip// if $strip;
4013+ if (length $title) {
4014+ my $anchor = $title;
4015+ $anchor =~ s/^\s*|\s*$//g; # strip leading and closing spaces
4016+ $anchor =~ s/\W/_/g;
4017+ $title = qq{<a name="item_$anchor"></a><b>$title</b>};
4018+ }
4019+ }
4020+
4021+ return '<li>'
4022+ . "$title\n"
4023+ . $item->content->present($self)
4024+ . "</li>\n";
4025+ }
4026+
4027+
4028+ sub view_for {
4029+ my ($self, $for) = @_;
4030+ return '' unless $for->format() =~ /\bhtml\b/;
4031+ return $for->text()
4032+ . "\n\n";
4033+ }
4034+
4035+
4036+ sub view_begin {
4037+ my ($self, $begin) = @_;
4038+ return '' unless $begin->format() =~ /\bhtml\b/;
4039+ $HTML_PROTECT++;
4040+ my $output = $begin->content->present($self);
4041+ $HTML_PROTECT--;
4042+ return $output;
4043+ }
4044+
4045+
4046+ sub view_textblock {
4047+ my ($self, $text) = @_;
4048+ return $HTML_PROTECT ? "$text\n" : "<p>$text</p>\n";
4049+ }
4050+
4051+
4052+ sub view_verbatim {
4053+ my ($self, $text) = @_;
4054+ for ($text) {
4055+ s/&/&amp;/g;
4056+ s/</&lt;/g;
4057+ s/>/&gt;/g;
4058+ }
4059+ return "<pre>$text</pre>\n\n";
4060+ }
4061+
4062+
4063+ sub view_seq_bold {
4064+ my ($self, $text) = @_;
4065+ return "<b>$text</b>";
4066+ }
4067+
4068+
4069+ sub view_seq_italic {
4070+ my ($self, $text) = @_;
4071+ return "<i>$text</i>";
4072+ }
4073+
4074+
4075+ sub view_seq_code {
4076+ my ($self, $text) = @_;
4077+ return "<code>$text</code>";
4078+ }
4079+
4080+ sub view_seq_file {
4081+ my ($self, $text) = @_;
4082+ return "<i>$text</i>";
4083+ }
4084+
4085+ sub view_seq_space {
4086+ my ($self, $text) = @_;
4087+ $text =~ s/\s/&nbsp;/g;
4088+ return $text;
4089+ }
4090+
4091+
4092+ sub view_seq_entity {
4093+ my ($self, $entity) = @_;
4094+ return "&$entity;"
4095+ }
4096+
4097+
4098+ sub view_seq_index {
4099+ return '';
4100+ }
4101+
4102+
4103+ sub view_seq_link {
4104+ my ($self, $link) = @_;
4105+
4106+ # view_seq_text has already taken care of L<http://example.com/>
4107+ if ($link =~ /^<a href=/ ) {
4108+ return $link;
4109+ }
4110+
4111+ # full-blown URL's are emitted as-is
4112+ if ($link =~ m{^\w+://}s ) {
4113+ return make_href($link);
4114+ }
4115+
4116+ $link =~ s/\n/ /g; # undo line-wrapped tags
4117+
4118+ my $orig_link = $link;
4119+ my $linktext;
4120+ # strip the sub-title and the following '|' char
4121+ if ( $link =~ s/^ ([^|]+) \| //x ) {
4122+ $linktext = $1;
4123+ }
4124+
4125+ # make sure sections start with a /
4126+ $link =~ s|^"|/"|;
4127+
4128+ my $page;
4129+ my $section;
4130+ if ($link =~ m|^ (.*?) / "? (.*?) "? $|x) { # [name]/"section"
4131+ ($page, $section) = ($1, $2);
4132+ }
4133+ elsif ($link =~ /\s/) { # this must be a section with missing quotes
4134+ ($page, $section) = ('', $link);
4135+ }
4136+ else {
4137+ ($page, $section) = ($link, '');
4138+ }
4139+
4140+ # warning; show some text.
4141+ $linktext = $orig_link unless defined $linktext;
4142+
4143+ my $url = '';
4144+ if (defined $page && length $page) {
4145+ $url = $self->view_seq_link_transform_path($page);
4146+ }
4147+
4148+ # append the #section if exists
4149+ $url .= "#$section" if defined $url and
4150+ defined $section and length $section;
4151+
4152+ return make_href($url, $linktext);
4153+ }
4154+
4155+
4156+ # should be sub-classed if extra transformations are needed
4157+ #
4158+ # for example a sub-class may search for the given page and return a
4159+ # relative path to it.
4160+ #
4161+ # META: where this functionality should be documented? This module
4162+ # doesn't have docs section
4163+ #
4164+ sub view_seq_link_transform_path {
4165+ my($self, $page) = @_;
4166+
4167+ # right now the default transform doesn't check whether the link
4168+ # is not dead (i.e. whether there is a corresponding file.
4169+ # therefore we don't link L<>'s other than L<http://>
4170+ # subclass to change the default (and of course add validation)
4171+
4172+ # this is the minimal transformation that will be required if enabled
4173+ # $page = "$page.html";
4174+ # $page =~ s|::|/|g;
4175+ #print "page $page\n";
4176+ return undef;
4177+ }
4178+
4179+
4180+ sub make_href {
4181+ my($url, $title) = @_;
4182+
4183+ if (!defined $url) {
4184+ return defined $title ? "<i>$title</i>" : '';
4185+ }
4186+
4187+ $title = $url unless defined $title;
4188+ #print "$url, $title\n";
4189+ return qq{<a href="$url">$title</a>};
4190+ }
4191+
4192+
4193+
4194+
4195+ # this code has been borrowed from Pod::Html
4196+ my $urls = '(' . join ('|',
4197+ qw{
4198+ http
4199+ telnet
4200+ mailto
4201+ news
4202+ gopher
4203+ file
4204+ wais
4205+ ftp
4206+ } ) . ')';
4207+ my $ltrs = '\w';
4208+ my $gunk = '/#~:.?+=&%@!\-';
4209+ my $punc = '.:!?\-;';
4210+ my $any = "${ltrs}${gunk}${punc}";
4211+
4212+ sub view_seq_text {
4213+ my ($self, $text) = @_;
4214+
4215+ unless ($HTML_PROTECT) {
4216+ for ($text) {
4217+ s/&/&amp;/g;
4218+ s/</&lt;/g;
4219+ s/>/&gt;/g;
4220+ }
4221+ }
4222+
4223+ $text =~ s{
4224+ \b # start at word boundary
4225+ ( # begin $1 {
4226+ $urls : # need resource and a colon
4227+ (?!:) # Ignore File::, among others.
4228+ [$any] +? # followed by one or more of any valid
4229+ # character, but be conservative and
4230+ # take only what you need to....
4231+ ) # end $1 }
4232+ (?= # look-ahead non-consumptive assertion
4233+ [$punc]* # either 0 or more punctuation followed
4234+ (?: # followed
4235+ [^$any] # by a non-url char
4236+ | # or
4237+ $ # end of the string
4238+ ) #
4239+ | # or else
4240+ $ # then end of the string
4241+ )
4242+ }{<a href="$1">$1</a>}igox;
4243+
4244+ return $text;
4245+ }
4246+
4247+ sub encode {
4248+ my($self,$text) = @_;
4249+ require Encode;
4250+ return Encode::encode("ascii",$text,Encode::FB_XMLCREF());
4251+ }
4252+
4253+ 1;
4254+
4255+ =head1 NAME
4256+
4257+ Pod::POM::View::HTML
4258+
4259+ =head1 DESCRIPTION
4260+
4261+ HTML view of a Pod Object Model.
4262+
4263+ =head1 METHODS
4264+
4265+ =over 4
4266+
4267+ =item C<view($self, $type, $item)>
4268+
4269+ =item C<view_pod($self, $pod)>
4270+
4271+ =item C<view_head1($self, $head1)>
4272+
4273+ =item C<view_head2($self, $head2)>
4274+
4275+ =item C<view_head3($self, $head3)>
4276+
4277+ =item C<view_head4($self, $head4)>
4278+
4279+ =item C<view_over($self, $over)>
4280+
4281+ =item C<view_item($self, $item)>
4282+
4283+ =item C<view_for($self, $for)>
4284+
4285+ =item C<view_begin($self, $begin)>
4286+
4287+ =item C<view_textblock($self, $textblock)>
4288+
4289+ =item C<view_verbatim($self, $verbatim)>
4290+
4291+ =item C<view_meta($self, $meta)>
4292+
4293+ =item C<view_seq_bold($self, $text)>
4294+
4295+ Returns the text of a C<BE<lt>E<gt>> sequence enclosed in a C<E<lt>b<E<gt>> element.
4296+
4297+ =item C<view_seq_italic($self, $text)>
4298+
4299+ Returns the text of a C<IE<lt>E<gt>> sequence enclosed in a C<E<lt>i<E<gt>> element.
4300+
4301+ =item C<view_seq_code($self, $text)>
4302+
4303+ Returns the text of a C<CE<lt>E<gt>> sequence enclosed in a C<E<lt>code<E<gt>> element.
4304+
4305+ =item C<view_seq_file($self, $text)>
4306+
4307+ =item C<view_seq_entity($self, $text)>
4308+
4309+ =item C<view_seq_index($self, $text)>
4310+
4311+ Returns an empty string. Index sequences are suppressed in HTML view.
4312+
4313+ =item C<view_seq_link($self, $text)>
4314+
4315+ =back
4316+
4317+ =head1 AUTHOR
4318+
4319+ Andy Wardley E<lt>abw@kfs.orgE<gt>
4320+
4321+ =head1 COPYRIGHT AND LICENSE
4322+
4323+ Copyright (C) 2000 Andy Wardley. All Rights Reserved.
4324+
4325+ This module is free software; you can redistribute it and/or
4326+ modify it under the same terms as Perl itself.
4327+
4328+ =cut
4329+POD_POM_VIEW_HTML
4330+
4331+$fatpacked{"Pod/POM/View/Pod.pm"} = <<'POD_POM_VIEW_POD';
4332+ #============================================================= -*-Perl-*-
4333+ #
4334+ # Pod::POM::View::Pod
4335+ #
4336+ # DESCRIPTION
4337+ # Pod view of a Pod Object Model.
4338+ #
4339+ # AUTHOR
4340+ # Andy Wardley <abw@kfs.org>
4341+ #
4342+ # COPYRIGHT
4343+ # Copyright (C) 2000 Andy Wardley. All Rights Reserved.
4344+ #
4345+ # This module is free software; you can redistribute it and/or
4346+ # modify it under the same terms as Perl itself.
4347+ #
4348+ # REVISION
4349+ # $Id: Pod.pm 77 2009-08-20 20:44:14Z ford $
4350+ #
4351+ #========================================================================
4352+
4353+ package Pod::POM::View::Pod;
4354+
4355+ require 5.004;
4356+
4357+ use strict;
4358+ use Pod::POM::Nodes;
4359+ use Pod::POM::View;
4360+ use parent qw( Pod::POM::View );
4361+ use vars qw( $VERSION $DEBUG $ERROR $AUTOLOAD $MARKUP );
4362+
4363+ $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
4364+ $DEBUG = 0 unless defined $DEBUG;
4365+
4366+ # create reverse lookup table mapping method name to original sequence
4367+ $MARKUP = {
4368+ map { ( $Pod::POM::Node::Sequence::NAME{ $_ } => $_ ) }
4369+ keys %Pod::POM::Node::Sequence::NAME,
4370+ };
4371+
4372+
4373+ sub view {
4374+ my ($self, $type, $item) = @_;
4375+
4376+ # my ($pkg, $file, $line) = caller;
4377+ # print STDERR "called view ($type) from $file line $line\n";
4378+
4379+ if ($type =~ s/^seq_//) {
4380+ if ($type eq 'text') {
4381+ return "$item";
4382+ }
4383+ if ($type = $MARKUP->{ $type }) {
4384+ if ($item =~ /[<>]/) {
4385+ return "$type<< $item >>";
4386+ }
4387+ else {
4388+ return "$type<$item>";
4389+ }
4390+ }
4391+ }
4392+ elsif (ref $item eq 'HASH') {
4393+ if (defined $item->{ content }) {
4394+ return $item->{ content }->present($self);
4395+ }
4396+ elsif (defined $item->{ text }) {
4397+ my $text = $item->{ text };
4398+ return ref $text ? $text->present($self) : $text;
4399+ }
4400+ else {
4401+ return '';
4402+ }
4403+ }
4404+ elsif (! ref $item) {
4405+ return $item;
4406+ }
4407+ else {
4408+ return '';
4409+ }
4410+ }
4411+
4412+
4413+ sub view_pod {
4414+ my ($self, $pod) = @_;
4415+ # return "=pod\n\n" . $pod->content->present($self) . "=cut\n\n";
4416+ return $pod->content->present($self);
4417+ }
4418+
4419+
4420+ sub view_head1 {
4421+ my ($self, $head1) = @_;
4422+ return '=head1 '
4423+ . $head1->title->present($self)
4424+ . "\n\n"
4425+ . $head1->content->present($self);
4426+ }
4427+
4428+
4429+ sub view_head2 {
4430+ my ($self, $head2) = @_;
4431+ return '=head2 '
4432+ . $head2->title->present($self)
4433+ . "\n\n"
4434+ . $head2->content->present($self);
4435+ }
4436+
4437+
4438+ sub view_head3 {
4439+ my ($self, $head3) = @_;
4440+ return '=head3 '
4441+ . $head3->title->present($self)
4442+ . "\n\n"
4443+ . $head3->content->present($self);
4444+ }
4445+
4446+
4447+ sub view_head4 {
4448+ my ($self, $head4) = @_;
4449+ return '=head4 '
4450+ . $head4->title->present($self)
4451+ . "\n\n"
4452+ . $head4->content->present($self);
4453+ }
4454+
4455+
4456+ sub view_over {
4457+ my ($self, $over) = @_;
4458+ return '=over '
4459+ . $over->indent()
4460+ . "\n\n"
4461+ . $over->content->present($self)
4462+ . "=back\n\n";
4463+ }
4464+
4465+
4466+ sub view_item {
4467+ my ($self, $item) = @_;
4468+
4469+ my $title = $item->title();
4470+ $title = $title->present($self) if ref $title;
4471+ return "=item $title\n\n"
4472+ . $item->content->present($self);
4473+ }
4474+
4475+
4476+ sub view_for {
4477+ my ($self, $for) = @_;
4478+ return '=for '
4479+ . $for->format . ' '
4480+ . $for->text()
4481+ . "\n\n"
4482+ . $for->content->present($self);
4483+ }
4484+
4485+
4486+ sub view_begin {
4487+ my ($self, $begin) = @_;
4488+ return '=begin '
4489+ . $begin->format()
4490+ . "\n\n"
4491+ . $begin->content->present($self)
4492+ . "=end "
4493+ . $begin->format()
4494+ . "\n\n";
4495+ }
4496+
4497+
4498+ sub view_textblock {
4499+ my ($self, $text) = @_;
4500+ return "$text\n\n";
4501+ }
4502+
4503+
4504+ sub view_verbatim {
4505+ my ($self, $text) = @_;
4506+ return "$text\n\n";
4507+ }
4508+
4509+
4510+ sub view_meta {
4511+ my ($self, $meta) = @_;
4512+ return '=meta '
4513+ . $meta->name()
4514+ . "\n\n"
4515+ . $meta->content->present($self)
4516+ . "=end\n\n";
4517+ }
4518+
4519+
4520+ 1;
4521+
4522+ =head1 NAME
4523+
4524+ Pod::POM::View::Pod
4525+
4526+ =head1 DESCRIPTION
4527+
4528+ Pod view of a Pod Object Model.
4529+
4530+ =head1 METHODS
4531+
4532+ =over 4
4533+
4534+ =item C<view($self, $type, $item)>
4535+
4536+ =item C<view_pod($self, $pod)>
4537+
4538+ =item C<view_head1($self, $head1)>
4539+
4540+ =item C<view_head2($self, $head2)>
4541+
4542+ =item C<view_head3($self, $head3)>
4543+
4544+ =item C<view_head4($self, $head4)>
4545+
4546+ =item C<view_over($self, $over)>
4547+
4548+ =item C<view_item($self, $item)>
4549+
4550+ =item C<view_for($self, $for)>
4551+
4552+ =item C<view_begin($self, $begin)>
4553+
4554+ =item C<view_textblock($self, $textblock)>
4555+
4556+ =item C<view_verbatim($self, $verbatim)>
4557+
4558+ =item C<view_meta($self, $meta)>
4559+
4560+ =back
4561+
4562+ =head1 AUTHOR
4563+
4564+ Andy Wardley E<lt>abw@kfs.orgE<gt>
4565+
4566+ =head1 COPYRIGHT AND LICENSE
4567+
4568+ Copyright (C) 2000 Andy Wardley. All Rights Reserved.
4569+
4570+ This module is free software; you can redistribute it and/or
4571+ modify it under the same terms as Perl itself.
4572+
4573+ =cut
4574+POD_POM_VIEW_POD
4575+
4576+$fatpacked{"Pod/POM/View/Restructured.pm"} = <<'POD_POM_VIEW_RESTRUCTURED';
4577+ # Original authors: don
4578+ # $Revision: 1595 $
4579+
4580+ # Copyright (c) 2010 Don Owens <don@regexguy.com>. All rights reserved.
4581+ #
4582+ # This is free software; you can redistribute it and/or modify it under
4583+ # the Perl Artistic license. You should have received a copy of the
4584+ # Artistic license with this distribution, in the file named
4585+ # "Artistic". You may also obtain a copy from
4586+ # http://regexguy.com/license/Artistic
4587+ #
4588+ # This program is distributed in the hope that it will be
4589+ # useful, but WITHOUT ANY WARRANTY; without even the implied
4590+ # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
4591+ # PURPOSE.
4592+
4593+
4594+ =pod
4595+
4596+ =head1 NAME
4597+
4598+ Pod::POM::View::Restructured - View for Pod::POM that outputs reStructuredText
4599+
4600+ =head1 SYNOPSIS
4601+
4602+ use Pod::POM::View::Restructured;
4603+
4604+ my $view = Pod::POM::View::Restructured->new;
4605+ my $parser = Pod::POM->new;
4606+ my $pom = $parser->parse_file("$top_dir/lib/Pod/POM/View/Restructured.pm");
4607+ my $out = $pom->present($view);
4608+
4609+
4610+ =head1 DESCRIPTION
4611+
4612+ This module outputs reStructuredText that is expected to be used
4613+ with Sphinx. Verbatim sections (indented paragraphs) in the POD
4614+ will be output with syntax hilighting for Perl code by default.
4615+ See L</"POD commands specifically for reStructuredText"> for how
4616+ to change this for a particular block.
4617+
4618+ For a list of changes in recent versions, see the documentation
4619+ for L<Pod::POM::View::Restructured::Changes>.
4620+
4621+ This module can be downloaded from L<http://www.cpan.org/authors/id/D/DO/DOWENS/>.
4622+
4623+ =cut
4624+
4625+ use strict;
4626+ use warnings;
4627+ use Data::Dumper ();
4628+
4629+ use Pod::POM;
4630+
4631+ package Pod::POM::View::Restructured;
4632+
4633+ our $VERSION = '0.02'; # change in POD below!
4634+
4635+ use base 'Pod::POM::View::Text';
4636+
4637+ =pod
4638+
4639+ =head1 METHODS
4640+
4641+ =head2 C<new(\%params)>
4642+
4643+ Constructor. \%params is optional. If present, the following keys are valid:
4644+
4645+ =over 4
4646+
4647+ =item C<callbacks>
4648+
4649+ See documentation below for C<convert_file()>.
4650+
4651+ =back
4652+
4653+ =cut
4654+
4655+ sub new {
4656+ my ($class, $params) = @_;
4657+ $params = { } unless $params and UNIVERSAL::isa($params, 'HASH');
4658+
4659+ my $self = bless { seen_something => 0, title_set => 0, params => { } }, ref($class) || $class;
4660+
4661+ my $callbacks = $params->{callbacks};
4662+ $callbacks = { } unless $callbacks;
4663+ $self->{callbacks} = $callbacks;
4664+
4665+ return $self;
4666+ }
4667+
4668+ =pod
4669+
4670+ =head2 C<convert_file($source_file, $title, $dest_file, $callbacks)>
4671+
4672+ Converts the POD in C<$source_file> to reStructuredText. If
4673+ C<$dest_file> is defined, it writes the output there. If
4674+ C<$title> is defined, it is used for the title of the document.
4675+ Otherwise, an attempt is made to infer the title from the NAME
4676+ section (checks if the body looks like C</\A\s*(\w+(?:::\w+)+)\s+-\s+/s>).
4677+
4678+ Returns the output as a string.
4679+
4680+ C<$source_file> and C<$dest_file> can be either file names or file
4681+ handles.
4682+
4683+ =cut
4684+ sub convert_file {
4685+ my ($self, $source_file, $title, $dest_file, $callbacks) = @_;
4686+
4687+ my $cb;
4688+ if ($callbacks) {
4689+ $cb = { %{ $self->{callbacks} }, %$callbacks };
4690+ }
4691+ else {
4692+ $cb = $self->{callbacks};
4693+ }
4694+
4695+ my $view = Pod::POM::View::Restructured->new({ callbacks => $cb });
4696+ my $parser = Pod::POM->new;
4697+
4698+ unless (-r $source_file) {
4699+ warn "can't read source file $source_file";
4700+ return undef;
4701+ }
4702+
4703+ my $pom = $parser->parse_file($source_file);
4704+
4705+ $view->{title_set} = 1 if defined($title);
4706+ my $out = $pom->present($view);
4707+
4708+ if (defined($title)) {
4709+ $out = $self->_build_header($title, '#', 1) . "\n" . $out;
4710+ }
4711+ else {
4712+ $title = $view->{title};
4713+ }
4714+
4715+ if (defined($dest_file) and $dest_file ne '') {
4716+ my $out_fh;
4717+ if (UNIVERSAL::isa($dest_file, 'GLOB')) {
4718+ $out_fh = $dest_file;
4719+ }
4720+ else {
4721+ unless (open($out_fh, '>', $dest_file)) {
4722+ warn "couldn't open output file $dest_file";
4723+ return undef;
4724+ }
4725+ }
4726+
4727+ print $out_fh $out;
4728+ close $out_fh;
4729+ }
4730+
4731+ my $rv = { content => $out, title => $title };
4732+
4733+ return $rv;
4734+ }
4735+
4736+ =pod
4737+
4738+ =head2 C<convert_files($file_spec, $index_file, $index_title, $out_dir)>
4739+
4740+ Converts the files given in C<$file_spec> to reStructuredText.
4741+ If C<$index_file> is provided, it is the path to the index file
4742+ to be created (with a table of contents pointing to all of the
4743+ files created). If C<$index_title> is provided, it is used as
4744+ the section title for the index file. C<$out_dir> is the
4745+ directory the generated files will be written to.
4746+
4747+ C<$file_spec> is a reference to an array of hashes specifying
4748+ attributes for each file to be converted. The valid keys are:
4749+
4750+ =over 4
4751+
4752+ =item C<source_file>
4753+
4754+ File to convert.
4755+
4756+ =item C<dest_file>
4757+
4758+ File to output the reStructuredText. If not provided, a file
4759+ name will be generated based on the title.
4760+
4761+ =item C<title>
4762+
4763+ Section title for the generated reStructuredText. If not
4764+ provided, an attempt will be made to infer the title from the
4765+ NAME section in the POD, if it exists. As a last resort, a title
4766+ will be generated that looks like "section_(\d+)".
4767+
4768+ =item C<callbacks>
4769+
4770+ A reference to a hash containing names and the corresponding callbacks.
4771+
4772+ Currently the only valid callback is C<link>. It is given the
4773+ text inside a LE<lt>E<gt> section from the POD, and is expected to return a
4774+ tuple C<($url, $label)>. If the value returned for C<$label> is
4775+ undefined, the value of C<$url> is used as the label.
4776+
4777+ =item C<no_toc>
4778+
4779+ Causes the item to not be printed to the index or return in the C<toc> field.
4780+
4781+ =back
4782+
4783+ This method returns a hash ref with a table of contents (the
4784+ C<toc> field) suitable for a reStructuredText table of contents.
4785+
4786+ E.g.,
4787+
4788+ my $conv = Pod::POM::View::Restructured->new;
4789+
4790+ my $files = [
4791+ { source_file => "$base_dir/Restructured.pm" },
4792+ { source_file => "$base_dir/DWIW.pm" },
4793+ { source_file => "$base_dir/Wrapper.pm" },
4794+ ];
4795+
4796+
4797+ my $rv = $conv->convert_files($files, "$dest_dir/index.rst", 'My Big Test', $dest_dir);
4798+
4799+
4800+ =cut
4801+ sub convert_files {
4802+ my ($self, $file_spec, $index_file, $index_title, $out_dir) = @_;
4803+
4804+ my $index_fh = $self->_get_file_handle($index_file, '>');
4805+
4806+ if ($index_fh and defined($index_title) and $index_title ne '') {
4807+ my $header = $self->_build_header($index_title, '#', 1);
4808+ # my $line = '#' x length($index_title);
4809+ # my $header = $line . "\n" . $index_title . "\n" . $line . "\n\n";
4810+
4811+ print $index_fh $header;
4812+
4813+ print $index_fh "\nContents:\n\n";
4814+ print $index_fh ".. toctree::\n";
4815+ print $index_fh " :maxdepth: 1\n\n";
4816+ }
4817+
4818+ my $count = 0;
4819+ my $toc = '';
4820+ foreach my $spec (@$file_spec) {
4821+ $count++;
4822+ my $data = $self->convert_file($spec->{source_file}, $spec->{title},
4823+ $spec->{dest_file}, $spec->{callbacks});
4824+
4825+ my $this_title = $data->{title};
4826+ # print STDERR Data::Dumper->Dump([ $this_title ], [ 'this_title' ]) . "\n\n";
4827+
4828+ unless (defined($this_title) and $this_title !~ /\A\s*\Z/) {
4829+ $this_title = 'section_' . $count;
4830+ }
4831+
4832+ my $name = $spec->{dest_file};
4833+ if (defined($name)) {
4834+ $name =~ s/\.rst\Z//;
4835+ }
4836+ else {
4837+ ($name = $this_title) =~ s/\W/_/g;
4838+ my $dest_file = $out_dir . '/' . $name . '.rst';
4839+ my $out_fh;
4840+
4841+ unless (open($out_fh, '>', $dest_file)) {
4842+ warn "couldn't open output file $dest_file";
4843+ return undef;
4844+ }
4845+
4846+ print $out_fh $data->{content};
4847+ close $out_fh;
4848+ }
4849+
4850+ unless ($spec->{no_toc}) {
4851+ $toc .= ' ' . $name . "\n";
4852+ }
4853+
4854+ if ($index_fh and not $spec->{no_toc}) {
4855+ print $index_fh " " . $name . "\n";
4856+ }
4857+ }
4858+
4859+ if ($index_fh) {
4860+ print $index_fh "\n";
4861+ }
4862+
4863+ return { toc => $toc };
4864+ }
4865+
4866+ sub _get_file_handle {
4867+ my ($self, $file, $mode) = @_;
4868+
4869+ return undef unless defined $file;
4870+
4871+ if (ref($file) and UNIVERSAL::isa($file, 'GLOB')) {
4872+ return $file;
4873+ }
4874+
4875+ $mode = '<' unless $mode;
4876+
4877+ my $fh;
4878+ if ($file ne '') {
4879+ unless (open($fh, $mode, $file)) {
4880+ warn "couldn't open input file $file: $!";
4881+ return undef;
4882+ }
4883+ }
4884+
4885+ return $fh;
4886+ }
4887+
4888+ sub view_pod {
4889+ my ($self, $node) = @_;
4890+
4891+ my $content = ".. highlight:: perl\n\n";
4892+
4893+ return $content . $node->content()->present($self);
4894+ }
4895+
4896+ sub _generic_head {
4897+ my ($self, $node, $marker, $do_overline) = @_;
4898+
4899+ return scalar($self->_generic_head_multi($node, $marker, $do_overline));
4900+ }
4901+
4902+ sub _generic_head_multi {
4903+ my ($self, $node, $marker, $do_overline) = @_;
4904+
4905+ my $title = $node->title()->present($self);
4906+ my $content = $node->content()->present($self);
4907+
4908+ $title = ' ' if $title eq '';
4909+ # my $section_line = $marker x length($title);
4910+
4911+ my $section = $self->_build_header($title, $marker, $do_overline) . "\n" . $content;
4912+
4913+ # my $section = $title . "\n" . $section_line . "\n\n" . $content;
4914+ # if ($do_overline) {
4915+ # $section = $section_line . "\n" . $section;
4916+ # }
4917+
4918+ $section .= "\n";
4919+
4920+ return wantarray ? ($section, $content, $title) : $section;
4921+ }
4922+
4923+ sub _build_header {
4924+ my ($self, $text, $marker, $do_overline) = @_;
4925+
4926+ my $line = $marker x length($text);
4927+ my $header = $text . "\n" . $line . "\n";
4928+
4929+ if ($do_overline) {
4930+ $header = $line . "\n" . $header;
4931+ }
4932+
4933+ return "\n" . $header;
4934+ }
4935+
4936+ sub _do_indent {
4937+ my ($self, $text, $indent_amount, $dbg) = @_;
4938+
4939+ my $indent = ' ' x $indent_amount;
4940+
4941+ # $indent = "'$dbg" . $indent . "'";
4942+
4943+ my @lines = split /\n/, $text, -1;
4944+ foreach my $line (@lines) {
4945+ $line = $indent . $line;
4946+ }
4947+
4948+ return join("\n", @lines);
4949+ }
4950+
4951+ sub view_head1 {
4952+ my ($self, $node) = @_;
4953+
4954+ my ($section, $content, $title) = $self->_generic_head_multi($node, '*', 1);
4955+
4956+ unless ($self->{seen_something} or $self->{title_set}) {
4957+ if ($title eq 'NAME') {
4958+ $self->{seen_something} = 1;
4959+
4960+ if ($content =~ /\A\s*(\w+(?:::\w+)+)\s+-\s+/s) {
4961+ my $mod_name = $1;
4962+ $self->{module_name} = $mod_name;
4963+ $self->{title} = $mod_name;
4964+ $self->{title_set} = 1;
4965+
4966+ $section = $self->_build_header($mod_name, '#', 1) . $section;
4967+
4968+ # my $line = '#' x length($mod_name);
4969+ # $section = $line . "\n" . $mod_name . "\n" . $line . "\n\n" . $section;
4970+ }
4971+
4972+ return $section;
4973+ }
4974+ }
4975+
4976+ $self->{seen_something} = 1;
4977+ return $section;
4978+ }
4979+
4980+ sub view_head2 {
4981+ my ($self, $node) = @_;
4982+
4983+ $self->{seen_something} = 1;
4984+ return $self->_generic_head($node, '=');
4985+ }
4986+
4987+ sub view_head3 {
4988+ my ($self, $node) = @_;
4989+
4990+ $self->{seen_something} = 1;
4991+ return $self->_generic_head($node, '-');
4992+ }
4993+
4994+ sub view_head4 {
4995+ my ($self, $node) = @_;
4996+
4997+ $self->{seen_something} = 1;
4998+ return $self->_generic_head($node, '^');
4999+ }
5000+
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: