home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / perl5 / XML / XPath / LocationPath.pm < prev    next >
Encoding:
Perl POD Document  |  2001-03-16  |  1.1 KB  |  62 lines

  1. # $Id: LocationPath.pm,v 1.8 2001/03/16 11:10:08 matt Exp $
  2.  
  3. package XML::XPath::LocationPath;
  4. use XML::XPath::Root;
  5. use strict;
  6.  
  7. sub new {
  8.     my $class = shift;
  9.     my $self = [];
  10.     bless $self, $class;
  11. }
  12.  
  13. sub as_string {
  14.     my $self = shift;
  15.     my $string;
  16.     for (my $i = 0; $i < @$self; $i++) {
  17.         $string .= $self->[$i]->as_string;
  18.         $string .= "/" if $self->[$i+1];
  19.     }
  20.     return $string;
  21. }
  22.  
  23. sub as_xml {
  24.     my $self = shift;
  25.     my $string = "<LocationPath>\n";
  26.     
  27.     for (my $i = 0; $i < @$self; $i++) {
  28.         $string .= $self->[$i]->as_xml;
  29.     }
  30.     
  31.     $string .= "</LocationPath>\n";
  32.     return $string;
  33. }
  34.  
  35. sub set_root {
  36.     my $self = shift;
  37.     unshift @$self, XML::XPath::Root->new();
  38. }
  39.  
  40. sub evaluate {
  41.     my $self = shift;
  42.     # context _MUST_ be a single node
  43.     my $context = shift;
  44.     die "No context" unless $context;
  45.     
  46.     # I _think_ this is how it should work :)
  47.     
  48.     my $nodeset = XML::XPath::NodeSet->new();
  49.     $nodeset->push($context);
  50.     
  51.     foreach my $step (@$self) {
  52.         # For each step
  53.         # evaluate the step with the nodeset
  54.         my $pos = 1;
  55.         $nodeset = $step->evaluate($nodeset);
  56.     }
  57.     
  58.     return $nodeset;
  59. }
  60.  
  61. 1;
  62.