<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#############################################################################
# Pod/InputObjects.pm -- package which defines objects for input streams
# and paragraphs and commands when parsing POD docs.
#
# Copyright (C) 1996-2000 by Bradford Appleton. All rights reserved.
# This file is part of "PodParser". PodParser is free software;
# you can redistribute it and/or modify it under the same terms
# as Perl itself.
#############################################################################

package Pod::InputObjects;
use strict;

use vars qw($VERSION);
$VERSION = '1.60';  ## Current version of this package
require  5.005;    ## requires this Perl version or later

#############################################################################

=head1 NAME

Pod::InputObjects - objects representing POD input paragraphs, commands, etc.

=head1 SYNOPSIS

    use Pod::InputObjects;

=head1 REQUIRES

perl5.004, Carp

=head1 EXPORTS

Nothing.

=head1 DESCRIPTION

This module defines some basic input objects used by B&lt;Pod::Parser&gt; when
reading and parsing POD text from an input source. The following objects
are defined:

=begin __PRIVATE__

=over 4

=item package B&lt;Pod::InputSource&gt;

An object corresponding to a source of POD input text. It is mostly a
wrapper around a filehandle or C&lt;IO::Handle&gt;-type object (or anything
that implements the C&lt;getline()&gt; method) which keeps track of some
additional information relevant to the parsing of PODs.

=back

=end __PRIVATE__

=over 4

=item package B&lt;Pod::Paragraph&gt;

An object corresponding to a paragraph of POD input text. It may be a
plain paragraph, a verbatim paragraph, or a command paragraph (see
L&lt;perlpod&gt;).

=item package B&lt;Pod::InteriorSequence&gt;

An object corresponding to an interior sequence command from the POD
input text (see L&lt;perlpod&gt;).

=item package B&lt;Pod::ParseTree&gt;

An object corresponding to a tree of parsed POD text. Each "node" in
a parse-tree (or I&lt;ptree&gt;) is either a text-string or a reference to
a B&lt;Pod::InteriorSequence&gt; object. The nodes appear in the parse-tree
in the order in which they were parsed from left-to-right.

=back

Each of these input objects are described in further detail in the
sections which follow.

=cut

#############################################################################

package Pod::InputSource;

##---------------------------------------------------------------------------

=begin __PRIVATE__

=head1 B&lt;Pod::InputSource&gt;

This object corresponds to an input source or stream of POD
documentation. When parsing PODs, it is necessary to associate and store
certain context information with each input source. All of this
information is kept together with the stream itself in one of these
C&lt;Pod::InputSource&gt; objects. Each such object is merely a wrapper around
an C&lt;IO::Handle&gt; object of some kind (or at least something that
implements the C&lt;getline()&gt; method). They have the following
methods/attributes:

=end __PRIVATE__

=cut

##---------------------------------------------------------------------------

=begin __PRIVATE__

=head2 B&lt;new()&gt;

        my $pod_input1 = Pod::InputSource-&gt;new(-handle =&gt; $filehandle);
        my $pod_input2 = new Pod::InputSource(-handle =&gt; $filehandle,
                                              -name   =&gt; $name);
        my $pod_input3 = new Pod::InputSource(-handle =&gt; \*STDIN);
        my $pod_input4 = Pod::InputSource-&gt;new(-handle =&gt; \*STDIN,
                                               -name =&gt; "(STDIN)");

This is a class method that constructs a C&lt;Pod::InputSource&gt; object and
returns a reference to the new input source object. It takes one or more
keyword arguments in the form of a hash. The keyword C&lt;-handle&gt; is
required and designates the corresponding input handle. The keyword
C&lt;-name&gt; is optional and specifies the name associated with the input
handle (typically a file name).

=end __PRIVATE__

=cut

sub new {
    ## Determine if we were called via an object-ref or a classname
    my $this = shift;
    my $class = ref($this) || $this;

    ## Any remaining arguments are treated as initial values for the
    ## hash that is used to represent this object. Note that we default
    ## certain values by specifying them *before* the arguments passed.
    ## If they are in the argument list, they will override the defaults.
    my $self = { -name        =&gt; '(unknown)',
                 -handle      =&gt; undef,
                 -was_cutting =&gt; 0,
                 @_ };

    ## Bless ourselves into the desired class and perform any initialization
    bless $self, $class;
    return $self;
}

