"Fossies" - the Fresh Open Source Software Archive

Member "install-tl-20200916/tlpkg/tlperl/lib/Pod/Simple/SimpleTree.pm" (8 Mar 2018, 4632 Bytes) of package /windows/misc/install-tl.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 require 5;
    3 package Pod::Simple::SimpleTree;
    4 use strict;
    5 use Carp ();
    6 use Pod::Simple ();
    7 use vars qw( $ATTR_PAD @ISA $VERSION $SORT_ATTRS);
    8 $VERSION = '3.35';
    9 BEGIN {
   10   @ISA = ('Pod::Simple');
   11   *DEBUG = \&Pod::Simple::DEBUG unless defined &DEBUG;
   12 }
   13 
   14 __PACKAGE__->_accessorize(
   15   'root',   # root of the tree
   16 );
   17 
   18 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 
   20 sub _handle_element_start { # self, tagname, attrhash
   21   DEBUG > 2 and print STDERR "Handling $_[1] start-event\n";
   22   my $x = [$_[1], $_[2]];
   23   if($_[0]{'_currpos'}) {
   24     push    @{ $_[0]{'_currpos'}[0] }, $x; # insert in parent's child-list
   25     unshift @{ $_[0]{'_currpos'} },    $x; # prefix to stack
   26   } else {
   27     DEBUG and print STDERR " And oo, it gets to be root!\n";
   28     $_[0]{'_currpos'} = [   $_[0]{'root'} = $x   ];
   29       # first event!  set to stack, and set as root.
   30   }
   31   DEBUG > 3 and print STDERR "Stack is now: ",
   32     join(">", map $_->[0], @{$_[0]{'_currpos'}}), "\n";
   33   return;
   34 }
   35 
   36 sub _handle_element_end { # self, tagname
   37   DEBUG > 2 and print STDERR "Handling $_[1] end-event\n";
   38   shift @{$_[0]{'_currpos'}};
   39   DEBUG > 3 and print STDERR "Stack is now: ",
   40     join(">", map $_->[0], @{$_[0]{'_currpos'}}), "\n";
   41   return;
   42 }
   43 
   44 sub _handle_text { # self, text
   45   DEBUG > 2 and print STDERR "Handling $_[1] text-event\n";
   46   push @{ $_[0]{'_currpos'}[0] }, $_[1];
   47   return;
   48 }
   49 
   50 
   51 # A bit of evil from the black box...  please avert your eyes, kind souls.
   52 sub _traverse_treelet_bit {
   53   DEBUG > 2 and print STDERR "Handling $_[1] paragraph event\n";
   54   my $self = shift;
   55   push @{ $self->{'_currpos'}[0] }, [@_];
   56   return;
   57 }
   58 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   59 1;
   60 __END__
   61 
   62 =head1 NAME
   63 
   64 Pod::Simple::SimpleTree -- parse Pod into a simple parse tree 
   65 
   66 =head1 SYNOPSIS
   67 
   68   % cat ptest.pod
   69 
   70   =head1 PIE
   71 
   72   I like B<pie>!
   73 
   74   % perl -MPod::Simple::SimpleTree -MData::Dumper -e \
   75      "print Dumper(Pod::Simple::SimpleTree->new->parse_file(shift)->root)" \
   76      ptest.pod
   77 
   78   $VAR1 = [
   79             'Document',
   80             { 'start_line' => 1 },
   81             [
   82               'head1',
   83               { 'start_line' => 1 },
   84               'PIE'
   85             ],
   86             [
   87               'Para',
   88               { 'start_line' => 3 },
   89               'I like ',
   90               [
   91                 'B',
   92                 {},
   93                 'pie'
   94               ],
   95               '!'
   96             ]
   97           ];
   98 
   99 =head1 DESCRIPTION
  100 
  101 This class is of interest to people writing a Pod processor/formatter.
  102 
  103 This class takes Pod and parses it, returning a parse tree made just
  104 of arrayrefs, and hashrefs, and strings.
  105 
  106 This is a subclass of L<Pod::Simple> and inherits all its methods.
  107 
  108 This class is inspired by XML::Parser's "Tree" parsing-style, although
  109 it doesn't use exactly the same LoL format.
  110 
  111 =head1 METHODS
  112 
  113 At the end of the parse, call C<< $parser->root >> to get the
  114 tree's top node.
  115 
  116 =head1 Tree Contents
  117 
  118 Every element node in the parse tree is represented by an arrayref of
  119 the form: C<[ I<elementname>, \%attributes, I<...subnodes...> ]>.
  120 See the example tree dump in the Synopsis, above.
  121 
  122 Every text node in the tree is represented by a simple (non-ref)
  123 string scalar.  So you can test C<ref($node)> to see whether you have
  124 an element node or just a text node.
  125 
  126 The top node in the tree is C<[ 'Document', \%attributes,
  127 I<...subnodes...> ]>
  128 
  129 
  130 =head1 SEE ALSO
  131 
  132 L<Pod::Simple>
  133 
  134 L<perllol>
  135 
  136 L<The "Tree" subsubsection in XML::Parser|XML::Parser/"Tree">
  137 
  138 =head1 SUPPORT
  139 
  140 Questions or discussion about POD and Pod::Simple should be sent to the
  141 pod-people@perl.org mail list. Send an empty email to
  142 pod-people-subscribe@perl.org to subscribe.
  143 
  144 This module is managed in an open GitHub repository,
  145 L<https://github.com/perl-pod/pod-simple/>. Feel free to fork and contribute, or
  146 to clone L<git://github.com/perl-pod/pod-simple.git> and send patches!
  147 
  148 Patches against Pod::Simple are welcome. Please send bug reports to
  149 <bug-pod-simple@rt.cpan.org>.
  150 
  151 =head1 COPYRIGHT AND DISCLAIMERS
  152 
  153 Copyright (c) 2002 Sean M. Burke.
  154 
  155 This library is free software; you can redistribute it and/or modify it
  156 under the same terms as Perl itself.
  157 
  158 This program is distributed in the hope that it will be useful, but
  159 without any warranty; without even the implied warranty of
  160 merchantability or fitness for a particular purpose.
  161 
  162 =head1 AUTHOR
  163 
  164 Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.
  165 But don't bother him, he's retired.
  166 
  167 Pod::Simple is maintained by:
  168 
  169 =over
  170 
  171 =item * Allison Randal C<allison@perl.org>
  172 
  173 =item * Hans Dieter Pearcey C<hdp@cpan.org>
  174 
  175 =item * David E. Wheeler C<dwheeler@cpan.org>
  176 
  177 =back
  178 
  179 =cut