line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Struct::Value; |
2
|
|
|
|
|
|
|
|
3
|
42
|
|
|
42
|
|
361925
|
use base qw(Exporter); |
|
42
|
|
|
|
|
126
|
|
|
42
|
|
|
|
|
4381
|
|
4
|
42
|
|
|
42
|
|
284
|
use strict; |
|
42
|
|
|
|
|
90
|
|
|
42
|
|
|
|
|
865
|
|
5
|
42
|
|
|
42
|
|
250
|
use warnings; |
|
42
|
|
|
|
|
86
|
|
|
42
|
|
|
|
|
1353
|
|
6
|
|
|
|
|
|
|
|
7
|
42
|
|
|
42
|
|
1716
|
use Error::Pure qw(err); |
|
42
|
|
|
|
|
24617
|
|
|
42
|
|
|
|
|
1839
|
|
8
|
42
|
|
|
42
|
|
476
|
use Readonly; |
|
42
|
|
|
|
|
85
|
|
|
42
|
|
|
|
|
1961
|
|
9
|
42
|
|
|
42
|
|
8127
|
use Wikibase::Datatype::Value; |
|
42
|
|
|
|
|
19837
|
|
|
42
|
|
|
|
|
1241
|
|
10
|
42
|
|
|
42
|
|
20999
|
use Wikibase::Datatype::Struct::Value::Globecoordinate; |
|
42
|
|
|
|
|
145
|
|
|
42
|
|
|
|
|
2100
|
|
11
|
42
|
|
|
42
|
|
21493
|
use Wikibase::Datatype::Struct::Value::Item; |
|
42
|
|
|
|
|
128
|
|
|
42
|
|
|
|
|
2032
|
|
12
|
42
|
|
|
42
|
|
20457
|
use Wikibase::Datatype::Struct::Value::Monolingual; |
|
42
|
|
|
|
|
136
|
|
|
42
|
|
|
|
|
1967
|
|
13
|
42
|
|
|
42
|
|
20778
|
use Wikibase::Datatype::Struct::Value::Property; |
|
42
|
|
|
|
|
116
|
|
|
42
|
|
|
|
|
2069
|
|
14
|
42
|
|
|
42
|
|
21090
|
use Wikibase::Datatype::Struct::Value::Quantity; |
|
42
|
|
|
|
|
128
|
|
|
42
|
|
|
|
|
2043
|
|
15
|
42
|
|
|
42
|
|
20803
|
use Wikibase::Datatype::Struct::Value::String; |
|
42
|
|
|
|
|
117
|
|
|
42
|
|
|
|
|
1890
|
|
16
|
42
|
|
|
42
|
|
20176
|
use Wikibase::Datatype::Struct::Value::Time; |
|
42
|
|
|
|
|
213
|
|
|
42
|
|
|
|
|
22538
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = 0.08; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub obj2struct { |
23
|
44
|
|
|
44
|
1
|
27143
|
my ($obj, $base_uri) = @_; |
24
|
|
|
|
|
|
|
|
25
|
44
|
100
|
|
|
|
217
|
if (! defined $obj) { |
26
|
1
|
|
|
|
|
4
|
err "Object doesn't exist."; |
27
|
|
|
|
|
|
|
} |
28
|
43
|
100
|
|
|
|
210
|
if (! $obj->isa('Wikibase::Datatype::Value')) { |
29
|
1
|
|
|
|
|
4
|
err "Object isn't 'Wikibase::Datatype::Value'."; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
42
|
|
|
|
|
86
|
my $struct_hr; |
33
|
42
|
|
|
|
|
135
|
my $type = $obj->type; |
34
|
42
|
100
|
|
|
|
392
|
if ($type eq 'globecoordinate') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
35
|
1
|
|
|
|
|
5
|
$struct_hr = Wikibase::Datatype::Struct::Value::Globecoordinate::obj2struct($obj, $base_uri); |
36
|
|
|
|
|
|
|
} elsif ($type eq 'item') { |
37
|
15
|
|
|
|
|
57
|
$struct_hr = Wikibase::Datatype::Struct::Value::Item::obj2struct($obj); |
38
|
|
|
|
|
|
|
} elsif ($type eq 'monolingualtext') { |
39
|
1
|
|
|
|
|
6
|
$struct_hr = Wikibase::Datatype::Struct::Value::Monolingual::obj2struct($obj); |
40
|
|
|
|
|
|
|
} elsif ($type eq 'property') { |
41
|
1
|
|
|
|
|
4
|
$struct_hr = Wikibase::Datatype::Struct::Value::Property::obj2struct($obj); |
42
|
|
|
|
|
|
|
} elsif ($type eq 'quantity') { |
43
|
1
|
|
|
|
|
5
|
$struct_hr = Wikibase::Datatype::Struct::Value::Quantity::obj2struct($obj, $base_uri); |
44
|
|
|
|
|
|
|
} elsif ($type eq 'string') { |
45
|
18
|
|
|
|
|
77
|
$struct_hr = Wikibase::Datatype::Struct::Value::String::obj2struct($obj); |
46
|
|
|
|
|
|
|
} elsif ($type eq 'time') { |
47
|
4
|
|
|
|
|
17
|
$struct_hr = Wikibase::Datatype::Struct::Value::Time::obj2struct($obj, $base_uri); |
48
|
|
|
|
|
|
|
} else { |
49
|
1
|
|
|
|
|
5
|
err "Type '$type' is unsupported."; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
41
|
|
|
|
|
199
|
return $struct_hr; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub struct2obj { |
56
|
35
|
|
|
35
|
1
|
16420
|
my $struct_hr = shift; |
57
|
|
|
|
|
|
|
|
58
|
35
|
50
|
|
|
|
105
|
if (! exists $struct_hr->{'type'}) { |
59
|
0
|
|
|
|
|
0
|
err "Type doesn't exist."; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
35
|
|
|
|
|
62
|
my $obj; |
63
|
35
|
100
|
|
|
|
206
|
if ($struct_hr->{'type'} eq 'globecoordinate') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
64
|
1
|
|
|
|
|
5
|
$obj = Wikibase::Datatype::Struct::Value::Globecoordinate::struct2obj($struct_hr); |
65
|
|
|
|
|
|
|
} elsif ($struct_hr->{'type'} eq 'monolingualtext') { |
66
|
1
|
|
|
|
|
4
|
$obj = Wikibase::Datatype::Struct::Value::Monolingual::struct2obj($struct_hr); |
67
|
|
|
|
|
|
|
} elsif ($struct_hr->{'type'} eq 'quantity') { |
68
|
1
|
|
|
|
|
5
|
$obj = Wikibase::Datatype::Struct::Value::Quantity::struct2obj($struct_hr); |
69
|
|
|
|
|
|
|
} elsif ($struct_hr->{'type'} eq 'string') { |
70
|
16
|
|
|
|
|
60
|
$obj = Wikibase::Datatype::Struct::Value::String::struct2obj($struct_hr); |
71
|
|
|
|
|
|
|
} elsif ($struct_hr->{'type'} eq 'time') { |
72
|
4
|
|
|
|
|
17
|
$obj = Wikibase::Datatype::Struct::Value::Time::struct2obj($struct_hr); |
73
|
|
|
|
|
|
|
} elsif ($struct_hr->{'type'} eq 'wikibase-entityid') { |
74
|
11
|
100
|
|
|
|
36
|
if ($struct_hr->{'value'}->{'entity-type'} eq 'item') { |
|
|
50
|
|
|
|
|
|
75
|
10
|
|
|
|
|
43
|
$obj = Wikibase::Datatype::Struct::Value::Item::struct2obj($struct_hr); |
76
|
|
|
|
|
|
|
} elsif ($struct_hr->{'value'}->{'entity-type'} eq 'property') { |
77
|
1
|
|
|
|
|
5
|
$obj = Wikibase::Datatype::Struct::Value::Property::struct2obj($struct_hr); |
78
|
|
|
|
|
|
|
} else { |
79
|
0
|
|
|
|
|
0
|
err "Entity type '$struct_hr->{'value'}->{'entity-type'}' is unsupported."; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} else { |
82
|
1
|
|
|
|
|
6
|
err "Type '$struct_hr->{'type'}' is unsupported."; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
34
|
|
|
|
|
121
|
return $obj; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=pod |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=encoding utf8 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Wikibase::Datatype::Struct::Value - Wikibase value structure serialization. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SYNOPSIS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value qw(obj2struct struct2obj); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
105
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 DESCRIPTION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This conversion is between objects defined in Wikibase::Datatype and structures |
110
|
|
|
|
|
|
|
serialized via JSON to MediaWiki. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SUBROUTINES |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 C<obj2struct> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Convert Wikibase::Datatype::Value instance to structure. |
119
|
|
|
|
|
|
|
C<$base_uri> is base URI of Wikibase system (e.g. http://test.wikidata.org/entity/). |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns reference to hash with structure. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 C<struct2obj> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Convert structure of value to object. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Returns Wikibase::Datatype::Value instance. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 ERRORS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
obj2struct(): |
134
|
|
|
|
|
|
|
Object doesn't exist. |
135
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Value'. |
136
|
|
|
|
|
|
|
Type '%s' is unsupported. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
struct2obj(): |
139
|
|
|
|
|
|
|
Entity type '%s' is unsupported. |
140
|
|
|
|
|
|
|
Type doesn't exist. |
141
|
|
|
|
|
|
|
Type '%s' is unsupported. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
use strict; |
146
|
|
|
|
|
|
|
use warnings; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
use Data::Printer; |
149
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Time; |
150
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value qw(obj2struct); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Object. |
153
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Value::Time->new( |
154
|
|
|
|
|
|
|
'precision' => 10, |
155
|
|
|
|
|
|
|
'value' => '+2020-09-01T00:00:00Z', |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Get structure. |
159
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/'); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# Dump to output. |
162
|
|
|
|
|
|
|
p $struct_hr; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# Output: |
165
|
|
|
|
|
|
|
# \ { |
166
|
|
|
|
|
|
|
# type "time", |
167
|
|
|
|
|
|
|
# value { |
168
|
|
|
|
|
|
|
# after 0, |
169
|
|
|
|
|
|
|
# before 0, |
170
|
|
|
|
|
|
|
# calendarmodel "http://test.wikidata.org/entity/Q1985727", |
171
|
|
|
|
|
|
|
# precision 10, |
172
|
|
|
|
|
|
|
# time "+2020-09-01T00:00:00Z", |
173
|
|
|
|
|
|
|
# timezone 0 |
174
|
|
|
|
|
|
|
# } |
175
|
|
|
|
|
|
|
# } |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
use strict; |
180
|
|
|
|
|
|
|
use warnings; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value qw(struct2obj); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# Time structure. |
185
|
|
|
|
|
|
|
my $struct_hr = { |
186
|
|
|
|
|
|
|
'type' => 'time', |
187
|
|
|
|
|
|
|
'value' => { |
188
|
|
|
|
|
|
|
'after' => 0, |
189
|
|
|
|
|
|
|
'before' => 0, |
190
|
|
|
|
|
|
|
'calendarmodel' => 'http://test.wikidata.org/entity/Q1985727', |
191
|
|
|
|
|
|
|
'precision' => 10, |
192
|
|
|
|
|
|
|
'time' => '+2020-09-01T00:00:00Z', |
193
|
|
|
|
|
|
|
'timezone' => 0, |
194
|
|
|
|
|
|
|
}, |
195
|
|
|
|
|
|
|
}; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# Get object. |
198
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# Get calendar model. |
201
|
|
|
|
|
|
|
my $calendarmodel = $obj->calendarmodel; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# Get precision. |
204
|
|
|
|
|
|
|
my $precision = $obj->precision; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Get type. |
207
|
|
|
|
|
|
|
my $type = $obj->type; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# Get value. |
210
|
|
|
|
|
|
|
my $value = $obj->value; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# Print out. |
213
|
|
|
|
|
|
|
print "Calendar model: $calendarmodel\n"; |
214
|
|
|
|
|
|
|
print "Precision: $precision\n"; |
215
|
|
|
|
|
|
|
print "Type: $type\n"; |
216
|
|
|
|
|
|
|
print "Value: $value\n"; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# Output: |
219
|
|
|
|
|
|
|
# Calendar model: Q1985727 |
220
|
|
|
|
|
|
|
# Precision: 10 |
221
|
|
|
|
|
|
|
# Type: time |
222
|
|
|
|
|
|
|
# Value: +2020-09-01T00:00:00Z |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
L<Error::Pure>, |
227
|
|
|
|
|
|
|
L<Exporter>, |
228
|
|
|
|
|
|
|
L<Readonly>, |
229
|
|
|
|
|
|
|
L<Wikibase::Datatype::Value>, |
230
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Value::Globecoordinate>, |
231
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Value::Item>, |
232
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Value::Monolingual>, |
233
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Value::Property>, |
234
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Value::Quantity>, |
235
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Value::String>, |
236
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Value::Time>. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 SEE ALSO |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=over |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Struct> |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Wikibase structure serialization. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Globecoordinate> |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Wikibase globe coordinate value datatype. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Item> |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Wikibase item value datatype. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Monolingual> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Wikibase monolingual value datatype. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Property> |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Wikibase property value datatype. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Quantity> |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Wikibase quantity value datatype. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::String> |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Wikibase string value datatype. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Time> |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
Wikibase time value datatype. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=back |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head1 REPOSITORY |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct> |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head1 AUTHOR |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
L<http://skim.cz> |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
© Michal Josef Špaček 2020-2021 |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
BSD 2-Clause License |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head1 VERSION |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
0.08 |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=cut |