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

  1. #
  2. # Copyright (C) 1999 Ken MacLeod
  3. # XML::PatAct::MatchName is free software; you can redistribute it and/or
  4. # modify it under the same terms as Perl itself.
  5. #
  6. # $Id: MatchName.pm,v 1.3 1999/12/22 21:15:00 kmacleod Exp $
  7. #
  8.  
  9. use strict;
  10.  
  11. package XML::PatAct::MatchName;
  12.  
  13. use vars qw{ $VERSION };
  14.  
  15. # will be substituted by make-rel script
  16. $VERSION = "0.08";
  17.  
  18. sub new {
  19.     my $type = shift;
  20.     my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ };
  21.  
  22.     return bless $self, $type;
  23. }
  24.  
  25. # This is functionally equivalent to PerlSAX `start_document()'
  26. sub initialize {
  27.     my ($self, $driver) = @_;
  28.     $self->{Driver} = $driver;
  29. }
  30.  
  31. # This is functionally equivalent to PerlSAX `end_document()'
  32. sub finalize {
  33.     my $self = shift;
  34.  
  35.     $self->{Driver} = undef;
  36. }
  37.  
  38. # This is functionally equivalent to a PerlSAX `start_element()'
  39. sub match {
  40.     my ($self, $element, $names, $nodes) = @_;
  41.  
  42.     my $names_path = '/' . join('/', @$names);
  43.     my $patterns = $self->{Patterns};
  44.     my $ii = 0;
  45.     while ($ii <= $#$patterns) {
  46.         my $pattern = $patterns->[$ii];
  47.     if ($names_path =~ m|/$pattern$|) {
  48.         return $ii / 2;
  49.     }
  50.     $ii += 2;
  51.     }
  52.  
  53.     return undef;
  54. }
  55.  
  56. 1;
  57.  
  58. __END__
  59.  
  60. =head1 NAME
  61.  
  62. XML::PatAct::MatchName - A pattern module for matching element names
  63.  
  64. =head1 SYNOPSIS
  65.  
  66.  use XML::PatAct::MatchName;
  67.  
  68.  my $matcher = XML::PatAct::MatchName->new();
  69.  
  70.  my $patterns = [ 'foo' => ACTION,
  71.           'bar/foo' => ACTION,
  72.           ... ];
  73.  
  74. =head1 DESCRIPTION
  75.  
  76. XML::PatAct::MatchName is a pattern module for use with PatAct drivers
  77. for applying pattern-action lists to XML parses or trees.
  78. XML::PatAct::MatchName is a simple pattern module that uses just
  79. element names to match on.  If multiple names are supplied seperated
  80. by `C</>' characters, then all of the parent element names must match
  81. as well.
  82.  
  83. The order of patterns in the list is not significant.
  84. XML::PatAct::MatchName will use the most specific match.  Using the
  85. synopsis above as an example, if you have an element `C<foo>',
  86. `C<bar/foo>' will match if `C<foo>' is in an element `C<bar>',
  87. otherwise just the pattern with `C<foo>' will match.
  88.  
  89. =head1 AUTHOR
  90.  
  91. Ken MacLeod, ken@bitsko.slc.ut.us
  92.  
  93. =head1 SEE ALSO
  94.  
  95. perl(1)
  96.  
  97. ``Using PatAct Modules'' and ``Creating PatAct Modules'' in libxml-perl.
  98.  
  99. =cut
  100.