line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use base qw(Exporter); |
3
|
6
|
|
|
6
|
|
106992
|
use strict; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
620
|
|
4
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
85
|
|
5
|
6
|
|
|
6
|
|
22
|
|
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
130
|
|
6
|
|
|
|
|
|
|
use Error::Pure qw(err); |
7
|
6
|
|
|
6
|
|
612
|
use Readonly; |
|
6
|
|
|
|
|
15790
|
|
|
6
|
|
|
|
|
150
|
|
8
|
6
|
|
|
6
|
|
100
|
use Wikibase::Datatype::MediainfoStatement; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
153
|
|
9
|
6
|
|
|
6
|
|
1722
|
use Wikibase::Datatype::Struct::MediainfoSnak; |
|
6
|
|
|
|
|
64839
|
|
|
6
|
|
|
|
|
129
|
|
10
|
6
|
|
|
6
|
|
1889
|
use Wikibase::Datatype::Struct::Utils qw(obj_array_ref2struct struct2snaks_array_ref); |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
221
|
|
11
|
6
|
|
|
6
|
|
1875
|
|
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
97
|
|
12
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.09; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my ($obj, $base_uri) = @_; |
17
|
|
|
|
|
|
|
|
18
|
4
|
|
|
4
|
1
|
30
|
if (! defined $obj) { |
19
|
|
|
|
|
|
|
err "Object doesn't exist."; |
20
|
4
|
50
|
|
|
|
9
|
} |
21
|
0
|
|
|
|
|
0
|
if (! $obj->isa('Wikibase::Datatype::MediainfoStatement')) { |
22
|
|
|
|
|
|
|
err "Object isn't 'Wikibase::Datatype::MediainfoStatement'."; |
23
|
4
|
50
|
|
|
|
10
|
} |
24
|
0
|
|
|
|
|
0
|
if (! defined $base_uri) { |
25
|
|
|
|
|
|
|
err 'Base URI is required.'; |
26
|
4
|
50
|
|
|
|
7
|
} |
27
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
my $struct_hr = { |
29
|
|
|
|
|
|
|
defined $obj->id ? ('id' => $obj->id) : (), |
30
|
|
|
|
|
|
|
'mainsnak' => Wikibase::Datatype::Struct::MediainfoSnak::obj2struct($obj->snak, $base_uri), |
31
|
|
|
|
|
|
|
@{$obj->property_snaks} ? ( |
32
|
|
|
|
|
|
|
%{obj_array_ref2struct($obj->property_snaks, 'qualifiers', $base_uri, |
33
|
4
|
|
|
|
|
9
|
'Wikibase::Datatype::MediainfoSnak', 'Wikibase::Datatype::Struct::MediainfoSnak')}, |
34
|
4
|
50
|
|
|
|
8
|
) : (), |
|
1
|
100
|
|
|
|
11
|
|
35
|
|
|
|
|
|
|
'rank' => $obj->rank, |
36
|
|
|
|
|
|
|
'type' => 'statement', |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return $struct_hr; |
40
|
|
|
|
|
|
|
} |
41
|
4
|
|
|
|
|
49
|
|
42
|
|
|
|
|
|
|
my $struct_hr = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::MediainfoStatement->new( |
45
|
0
|
|
|
0
|
1
|
|
exists $struct_hr->{'id'} ? ('id' => $struct_hr->{'id'}) : (), |
46
|
|
|
|
|
|
|
'property_snaks' => struct2snaks_array_ref($struct_hr, 'qualifiers', |
47
|
|
|
|
|
|
|
'Wikibase::Datatype::Struct::MediainfoSnak'), |
48
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Struct::MediainfoSnak::struct2obj($struct_hr->{'mainsnak'}), |
49
|
|
|
|
|
|
|
'rank' => $struct_hr->{'rank'}, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
return $obj; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=pod |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=encoding utf8 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Wikibase::Datatype::Struct::MediainfoStatement - Wikibase mediainfo statement structure serialization. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SYNOPSIS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::MediainfoStatement qw(obj2struct struct2obj); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
71
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This conversion is between objects defined in Wikibase::Datatype and structures |
76
|
|
|
|
|
|
|
serialized via JSON to MediaWiki. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SUBROUTINES |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 C<obj2struct> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Convert Wikibase::Datatype::MediainfoStatement instance to structure. |
85
|
|
|
|
|
|
|
C<$base_uri> is base URI of Wikibase system (e.g. http://test.wikidata.org/entity/). |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Returns reference to hash with structure. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 C<struct2obj> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Convert structure of mediainfo statement to object. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Returns Wikibase::Datatype::MediainfoStatement instance. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 ERRORS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
obj2struct(): |
100
|
|
|
|
|
|
|
Base URI is required. |
101
|
|
|
|
|
|
|
Object doesn't exist. |
102
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::MediainfoStatement'. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
use strict; |
107
|
|
|
|
|
|
|
use warnings; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Data::Printer; |
110
|
|
|
|
|
|
|
use Wikibase::Datatype::MediainfoSnak; |
111
|
|
|
|
|
|
|
use Wikibase::Datatype::MediainfoStatement; |
112
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::MediainfoStatement qw(obj2struct); |
113
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Item; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Object. |
116
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::MediainfoStatement->new( |
117
|
|
|
|
|
|
|
'id' => 'M123$00C04D2A-49AF-40C2-9930-C551916887E8', |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# instance of (P31) human (Q5) |
120
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::MediainfoSnak->new( |
121
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
122
|
|
|
|
|
|
|
'value' => 'Q5', |
123
|
|
|
|
|
|
|
), |
124
|
|
|
|
|
|
|
'property' => 'P31', |
125
|
|
|
|
|
|
|
), |
126
|
|
|
|
|
|
|
'property_snaks' => [ |
127
|
|
|
|
|
|
|
# of (P642) alien (Q474741) |
128
|
|
|
|
|
|
|
Wikibase::Datatype::MediainfoSnak->new( |
129
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
130
|
|
|
|
|
|
|
'value' => 'Q474741', |
131
|
|
|
|
|
|
|
), |
132
|
|
|
|
|
|
|
'property' => 'P642', |
133
|
|
|
|
|
|
|
), |
134
|
|
|
|
|
|
|
], |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Get structure. |
138
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/'); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Dump to output. |
141
|
|
|
|
|
|
|
p $struct_hr; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Output: |
144
|
|
|
|
|
|
|
# \ { |
145
|
|
|
|
|
|
|
# id "M123$00C04D2A-49AF-40C2-9930-C551916887E8", |
146
|
|
|
|
|
|
|
# mainsnak { |
147
|
|
|
|
|
|
|
# datavalue { |
148
|
|
|
|
|
|
|
# type "wikibase-entityid", |
149
|
|
|
|
|
|
|
# value { |
150
|
|
|
|
|
|
|
# entity-type "item", |
151
|
|
|
|
|
|
|
# id "Q5", |
152
|
|
|
|
|
|
|
# numeric-id 5 |
153
|
|
|
|
|
|
|
# } |
154
|
|
|
|
|
|
|
# }, |
155
|
|
|
|
|
|
|
# property "P31", |
156
|
|
|
|
|
|
|
# snaktype "value" |
157
|
|
|
|
|
|
|
# }, |
158
|
|
|
|
|
|
|
# qualifiers { |
159
|
|
|
|
|
|
|
# P642 [ |
160
|
|
|
|
|
|
|
# [0] { |
161
|
|
|
|
|
|
|
# datavalue { |
162
|
|
|
|
|
|
|
# type "wikibase-entityid", |
163
|
|
|
|
|
|
|
# value { |
164
|
|
|
|
|
|
|
# entity-type "item", |
165
|
|
|
|
|
|
|
# id "Q474741", |
166
|
|
|
|
|
|
|
# numeric-id 474741 |
167
|
|
|
|
|
|
|
# } |
168
|
|
|
|
|
|
|
# }, |
169
|
|
|
|
|
|
|
# property "P642", |
170
|
|
|
|
|
|
|
# snaktype "value" |
171
|
|
|
|
|
|
|
# } |
172
|
|
|
|
|
|
|
# ] |
173
|
|
|
|
|
|
|
# }, |
174
|
|
|
|
|
|
|
# qualifiers-order [ |
175
|
|
|
|
|
|
|
# [0] "P642" |
176
|
|
|
|
|
|
|
# ], |
177
|
|
|
|
|
|
|
# rank "normal", |
178
|
|
|
|
|
|
|
# type "statement" |
179
|
|
|
|
|
|
|
# } |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
use strict; |
184
|
|
|
|
|
|
|
use warnings; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::MediainfoStatement qw(struct2obj); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# Item structure. |
189
|
|
|
|
|
|
|
my $struct_hr = { |
190
|
|
|
|
|
|
|
'id' => 'M123$00C04D2A-49AF-40C2-9930-C551916887E8', |
191
|
|
|
|
|
|
|
'mainsnak' => { |
192
|
|
|
|
|
|
|
'datavalue' => { |
193
|
|
|
|
|
|
|
'type' => 'wikibase-entityid', |
194
|
|
|
|
|
|
|
'value' => { |
195
|
|
|
|
|
|
|
'entity-type' => 'item', |
196
|
|
|
|
|
|
|
'id' => 'Q5', |
197
|
|
|
|
|
|
|
'numeric-id' => 5, |
198
|
|
|
|
|
|
|
}, |
199
|
|
|
|
|
|
|
}, |
200
|
|
|
|
|
|
|
'property' => 'P31', |
201
|
|
|
|
|
|
|
'snaktype' => 'value', |
202
|
|
|
|
|
|
|
}, |
203
|
|
|
|
|
|
|
'qualifiers' => { |
204
|
|
|
|
|
|
|
'P642' => [{ |
205
|
|
|
|
|
|
|
'datavalue' => { |
206
|
|
|
|
|
|
|
'type' => 'wikibase-entityid', |
207
|
|
|
|
|
|
|
'value' => { |
208
|
|
|
|
|
|
|
'entity-type' => 'item', |
209
|
|
|
|
|
|
|
'id' => 'Q474741', |
210
|
|
|
|
|
|
|
'numeric-id' => 474741, |
211
|
|
|
|
|
|
|
}, |
212
|
|
|
|
|
|
|
}, |
213
|
|
|
|
|
|
|
'property' => 'P642', |
214
|
|
|
|
|
|
|
'snaktype' => 'value', |
215
|
|
|
|
|
|
|
}], |
216
|
|
|
|
|
|
|
}, |
217
|
|
|
|
|
|
|
'qualifiers-order' => [ |
218
|
|
|
|
|
|
|
'P642', |
219
|
|
|
|
|
|
|
], |
220
|
|
|
|
|
|
|
'rank' => 'normal', |
221
|
|
|
|
|
|
|
'type' => 'statement', |
222
|
|
|
|
|
|
|
}; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# Get object. |
225
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# Print out. |
228
|
|
|
|
|
|
|
print 'Id: '.$obj->id."\n"; |
229
|
|
|
|
|
|
|
print 'Statements: '.$obj->snak->property.' -> '.$obj->snak->datavalue->value."\n"; |
230
|
|
|
|
|
|
|
print "Qualifiers:\n"; |
231
|
|
|
|
|
|
|
foreach my $property_snak (@{$obj->property_snaks}) { |
232
|
|
|
|
|
|
|
print "\t".$property_snak->property.' -> '. |
233
|
|
|
|
|
|
|
$property_snak->datavalue->value."\n"; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
print 'Rank: '.$obj->rank."\n"; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# Output: |
238
|
|
|
|
|
|
|
# Id: M123$00C04D2A-49AF-40C2-9930-C551916887E8 |
239
|
|
|
|
|
|
|
# Statements: P31 -> Q5 |
240
|
|
|
|
|
|
|
# Qualifiers: |
241
|
|
|
|
|
|
|
# P642 -> Q474741 |
242
|
|
|
|
|
|
|
# Rank: normal |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
L<Error::Pure>, |
247
|
|
|
|
|
|
|
L<Exporter>, |
248
|
|
|
|
|
|
|
L<Readonly>, |
249
|
|
|
|
|
|
|
L<Wikibase::Datatype::MediainfoStatement>, |
250
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Snak>, |
251
|
|
|
|
|
|
|
L<Wikibase::Datatype::Struct::Utils>. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 SEE ALSO |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=over |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Struct> |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Wikibase structure serialization. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Statement> |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Wikibase statement datatype. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::MediainfoStatement> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Wikibase mediainfo statement datatype. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=back |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 REPOSITORY |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct> |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head1 AUTHOR |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
L<http://skim.cz> |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
© 2020-2022 Michal Josef Špaček |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
BSD 2-Clause License |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 VERSION |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
0.09 |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=cut |