##---------------------------------------------------------------------------

=begin __PRIVATE__

=head2 B&lt;name()&gt;

        my $filename = $pod_input-&gt;name();
        $pod_input-&gt;name($new_filename_to_use);

This method gets/sets the name of the input source (usually a filename).
If no argument is given, it returns a string containing the name of
the input source; otherwise it sets the name of the input source to the
contents of the given argument.

=end __PRIVATE__

=cut

sub name {
   (@_ &gt; 1)  and  $_[0]-&gt;{'-name'} = $_[1];
   return $_[0]-&gt;{'-name'};
}

## allow 'filename' as an alias for 'name'
*filename = \&amp;name;

##---------------------------------------------------------------------------

=begin __PRIVATE__

=head2 B&lt;handle()&gt;

        my $handle = $pod_input-&gt;handle();

Returns a reference to the handle object from which input is read (the
one used to contructed this input source object).

=end __PRIVATE__

=cut

sub handle {
   return $_[0]-&gt;{'-handle'};
}

##---------------------------------------------------------------------------

=begin __PRIVATE__

=head2 B&lt;was_cutting()&gt;

        print "Yes.\n" if ($pod_input-&gt;was_cutting());

The value of the C&lt;cutting&gt; state (that the B&lt;cutting()&gt; method would
have returned) immediately before any input was read from this input
stream. After all input from this stream has been read, the C&lt;cutting&gt;
state is restored to this value.

=end __PRIVATE__

=cut

sub was_cutting {
   (@_ &gt; 1)  and  $_[0]-&gt;{-was_cutting} = $_[1];
   return $_[0]-&gt;{-was_cutting};
}

##---------------------------------------------------------------------------

#############################################################################

package Pod::Paragraph;

##---------------------------------------------------------------------------

=head1 B&lt;Pod::Paragraph&gt;

An object representing a paragraph of POD input text.
It has the following methods/attributes:

=cut

##---------------------------------------------------------------------------

=head2 Pod::Paragraph-E&lt;gt&gt;B&lt;new()&gt;

        my $pod_para1 = Pod::Paragraph-&gt;new(-text =&gt; $text);
        my $pod_para2 = Pod::Paragraph-&gt;new(-name =&gt; $cmd,
                                            -text =&gt; $text);
        my $pod_para3 = new Pod::Paragraph(-text =&gt; $text);
        my $pod_para4 = new Pod::Paragraph(-name =&gt; $cmd,
                                           -text =&gt; $text);
        my $pod_para5 = Pod::Paragraph-&gt;new(-name =&gt; $cmd,
                                            -text =&gt; $text,
                                            -file =&gt; $filename,
                                            -line =&gt; $line_number);

This is a class method that constructs a C&lt;Pod::Paragraph&gt; object and
returns a reference to the new paragraph object. It may be given one or
two keyword arguments. The C&lt;-text&gt; keyword indicates the corresponding
text of the POD paragraph. The C&lt;-name&gt; keyword indicates the name of
the corresponding POD command, such as C&lt;head1&gt; or C&lt;item&gt; (it should
I&lt;not&gt; contain the C&lt;=&gt; prefix); this is needed only if the POD
paragraph corresponds to a command paragraph. The C&lt;-file&gt; and C&lt;-line&gt;
keywords indicate the filename and line number corresponding to the
beginning of the paragraph 

=cut

sub new {
    ## Determine if we were called via an object-ref or a classname
    my $this = shift;
    my $class = ref($this) || $this;

    ## Any remaining arguments are treated as initial values for the
    ## hash that is used to represent this object. Note that we default
    ## certain values by specifying them *before* the arguments passed.
    ## If they are in the argument list, they will override the defaults.
    my $self = {
          -name       =&gt; undef,
          -text       =&gt; (@_ == 1) ? shift : undef,
          -file       =&gt; '&lt;unknown-file&gt;',
          -line       =&gt; 0,
          -prefix     =&gt; '=',
          -separator  =&gt; ' ',
          -ptree =&gt; [],
          @_
    };

    ## Bless ourselves into the desired class and perform any initialization
    bless $self, $class;
    return $self;
}

