[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-unattended/var/se3/unattended/install/linuxaux/opt/perl/lib/site_perl/5.10.0/XML/XPath/ -> Literal.pm (source)

   1  # $Id: Literal.pm,v 1.11 2001/03/16 11:10:08 matt Exp $
   2  
   3  package XML::XPath::Literal;
   4  use XML::XPath::Boolean;
   5  use XML::XPath::Number;
   6  use strict;
   7  
   8  use overload 
   9          '""' => \&value,
  10          'cmp' => \&cmp;
  11  
  12  sub new {
  13      my $class = shift;
  14      my ($string) = @_;
  15      
  16  #    $string =~ s/"/"/g;
  17  #    $string =~ s/'/'/g;
  18      
  19      bless \$string, $class;
  20  }
  21  
  22  sub as_string {
  23      my $self = shift;
  24      my $string = $$self;
  25      $string =~ s/'/'/g;
  26      return "'$string'";
  27  }
  28  
  29  sub as_xml {
  30      my $self = shift;
  31      my $string = $$self;
  32      return "<Literal>$string</Literal>\n";
  33  }
  34  
  35  sub value {
  36      my $self = shift;
  37      $$self;
  38  }
  39  
  40  sub cmp {
  41      my $self = shift;
  42      my ($cmp, $swap) = @_;
  43      if ($swap) {
  44          return $cmp cmp $$self;
  45      }
  46      return $$self cmp $cmp;
  47  }
  48  
  49  sub evaluate {
  50      my $self = shift;
  51      $self;
  52  }
  53  
  54  sub to_boolean {
  55      my $self = shift;
  56      return (length($$self) > 0) ? XML::XPath::Boolean->True : XML::XPath::Boolean->False;
  57  }
  58  
  59  sub to_number { return XML::XPath::Number->new($_[0]->value); }
  60  sub to_literal { return $_[0]; }
  61  
  62  sub string_value { return $_[0]->value; }
  63  
  64  1;
  65  __END__
  66  
  67  =head1 NAME
  68  
  69  XML::XPath::Literal - Simple string values.
  70  
  71  =head1 DESCRIPTION
  72  
  73  In XPath terms a Literal is what we know as a string.
  74  
  75  =head1 API
  76  
  77  =head2 new($string)
  78  
  79  Create a new Literal object with the value in $string. Note that &quot; and
  80  &apos; will be converted to " and ' respectively. That is not part of the XPath
  81  specification, but I consider it useful. Note though that you have to go
  82  to extraordinary lengths in an XML template file (be it XSLT or whatever) to
  83  make use of this:
  84  
  85      <xsl:value-of select="&quot;I'm feeling &amp;quot;sad&amp;quot;&quot;"/>
  86  
  87  Which produces a Literal of:
  88  
  89      I'm feeling "sad"
  90  
  91  =head2 value()
  92  
  93  Also overloaded as stringification, simply returns the literal string value.
  94  
  95  =head2 cmp($literal)
  96  
  97  Returns the equivalent of perl's cmp operator against the given $literal.
  98  
  99  =cut


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