Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / i486-linux-gnu-thread-multi / XML / LibXML / Literal.pm
CommitLineData
3fea05b9 1# $Id: Literal.pm 785 2009-07-16 14:17:46Z pajas $
2#
3# This is free software, you may use it and distribute it under the same terms as
4# Perl itself.
5#
6# Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
7#
8#
9
10package XML::LibXML::Literal;
11use XML::LibXML::Boolean;
12use XML::LibXML::Number;
13use strict;
14
15use vars qw ($VERSION);
16$VERSION = "1.70"; # VERSION TEMPLATE: DO NOT CHANGE
17
18use overload
19 '""' => \&value,
20 'cmp' => \&cmp;
21
22sub new {
23 my $class = shift;
24 my ($string) = @_;
25
26# $string =~ s/"/"/g;
27# $string =~ s/'/'/g;
28
29 bless \$string, $class;
30}
31
32sub as_string {
33 my $self = shift;
34 my $string = $$self;
35 $string =~ s/'/'/g;
36 return "'$string'";
37}
38
39sub as_xml {
40 my $self = shift;
41 my $string = $$self;
42 return "<Literal>$string</Literal>\n";
43}
44
45sub value {
46 my $self = shift;
47 $$self;
48}
49
50sub cmp {
51 my $self = shift;
52 my ($cmp, $swap) = @_;
53 if ($swap) {
54 return $cmp cmp $$self;
55 }
56 return $$self cmp $cmp;
57}
58
59sub evaluate {
60 my $self = shift;
61 $self;
62}
63
64sub to_boolean {
65 my $self = shift;
66 return (length($$self) > 0) ? XML::LibXML::Boolean->True : XML::LibXML::Boolean->False;
67}
68
69sub to_number { return XML::LibXML::Number->new($_[0]->value); }
70sub to_literal { return $_[0]; }
71
72sub string_value { return $_[0]->value; }
73
741;
75__END__
76
77=head1 NAME
78
79XML::LibXML::Literal - Simple string values.
80
81=head1 DESCRIPTION
82
83In XPath terms a Literal is what we know as a string.
84
85=head1 API
86
87=head2 new($string)
88
89Create a new Literal object with the value in $string. Note that &quot; and
90&apos; will be converted to " and ' respectively. That is not part of the XPath
91specification, but I consider it useful. Note though that you have to go
92to extraordinary lengths in an XML template file (be it XSLT or whatever) to
93make use of this:
94
95 <xsl:value-of select="&quot;I'm feeling &amp;quot;sad&amp;quot;&quot;"/>
96
97Which produces a Literal of:
98
99 I'm feeling "sad"
100
101=head2 value()
102
103Also overloaded as stringification, simply returns the literal string value.
104
105=head2 cmp($literal)
106
107Returns the equivalent of perl's cmp operator against the given $literal.
108
109=cut