##---------------------------------------------------------------------------

=head2 $pod_para-E&lt;gt&gt;B&lt;cmd_name()&gt;

        my $para_cmd = $pod_para-&gt;cmd_name();

If this paragraph is a command paragraph, then this method will return 
the name of the command (I&lt;without&gt; any leading C&lt;=&gt; prefix).

=cut

sub cmd_name {
   (@_ &gt; 1)  and  $_[0]-&gt;{'-name'} = $_[1];
   return $_[0]-&gt;{'-name'};
}

## let name() be an alias for cmd_name()
*name = \&amp;cmd_name;

##---------------------------------------------------------------------------

=head2 $pod_para-E&lt;gt&gt;B&lt;text()&gt;

        my $para_text = $pod_para-&gt;text();

This method will return the corresponding text of the paragraph.

=cut

sub text {
   (@_ &gt; 1)  and  $_[0]-&gt;{'-text'} = $_[1];
   return $_[0]-&gt;{'-text'};
}

##---------------------------------------------------------------------------

=head2 $pod_para-E&lt;gt&gt;B&lt;raw_text()&gt;

        my $raw_pod_para = $pod_para-&gt;raw_text();

This method will return the I&lt;raw&gt; text of the POD paragraph, exactly
as it appeared in the input.

=cut

sub raw_text {
   return $_[0]-&gt;{'-text'}  unless (defined $_[0]-&gt;{'-name'});
   return $_[0]-&gt;{'-prefix'} . $_[0]-&gt;{'-name'} .
          $_[0]-&gt;{'-separator'} . $_[0]-&gt;{'-text'};
}

##---------------------------------------------------------------------------

=head2 $pod_para-E&lt;gt&gt;B&lt;cmd_prefix()&gt;

        my $prefix = $pod_para-&gt;cmd_prefix();

If this paragraph is a command paragraph, then this method will return 
the prefix used to denote the command (which should be the string "="
or "==").

=cut

sub cmd_prefix {
   return $_[0]-&gt;{'-prefix'};
}

##---------------------------------------------------------------------------

=head2 $pod_para-E&lt;gt&gt;B&lt;cmd_separator()&gt;

        my $separator = $pod_para-&gt;cmd_separator();

If this paragraph is a command paragraph, then this method will return
the text used to separate the command name from the rest of the
paragraph (if any).

=cut

sub cmd_separator {
   return $_[0]-&gt;{'-separator'};
}

##---------------------------------------------------------------------------

=head2 $pod_para-E&lt;gt&gt;B&lt;parse_tree()&gt;

        my $ptree = $pod_parser-&gt;parse_text( $pod_para-&gt;text() );
        $pod_para-&gt;parse_tree( $ptree );
        $ptree = $pod_para-&gt;parse_tree();

This method will get/set the corresponding parse-tree of the paragraph's text.

=cut

sub parse_tree {
   (@_ &gt; 1)  and  $_[0]-&gt;{'-ptree'} = $_[1];
   return $_[0]-&gt;{'-ptree'};
}

## let ptree() be an alias for parse_tree()
*ptree = \&amp;parse_tree;

##---------------------------------------------------------------------------

=head2 $pod_para-E&lt;gt&gt;B&lt;file_line()&gt;

        my ($filename, $line_number) = $pod_para-&gt;file_line();
        my $position = $pod_para-&gt;file_line();

Returns the current filename and line number for the paragraph
object.  If called in a list context, it returns a list of two
elements: first the filename, then the line number. If called in
a scalar context, it returns a string containing the filename, followed
by a colon (':'), followed by the line number.

=cut

sub file_line {
   my @loc = ($_[0]-&gt;{'-file'} || '&lt;unknown-file&gt;',
              $_[0]-&gt;{'-line'} || 0);
   return (wantarray) ? @loc : join(':', @loc);
}

