Debian Codegraph @

lib/XML/LibXML/Literal.pm

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