| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
|
2
|
|
|
|
|
|
|
## HTML Object - ~/lib/HTML/Object/Literal.pm |
|
3
|
|
|
|
|
|
|
## Version v0.2.0 |
|
4
|
|
|
|
|
|
|
## Copyright(c) 2021 DEGUEST Pte. Ltd. |
|
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
|
6
|
|
|
|
|
|
|
## Created 2021/04/22 |
|
7
|
|
|
|
|
|
|
## Modified 2022/09/18 |
|
8
|
|
|
|
|
|
|
## All rights reserved |
|
9
|
|
|
|
|
|
|
## |
|
10
|
|
|
|
|
|
|
## |
|
11
|
|
|
|
|
|
|
## This program is free software; you can redistribute it and/or modify it |
|
12
|
|
|
|
|
|
|
## under the same terms as Perl itself. |
|
13
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
|
14
|
|
|
|
|
|
|
package HTML::Object::Literal; |
|
15
|
|
|
|
|
|
|
BEGIN |
|
16
|
|
|
|
|
|
|
{ |
|
17
|
7
|
|
|
7
|
|
44
|
use strict; |
|
|
7
|
|
|
|
|
16
|
|
|
|
7
|
|
|
|
|
205
|
|
|
18
|
7
|
|
|
7
|
|
34
|
use warnings; |
|
|
7
|
|
|
|
|
21
|
|
|
|
7
|
|
|
|
|
204
|
|
|
19
|
7
|
|
|
7
|
|
34
|
use parent qw( Module::Generic::Scalar ); |
|
|
7
|
|
|
|
|
15
|
|
|
|
7
|
|
|
|
|
45
|
|
|
20
|
7
|
|
|
7
|
|
3222815
|
use vars qw( $VERSION ); |
|
|
7
|
|
|
|
|
20
|
|
|
|
7
|
|
|
|
|
326
|
|
|
21
|
7
|
|
|
7
|
|
140
|
our $VERSION = 'v0.2.0'; |
|
22
|
|
|
|
|
|
|
}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
7
|
|
|
7
|
|
38
|
use strict; |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
149
|
|
|
25
|
7
|
|
|
7
|
|
38
|
use warnings; |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
2911
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
1
|
|
sub as_number { return( shift->to_number( @_ ) ); } |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub as_string |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
|
32
|
0
|
|
|
|
|
|
my $txt = $self->SUPER::as_string; |
|
33
|
|
|
|
|
|
|
# $txt =~ s/'/'/g; |
|
34
|
0
|
|
|
|
|
|
$txt =~ s/(?<!\\)\'/\\\'/g; |
|
35
|
0
|
|
|
|
|
|
return( "'$txt'" ); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub as_xml |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
|
41
|
0
|
|
|
|
|
|
my $txt = $self->SUPER::as_string; |
|
42
|
0
|
|
|
|
|
|
return( "<Literal>$txt</Literal>\n" ); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
1
|
|
sub evaluate { return( shift( @_ ) ); } |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
1
|
|
sub getAttributes { return( shift->error( 'Cannot get attributes of a literal' ) ); } |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
1
|
|
sub getChildNodes { return( shift->error( 'Cannot get child nodes of a literal' ) ); } |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
1
|
|
sub getParentNode { return( shift->error( 'Cannot get parent node of a literal' ) ); } |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
1
|
|
sub string_value { return( shift->value ); } |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# sub to_boolean { return( shift->as_boolean ); } |
|
56
|
|
|
|
|
|
|
sub to_boolean |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
0
|
|
|
0
|
1
|
|
require HTML::Object::Boolean; |
|
59
|
0
|
0
|
|
|
|
|
return( shift->as_string ? HTML::Object::Boolean->True : HTML::Object::Boolean->False ); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
0
|
1
|
|
sub to_literal { return( shift( @_ ) ); } |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# sub to_number { return( shift->as_number ); } |
|
65
|
|
|
|
|
|
|
sub to_number |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
0
|
|
|
0
|
1
|
|
require HTML::Object::Number; |
|
68
|
0
|
|
|
|
|
|
return( HTML::Object::Number->new( shift->value ) ); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
0
|
1
|
|
sub value { return( shift->SUPER::as_string ); } |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
1
|
|
sub value_as_number { return( shift->as_number ); } |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
|
76
|
|
|
|
|
|
|
# NOTE: POD |
|
77
|
|
|
|
|
|
|
__END__ |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=encoding utf-8 |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
HTML::Object::Literal - Simple string values |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
use HTML::Object::Literal; |
|
88
|
|
|
|
|
|
|
my $this = HTML::Object::Literal->new || die( HTML::Object::Literal->error, "\n" ); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 VERSION |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
v0.2.0 |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
In XPath terms a Literal is what we know as a string. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This module inherits from L<Module::Generic::Scalar> |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 METHODS |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 new |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Provided with a C<string> and this will create a new Literal object with the value in C<string>. Note that " and ' will be converted to " and ' respectively. That is not part of the XPath specification, but I consider it useful. Note though that you have to go to extraordinary lengths in an XML template file (be it XSLT or whatever) to make use of this: |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
<xsl:value-of select=""I am feeling &quot;sad&quot;""/> |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Which produces a Literal of: |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
I am feeling "sad" |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 as_string |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns a string representation of this literal. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 as_xml |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns a string representation as xml. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 evaluate |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Does nothing. Returns the current object. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 getAttributes |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
If called, this would return an L<error|Module::Generic/error> |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 getChildNodes |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
If called, this would return an L<error|Module::Generic/error> |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 getParentNode |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
If called, this would return an L<error|Module::Generic/error> |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 string_value |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Returns the current value as-is. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 to_boolean |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Returns the current value as a L<boolean|Module::Generic::Boolean> |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 to_literal |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns the current object. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 to_number |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Returns the current value as a L<number|Module::Generic::Number> |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 value |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Also overloaded as stringification, simply returns the literal string value. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 value_as_number |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Returns the current value as a L<number|Module::Generic::Number> |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<HTML::Object>, L<HTML::Object::Attribute>, L<HTML::Object::Boolean>, L<HTML::Object::Closing>, L<HTML::Object::Collection>, L<HTML::Object::Comment>, L<HTML::Object::Declaration>, L<HTML::Object::Document>, L<HTML::Object::Element>, L<HTML::Object::Exception>, L<HTML::Object::Literal>, L<HTML::Object::Number>, L<HTML::Object::Root>, L<HTML::Object::Space>, L<HTML::Object::Text>, L<HTML::Object::XQuery> |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Copyright (c) 2021 DEGUEST Pte. Ltd. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
All rights reserved |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |