| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
############################################################################### |
|
2
|
|
|
|
|
|
|
#Value.pm |
|
3
|
|
|
|
|
|
|
#Last Change: 2009-28-01 |
|
4
|
|
|
|
|
|
|
#Copyright (c) 2009 Marc-Seabstian "Maluku" Lucksch |
|
5
|
|
|
|
|
|
|
#Version 0.3 |
|
6
|
|
|
|
|
|
|
#################### |
|
7
|
|
|
|
|
|
|
#This file is part of the sofu.pm project, a parser library for an all-purpose |
|
8
|
|
|
|
|
|
|
#ASCII file format. More information can be found on the project web site |
|
9
|
|
|
|
|
|
|
#at http://sofu.sourceforge.net/ . |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
#sofu.pm is published under the terms of the MIT license, which basically means |
|
12
|
|
|
|
|
|
|
#"Do with it whatever you want". For more information, see the license.txt |
|
13
|
|
|
|
|
|
|
#file that should be enclosed with libsofu distributions. A copy of the license |
|
14
|
|
|
|
|
|
|
#is (at the time of this writing) also available at |
|
15
|
|
|
|
|
|
|
#http://www.opensource.org/licenses/mit-license.php . |
|
16
|
|
|
|
|
|
|
############################################################################### |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Data::Sofu::Value - A Sofu Value |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Provides a interface similar to the original SofuD (sofu.sf.net) |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 Synopsis |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
require Data::Sofu::Value; |
|
30
|
|
|
|
|
|
|
my $v = Data::Sofu::Value->new(); |
|
31
|
|
|
|
|
|
|
$v->set("Hello World"); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNTAX |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This Module is pure OO, exports nothing |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
package Data::Sofu::Value; |
|
40
|
|
|
|
|
|
|
|
|
41
|
3
|
|
|
3
|
|
24
|
use strict; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
213
|
|
|
42
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
2322
|
|
|
43
|
|
|
|
|
|
|
require Data::Sofu::Object; |
|
44
|
|
|
|
|
|
|
require Data::Sofu::List; |
|
45
|
|
|
|
|
|
|
require Data::Sofu::Undefined; |
|
46
|
|
|
|
|
|
|
require Data::Sofu; |
|
47
|
|
|
|
|
|
|
our @ISA = qw/Data::Sofu::Object/; |
|
48
|
|
|
|
|
|
|
our $VERSION="0.3"; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 METHODS |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Also look at C for methods, cause Value inherits from it |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 new([DATA]) |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Creates a new C and returns it |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Converts DATA to a string if DATA is given. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$val = Data::Sofu::Value->new("Hello World"); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new { |
|
66
|
672
|
|
|
672
|
1
|
1135
|
my $self={}; |
|
67
|
672
|
|
|
|
|
1880
|
bless $self,shift; |
|
68
|
672
|
|
|
|
|
1517
|
$$self{Value}=undef; |
|
69
|
672
|
50
|
|
|
|
2397
|
$$self{Value}="".shift if @_; |
|
70
|
672
|
50
|
|
|
|
1236
|
if (@_) { |
|
71
|
0
|
|
|
|
|
0
|
return Data::Sofu::List->new($$self{Value},@_); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
672
|
50
|
|
|
|
2673
|
return $self if defined $$self{Value}; |
|
74
|
0
|
|
|
|
|
0
|
return Data::Sofu::Undefined->new(); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 set(DATA) |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Sets the contents of this Value (replaces the old contents). |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Note: DATA will be converted to a string. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$v->set("Foobar"); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub set { |
|
88
|
576
|
|
|
576
|
1
|
20239
|
my $self=shift; |
|
89
|
576
|
|
|
|
|
1789
|
$$self{Value}="".shift; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 asValue() |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Returns itself, used to make sure this Value is really a Value (Data::Sofu::Map and Data::Sofu::List will die if called with this method) |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub asValue { |
|
99
|
66
|
|
|
66
|
1
|
298
|
return shift; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 asScalar() |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Perl only |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns this Value as a perl Scalar (same as toString) |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub asScalar { |
|
111
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
|
112
|
0
|
|
|
|
|
0
|
return $$self{Value}; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 toString() |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Returns this as a string |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub toString { |
|
122
|
598
|
|
|
598
|
1
|
921
|
my $self=shift; |
|
123
|
598
|
|
|
|
|
2551
|
return $$self{Value}; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 toUTF16(), toUTF8(), toUTF32() |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Not working in Perl (cause there is no wchar, char, dchar stuff going on, if you need to convert strings use "Encode") |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
They just return the same as toString() |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
#TODO |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub toUTF16 { |
|
137
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
|
138
|
0
|
|
|
|
|
0
|
return $$self{Value}; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
sub toUTF8 { |
|
141
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
|
142
|
0
|
|
|
|
|
0
|
return $$self{Value}; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
sub toUTF32 { |
|
145
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
|
146
|
0
|
|
|
|
|
0
|
return $$self{Value}; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
#/TODO |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 toInt() |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Return the Value as an Integer |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$v->toInt() === int $v->toString(); |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub toInt { |
|
159
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
|
160
|
0
|
|
|
|
|
0
|
return int $$self{Value}; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 toFloat() |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Return the Value as a Float |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
$v->toFloat() === $v->toString()+0; |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub toFloat { |
|
172
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
|
173
|
0
|
|
|
|
|
0
|
return $$self{Value}+0; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 toLong() |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Return the Value as a Long |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
$v->toLong() === int $v->toString(); |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub toLong { |
|
185
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
|
186
|
0
|
|
|
|
|
0
|
return int $$self{Value}; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 toDouble() |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Return the Value as a Double |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
$v->toDouble() === $v->toString()+0; |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub toDouble { |
|
198
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
|
199
|
0
|
|
|
|
|
0
|
return $$self{Value}+0; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 isValue() |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Returns 1 |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub isValue { |
|
209
|
564
|
|
|
564
|
1
|
1819
|
return 1 |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
#=head2 string() |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
#Same as Data::Sofu::Object::string(), but skips the Reference building. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
#=cut |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#sub string { #No References for Values at this time (just remove this function to enable them |
|
220
|
|
|
|
|
|
|
# my $self=shift; |
|
221
|
|
|
|
|
|
|
# return $self->stringify(@_); |
|
222
|
|
|
|
|
|
|
#} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 stringify(LEVEL,TREE) |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Returns a string representation of this Value. |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
LEVEL and TREE are ignored... |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub stringify { |
|
233
|
57
|
|
|
57
|
1
|
64
|
my $self=shift; |
|
234
|
57
|
|
|
|
|
61
|
my $level=shift; |
|
235
|
57
|
|
|
|
|
52
|
my $tree=shift; |
|
236
|
57
|
50
|
|
|
|
92
|
return "Value = ".Data::Sofu::Sofuescape($$self{Value}).$self->stringComment()."\n" unless $level; |
|
237
|
57
|
|
|
|
|
158
|
return Data::Sofu::Sofuescape($$self{Value}).$self->stringComment()."\n"; |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 binarify (TREE,BINARY DRIVER) |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Returns the binary version of this Value using the BINARY DRIVER. Don't call this one, use binaryPack instead. |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=cut |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub binarify { |
|
247
|
108
|
|
|
108
|
1
|
139
|
my $self=shift; |
|
248
|
108
|
|
|
|
|
117
|
my $tree=shift; |
|
249
|
108
|
|
|
|
|
131
|
my $bin=shift; |
|
250
|
108
|
|
|
|
|
323
|
my $str=$bin->packType(1); |
|
251
|
108
|
|
|
|
|
307
|
$str.=$self->packComment($bin); |
|
252
|
108
|
|
|
|
|
356
|
$str.=$bin->packText($$self{Value}); |
|
253
|
108
|
|
|
|
|
554
|
return $str; |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 BUGS |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
most of the methods do the same, because perl does the converting for you. |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
L, L, L, L, L, L, L |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
1; |