##---------------------------------------------------------------------------

#############################################################################

package Pod::InteriorSequence;

##---------------------------------------------------------------------------

=head1 B&lt;Pod::InteriorSequence&gt;

An object representing a POD interior sequence command.
It has the following methods/attributes:

=cut

##---------------------------------------------------------------------------

=head2 Pod::InteriorSequence-E&lt;gt&gt;B&lt;new()&gt;

        my $pod_seq1 = Pod::InteriorSequence-&gt;new(-name =&gt; $cmd
                                                  -ldelim =&gt; $delimiter);
        my $pod_seq2 = new Pod::InteriorSequence(-name =&gt; $cmd,
                                                 -ldelim =&gt; $delimiter);
        my $pod_seq3 = new Pod::InteriorSequence(-name =&gt; $cmd,
                                                 -ldelim =&gt; $delimiter,
                                                 -file =&gt; $filename,
                                                 -line =&gt; $line_number);

        my $pod_seq4 = new Pod::InteriorSequence(-name =&gt; $cmd, $ptree);
        my $pod_seq5 = new Pod::InteriorSequence($cmd, $ptree);

This is a class method that constructs a C&lt;Pod::InteriorSequence&gt; object
and returns a reference to the new interior sequence object. It should
be given two keyword arguments.  The C&lt;-ldelim&gt; keyword indicates the
corresponding left-delimiter of the interior sequence (e.g. 'E&lt;lt&gt;').
The C&lt;-name&gt; keyword indicates the name of the corresponding interior
sequence command, such as C&lt;I&gt; or C&lt;B&gt; or C&lt;C&gt;. The C&lt;-file&gt; and
C&lt;-line&gt; keywords indicate the filename and line number corresponding
to the beginning of the interior sequence. If the C&lt;$ptree&gt; argument is
given, it must be the last argument, and it must be either string, or
else an array-ref suitable for passing to B&lt;Pod::ParseTree::new&gt; (or
it may be a reference to a Pod::ParseTree object).

=cut

sub new {
    ## Determine if we were called via an object-ref or a classname
    my $this = shift;
    my $class = ref($this) || $this;

    ## See if first argument has no keyword
    if (((@_ &lt;= 2) or (@_ % 2)) and $_[0] !~ /^-\w/) {
       ## Yup - need an implicit '-name' before first parameter
       unshift @_, '-name';
    }

    ## See if odd number of args
    if ((@_ % 2) != 0) {
       ## Yup - need an implicit '-ptree' before the last parameter
       splice @_, $#_, 0, '-ptree';
    }

    ## Any remaining arguments are treated as initial values for the
    ## hash that is used to represent this object. Note that we default
    ## certain values by specifying them *before* the arguments passed.
    ## If they are in the argument list, they will override the defaults.
    my $self = {
          -name       =&gt; (@_ == 1) ? $_[0] : undef,
          -file       =&gt; '&lt;unknown-file&gt;',
          -line       =&gt; 0,
          -ldelim     =&gt; '&lt;',
          -rdelim     =&gt; '&gt;',
          @_
    };

    ## Initialize contents if they havent been already
    my $ptree = $self-&gt;{'-ptree'} || new Pod::ParseTree();
    if ( ref $ptree =~ /^(ARRAY)?$/ ) {
        ## We have an array-ref, or a normal scalar. Pass it as an
        ## an argument to the ptree-constructor
        $ptree = new Pod::ParseTree($1 ? [$ptree] : $ptree);
    }
    $self-&gt;{'-ptree'} = $ptree;

    ## Bless ourselves into the desired class and perform any initialization
    bless $self, $class;
    return $self;
}

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;cmd_name()&gt;

        my $seq_cmd = $pod_seq-&gt;cmd_name();

The name of the interior sequence command.

=cut

sub cmd_name {
   (@_ &gt; 1)  and  $_[0]-&gt;{'-name'} = $_[1];
   return $_[0]-&gt;{'-name'};
}

## let name() be an alias for cmd_name()
*name = \&amp;cmd_name;

##---------------------------------------------------------------------------

