home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / perl5 / XML / PatAct / ActionTempl.pm next >
Encoding:
Text File  |  2003-10-21  |  3.1 KB  |  147 lines

  1. # This template file is in the Public Domain.
  2. # You may do anything you want with this file.
  3. #
  4. # $Id: ActionTempl.pm,v 1.2 1999/08/16 16:04:03 kmacleod Exp $
  5. #
  6.  
  7. # replace all occurrences of ACTION with the name of your module!
  8.  
  9. use strict;
  10.  
  11. use UNIVERSAL;
  12.  
  13. package XML::PatAct::ACTION;
  14.  
  15. sub new {
  16.     my $type = shift;
  17.     my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ };
  18.  
  19.     bless $self, $type;
  20.  
  21.     my $usage = <<'EOF';
  22. usage: XML::PatAct::ACTION->new( Matcher => $matcher,
  23.                  Patterns => $patterns );
  24. EOF
  25.  
  26.     die "No Matcher specified\n$usage\n"
  27.     if !defined $self->{Matcher};
  28.     die "No Patterns specified\n$usage\n"
  29.     if !defined $self->{Patterns};
  30.  
  31.     # perform additional initialization here
  32.  
  33.     return $self;
  34. }
  35.  
  36. sub start_document {
  37.     my ($self, $document) = @_;
  38.  
  39.     # initialize the pattern module at the start of a document
  40.     $self->{Matcher}->initialize($self);
  41.  
  42.     # create empty name and node lists for passing to `match()'
  43.     $self->{Names} = [ ];
  44.     $self->{Nodes} = [ ];
  45.  
  46.     # Knowing that a source is a tree can be useful information
  47.     $self->{SourceIsGrove} = UNIVERSAL::isa($document, 'Data::Grove');
  48. }
  49.  
  50. sub end_document {
  51.     my ($self, $document) = @_;
  52.  
  53.     # notify the pattern module that we're done
  54.     $self->{Matcher}->finalize();
  55.  
  56.     my $value;
  57.     # perform any finalization actions, use $value to return a result
  58.     # from calling `parse()'
  59.  
  60.     # release all the info that is just used during event handling
  61.     $self->{Matcher} = $self->{Names} = $self->{Nodes} = undef;
  62.     $self->{SourceIsGrove} = undef;
  63.  
  64.     return $value;
  65. }
  66.  
  67. sub start_element {
  68.     my ($self, $element) = @_;
  69.  
  70.     push @{$self->{Names}}, $element->{Name};
  71.     push @{$self->{Nodes}}, $element;
  72.  
  73.     my $index = $self->{Matcher}->match($element,
  74.                     $self->{Names},
  75.                     $self->{Nodes});
  76.  
  77.     # use $index to retrieve an action for this element
  78. }
  79.  
  80. sub end_element {
  81.     my ($self, $end_element) = @_;
  82.  
  83.     my $name = pop @{$self->{Names}};
  84.     my $element = pop @{$self->{Nodes}};
  85.  
  86.     # perform any finishing steps at the end of an element
  87. }
  88.  
  89. sub characters {
  90.     my ($self, $characters) = @_;
  91.  
  92. }
  93.  
  94. sub processing_instruction {
  95.     my ($self, $pi) = @_;
  96.  
  97. }
  98.  
  99. sub ignorable_whitespace {
  100.     my ($self, $characters) = @_;
  101.  
  102. }
  103.  
  104. 1;
  105.  
  106. __END__
  107.  
  108. =head1 NAME
  109.  
  110. XML::PatAct::ACTION - An action module for
  111.  
  112. =head1 SYNOPSIS
  113.  
  114.  use XML::PatAct::ACTION;
  115.  
  116.  my $patterns = [ PATTERN => ACTION,
  117.           ... ];
  118.  
  119.  my $matcher = XML::PatAct::ACTION->new(Patterns => $patterns,
  120.                     Matcher => $matcher );
  121.  
  122.  
  123. =head1 DESCRIPTION
  124.  
  125. XML::PatAct::ACTION is a PerlSAX handler for applying pattern-action
  126. lists to XML parses or trees.  XML::PatAct::ACTION ...
  127.  
  128. New XML::PatAct::ACTION instances are creating by calling `new()'.  A
  129. Parameters can be passed as a list of key, value pairs or a hash.
  130. Patterns and Matcher options are required.  Patterns is the
  131. pattern-action list to apply.  Matcher is an instance of the pattern
  132. or query matching module.
  133.  
  134. DESCRIBE THE FORMAT OF YOUR ACTIONS HERE
  135.  
  136. =head1 AUTHOR
  137.  
  138. This template file was written by Ken MacLeod, ken@bitsko.slc.ut.us
  139.  
  140. =head1 SEE ALSO
  141.  
  142. perl(1)
  143.  
  144. ``Using PatAct Modules'' and ``Creating PatAct Modules'' in libxml-perl.
  145.  
  146. =cut
  147.