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