## Private subroutine to set the parent pointer of all the given
## children that are interior-sequences to be $self

sub _set_child2parent_links {
   my ($self, @children) = @_;
   ## Make sure any sequences know who their parent is
   for (@children) {
      next  unless (length  and  ref  and  ref ne 'SCALAR');
      if (UNIVERSAL::isa($_, 'Pod::InteriorSequence') or
          UNIVERSAL::can($_, 'nested'))
      {
          $_-&gt;nested($self);
      }
   }
}

## Private subroutine to unset child-&gt;parent links

sub _unset_child2parent_links {
   my $self = shift;
   $self-&gt;{'-parent_sequence'} = undef;
   my $ptree = $self-&gt;{'-ptree'};
   for (@$ptree) {
      next  unless (length  and  ref  and  ref ne 'SCALAR');
      $_-&gt;_unset_child2parent_links()
          if UNIVERSAL::isa($_, 'Pod::InteriorSequence');
   }
}

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;prepend()&gt;

        $pod_seq-&gt;prepend($text);
        $pod_seq1-&gt;prepend($pod_seq2);

Prepends the given string or parse-tree or sequence object to the parse-tree
of this interior sequence.

=cut

sub prepend {
   my $self  = shift;
   $self-&gt;{'-ptree'}-&gt;prepend(@_);
   _set_child2parent_links($self, @_);
   return $self;
}

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;append()&gt;

        $pod_seq-&gt;append($text);
        $pod_seq1-&gt;append($pod_seq2);

Appends the given string or parse-tree or sequence object to the parse-tree
of this interior sequence.

=cut

sub append {
   my $self = shift;
   $self-&gt;{'-ptree'}-&gt;append(@_);
   _set_child2parent_links($self, @_);
   return $self;
}

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;nested()&gt;

        $outer_seq = $pod_seq-&gt;nested || print "not nested";

If this interior sequence is nested inside of another interior
sequence, then the outer/parent sequence that contains it is
returned. Otherwise C&lt;undef&gt; is returned.

=cut

sub nested {
   my $self = shift;
  (@_ == 1)  and  $self-&gt;{'-parent_sequence'} = shift;
   return  $self-&gt;{'-parent_sequence'} || undef;
}

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;raw_text()&gt;

        my $seq_raw_text = $pod_seq-&gt;raw_text();

This method will return the I&lt;raw&gt; text of the POD interior sequence,
exactly as it appeared in the input.

=cut

sub raw_text {
   my $self = shift;
   my $text = $self-&gt;{'-name'} . $self-&gt;{'-ldelim'};
   for ( $self-&gt;{'-ptree'}-&gt;children ) {
      $text .= (ref $_) ? $_-&gt;raw_text : $_;
   }
   $text .= $self-&gt;{'-rdelim'};
   return $text;
}

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;left_delimiter()&gt;

        my $ldelim = $pod_seq-&gt;left_delimiter();

The leftmost delimiter beginning the argument text to the interior
sequence (should be "&lt;").

=cut

sub left_delimiter {
   (@_ &gt; 1)  and  $_[0]-&gt;{'-ldelim'} = $_[1];
   return $_[0]-&gt;{'-ldelim'};
}

## let ldelim() be an alias for left_delimiter()
*ldelim = \&amp;left_delimiter;

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;right_delimiter()&gt;

The rightmost delimiter beginning the argument text to the interior
sequence (should be "&gt;").

=cut

sub right_delimiter {
   (@_ &gt; 1)  and  $_[0]-&gt;{'-rdelim'} = $_[1];
   return $_[0]-&gt;{'-rdelim'};
}

## let rdelim() be an alias for right_delimiter()
*rdelim = \&amp;right_delimiter;

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;parse_tree()&gt;

        my $ptree = $pod_parser-&gt;parse_text($paragraph_text);
        $pod_seq-&gt;parse_tree( $ptree );
        $ptree = $pod_seq-&gt;parse_tree();

This method will get/set the corresponding parse-tree of the interior
sequence's text.

=cut

