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