[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-unattended/var/se3/unattended/install/linuxaux/opt/perl/lib/5.10.0/pod/Simple/ -> SimpleTree.pm (source)

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


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1