sub parse_tree {
   (@_ &gt; 1)  and  $_[0]-&gt;{'-ptree'} = $_[1];
   return $_[0]-&gt;{'-ptree'};
}

## let ptree() be an alias for parse_tree()
*ptree = \&amp;parse_tree;

##---------------------------------------------------------------------------

=head2 $pod_seq-E&lt;gt&gt;B&lt;file_line()&gt;

        my ($filename, $line_number) = $pod_seq-&gt;file_line();
        my $position = $pod_seq-&gt;file_line();

Returns the current filename and line number for the interior sequence
object.  If called in a list context, it returns a list of two
elements: first the filename, then the line number. If called in
a scalar context, it returns a string containing the filename, followed
by a colon (':'), followed by the line number.

=cut

sub file_line {
   my @loc = ($_[0]-&gt;{'-file'}  || '&lt;unknown-file&gt;',
              $_[0]-&gt;{'-line'}  || 0);
   return (wantarray) ? @loc : join(':', @loc);
}

##---------------------------------------------------------------------------

=head2 Pod::InteriorSequence::B&lt;DESTROY()&gt;

This method performs any necessary cleanup for the interior-sequence.
If you override this method then it is B&lt;imperative&gt; that you invoke
the parent method from within your own method, otherwise
I&lt;interior-sequence storage will not be reclaimed upon destruction!&gt;

=cut

sub DESTROY {
   ## We need to get rid of all child-&gt;parent pointers throughout the
   ## tree so their reference counts will go to zero and they can be
   ## garbage-collected
   _unset_child2parent_links(@_);
}

##---------------------------------------------------------------------------

#############################################################################

package Pod::ParseTree;

##---------------------------------------------------------------------------

=head1 B&lt;Pod::ParseTree&gt;

This object corresponds to a tree of parsed POD text. As POD text is
scanned from left to right, it is parsed into an ordered list of
text-strings and B&lt;Pod::InteriorSequence&gt; objects (in order of
appearance). A B&lt;Pod::ParseTree&gt; object corresponds to this list of
strings and sequences. Each interior sequence in the parse-tree may
itself contain a parse-tree (since interior sequences may be nested).

=cut

##---------------------------------------------------------------------------

=head2 Pod::ParseTree-E&lt;gt&gt;B&lt;new()&gt;

        my $ptree1 = Pod::ParseTree-&gt;new;
        my $ptree2 = new Pod::ParseTree;
        my $ptree4 = Pod::ParseTree-&gt;new($array_ref);
        my $ptree3 = new Pod::ParseTree($array_ref);

This is a class method that constructs a C&lt;Pod::Parse_tree&gt; object and
returns a reference to the new parse-tree. If a single-argument is given,
it must be a reference to an array, and is used to initialize the root
(top) of the parse tree.

=cut

sub new {
    ## Determine if we were called via an object-ref or a classname
    my $this = shift;
    my $class = ref($this) || $this;

    my $self = (@_ == 1  and  ref $_[0]) ? $_[0] : [];

    ## Bless ourselves into the desired class and perform any initialization
    bless $self, $class;
    return $self;
}

##---------------------------------------------------------------------------

=head2 $ptree-E&lt;gt&gt;B&lt;top()&gt;

        my $top_node = $ptree-&gt;top();
        $ptree-&gt;top( $top_node );
        $ptree-&gt;top( @children );

This method gets/sets the top node of the parse-tree. If no arguments are
given, it returns the topmost node in the tree (the root), which is also
a B&lt;Pod::ParseTree&gt;. If it is given a single argument that is a reference,
then the reference is assumed to a parse-tree and becomes the new top node.
Otherwise, if arguments are given, they are treated as the new list of
children for the top node.

=cut

sub top {
   my $self = shift;
   if (@_ &gt; 0) {
      @{ $self } = (@_ == 1  and  ref $_[0]) ? ${ @_ } : @_;
   }
   return $self;
}

## let parse_tree() &amp; ptree() be aliases for the 'top' method
*parse_tree = *ptree = \&amp;top;

##---------------------------------------------------------------------------

=head2 $ptree-E&lt;gt&gt;B&lt;children()&gt;

This method gets/sets the children of the top node in the parse-tree.
If no arguments are given, it returns the list (array) of children
(each of which should be either a string or a B&lt;Pod::InteriorSequence&gt;.
Otherwise, if arguments are given, they are treated as the new list of
children for the top node.

=cut

sub children {
   my $self = shift;
   if (@_ &gt; 0) {
      @{ $self } = (@_ == 1  and  ref $_[0]) ? ${ @_ } : @_;
   }
   return @{ $self };
}

##---------------------------------------------------------------------------

=head2 $ptree-E&lt;gt&gt;B&lt;prepend()&gt;

This method prepends the given text or parse-tree to the current parse-tree.
If the first item on the parse-tree is text and the argument is also text,
then the text is prepended to the first item (not added as a separate string).
Otherwise the argument is added as a new string or parse-tree I&lt;before&gt;
the current one.

=cut

use vars qw(@ptree);  ## an alias used for performance reasons

sub prepend {
   my $self = shift;
   local *ptree = $self;
   for (@_) {
      next  unless length;
      if (@ptree &amp;&amp; !(ref $ptree[0]) &amp;&amp; !(ref $_)) {
         $ptree[0] = $_ . $ptree[0];
      }
      else {
         unshift @ptree, $_;
      }
   }
}

##---------------------------------------------------------------------------

=head2 $ptree-E&lt;gt&gt;B&lt;append()&gt;

This method appends the given text or parse-tree to the current parse-tree.
If the last item on the parse-tree is text and the argument is also text,
then the text is appended to the last item (not added as a separate string).
Otherwise the argument is added as a new string or parse-tree I&lt;after&gt;
the current one.

=cut

sub append {
   my $self = shift;
   local *ptree = $self;
   my $can_append = @ptree &amp;&amp; !(ref $ptree[-1]);
   for (@_) {
      if (ref) {
         push @ptree, $_;
      }
      elsif(!length) {
         next;
      }
      elsif ($can_append) {
         $ptree[-1] .= $_;
      }
      else {
         push @ptree, $_;
      }
   }
}

=head2 $ptree-E&lt;gt&gt;B&lt;raw_text()&gt;

        my $ptree_raw_text = $ptree-&gt;raw_text();

This method will return the I&lt;raw&gt; text of the POD parse-tree
exactly as it appeared in the input.

=cut

sub raw_text {
   my $self = shift;
   my $text = '';
   for ( @$self ) {
      $text .= (ref $_) ? $_-&gt;raw_text : $_;
   }
   return $text;
}

##---------------------------------------------------------------------------

## Private routines to set/unset child-&gt;parent links

sub _unset_child2parent_links {
   my $self = shift;
   local *ptree = $self;
   for (@ptree) {
       next  unless (defined and length  and  ref  and  ref ne 'SCALAR');
       $_-&gt;_unset_child2parent_links()
           if UNIVERSAL::isa($_, 'Pod::InteriorSequence');
   }
}

sub _set_child2parent_links {
    ## nothing to do, Pod::ParseTrees cant have parent pointers
}

=head2 Pod::ParseTree::B&lt;DESTROY()&gt;

This method performs any necessary cleanup for the parse-tree.
If you override this method then it is B&lt;imperative&gt;
that you invoke the parent method from within your own method,
otherwise I&lt;parse-tree storage will not be reclaimed upon destruction!&gt;

=cut

sub DESTROY {
   ## We need to get rid of all child-&gt;parent pointers throughout the
   ## tree so their reference counts will go to zero and they can be
   ## garbage-collected
   _unset_child2parent_links(@_);
}

#############################################################################

=head1 SEE ALSO

B&lt;Pod::InputObjects&gt; is part of the L&lt;Pod::Parser&gt; distribution.

See L&lt;Pod::Parser&gt;, L&lt;Pod::Select&gt;

=head1 AUTHOR

Please report bugs using L&lt;http://rt.cpan.org&gt;.

Brad Appleton E&lt;lt&gt;bradapp@enteract.comE&lt;gt&gt;

=cut

1;
</pre></body></html>