line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Print::Item; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
906139
|
use base qw(Exporter); |
|
3
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
333
|
|
4
|
3
|
|
|
3
|
|
24
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
56
|
|
5
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
79
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
934
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
22856
|
|
|
3
|
|
|
|
|
99
|
|
8
|
3
|
|
|
3
|
|
117
|
use Readonly; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
124
|
|
9
|
3
|
|
|
3
|
|
1377
|
use Wikibase::Datatype::Print::Sitelink; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
122
|
|
10
|
3
|
|
|
3
|
|
1337
|
use Wikibase::Datatype::Print::Statement; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
173
|
|
11
|
3
|
|
|
|
|
155
|
use Wikibase::Datatype::Print::Utils qw(print_aliases print_descriptions |
12
|
3
|
|
|
3
|
|
23
|
print_labels print_sitelinks print_statements); |
|
3
|
|
|
|
|
8
|
|
13
|
3
|
|
|
3
|
|
17
|
use Wikibase::Datatype::Print::Value::Monolingual; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
830
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(print); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = 0.12; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub print { |
20
|
2
|
|
|
2
|
1
|
24540
|
my ($obj, $opts_hr) = @_; |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
8
|
if (! defined $opts_hr) { |
23
|
2
|
|
|
|
|
5
|
$opts_hr = {}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
2
|
50
|
|
|
|
8
|
if (! exists $opts_hr->{'lang'}) { |
27
|
2
|
|
|
|
|
5
|
$opts_hr->{'lang'} = 'en'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
2
|
100
|
|
|
|
14
|
if (! $obj->isa('Wikibase::Datatype::Item')) { |
31
|
1
|
|
|
|
|
6
|
err "Object isn't 'Wikibase::Datatype::Item'."; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
3
|
my @ret; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Label. |
37
|
1
|
|
|
|
|
6
|
push @ret, print_labels($obj, $opts_hr, |
38
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Value::Monolingual::print); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Description. |
41
|
1
|
|
|
|
|
8
|
push @ret, print_descriptions($obj, $opts_hr, |
42
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Value::Monolingual::print); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Aliases. |
45
|
1
|
|
|
|
|
6
|
push @ret, print_aliases($obj, $opts_hr, |
46
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Value::Monolingual::print); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Sitelinks. |
49
|
1
|
|
|
|
|
13
|
push @ret, print_sitelinks($obj, $opts_hr, |
50
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Sitelink::print); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Statements. |
53
|
1
|
|
|
|
|
5
|
push @ret, print_statements($obj, $opts_hr, |
54
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Statement::print); |
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
|
|
|
12
|
return wantarray ? @ret : (join "\n", @ret); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=encoding utf8 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 NAME |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Wikibase::Datatype::Print::Item - Wikibase item pretty print helpers. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SYNOPSIS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Item qw(print); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SUBROUTINES |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 C<print> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Construct pretty print output for L<Wikibase::Datatype::Item> |
84
|
|
|
|
|
|
|
object. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns string. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 ERRORS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
print(): |
91
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Item'. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 EXAMPLE |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=for comment filename=create_and_print_item.pl |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use strict; |
98
|
|
|
|
|
|
|
use warnings; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use Unicode::UTF8 qw(decode_utf8 encode_utf8); |
101
|
|
|
|
|
|
|
use Wikibase::Datatype::Item; |
102
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Item; |
103
|
|
|
|
|
|
|
use Wikibase::Datatype::Reference; |
104
|
|
|
|
|
|
|
use Wikibase::Datatype::Sitelink; |
105
|
|
|
|
|
|
|
use Wikibase::Datatype::Snak; |
106
|
|
|
|
|
|
|
use Wikibase::Datatype::Statement; |
107
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Item; |
108
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Monolingual; |
109
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::String; |
110
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Time; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Statements. |
113
|
|
|
|
|
|
|
my $statement1 = Wikibase::Datatype::Statement->new( |
114
|
|
|
|
|
|
|
# instance of (P31) human (Q5) |
115
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Snak->new( |
116
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
117
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
118
|
|
|
|
|
|
|
'value' => 'Q5', |
119
|
|
|
|
|
|
|
), |
120
|
|
|
|
|
|
|
'property' => 'P31', |
121
|
|
|
|
|
|
|
), |
122
|
|
|
|
|
|
|
'property_snaks' => [ |
123
|
|
|
|
|
|
|
# of (P642) alien (Q474741) |
124
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
125
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
126
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
127
|
|
|
|
|
|
|
'value' => 'Q474741', |
128
|
|
|
|
|
|
|
), |
129
|
|
|
|
|
|
|
'property' => 'P642', |
130
|
|
|
|
|
|
|
), |
131
|
|
|
|
|
|
|
], |
132
|
|
|
|
|
|
|
'references' => [ |
133
|
|
|
|
|
|
|
Wikibase::Datatype::Reference->new( |
134
|
|
|
|
|
|
|
'snaks' => [ |
135
|
|
|
|
|
|
|
# stated in (P248) Virtual International Authority File (Q53919) |
136
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
137
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
138
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
139
|
|
|
|
|
|
|
'value' => 'Q53919', |
140
|
|
|
|
|
|
|
), |
141
|
|
|
|
|
|
|
'property' => 'P248', |
142
|
|
|
|
|
|
|
), |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# VIAF ID (P214) 113230702 |
145
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
146
|
|
|
|
|
|
|
'datatype' => 'external-id', |
147
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::String->new( |
148
|
|
|
|
|
|
|
'value' => '113230702', |
149
|
|
|
|
|
|
|
), |
150
|
|
|
|
|
|
|
'property' => 'P214', |
151
|
|
|
|
|
|
|
), |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# retrieved (P813) 7 December 2013 |
154
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
155
|
|
|
|
|
|
|
'datatype' => 'time', |
156
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Time->new( |
157
|
|
|
|
|
|
|
'value' => '+2013-12-07T00:00:00Z', |
158
|
|
|
|
|
|
|
), |
159
|
|
|
|
|
|
|
'property' => 'P813', |
160
|
|
|
|
|
|
|
), |
161
|
|
|
|
|
|
|
], |
162
|
|
|
|
|
|
|
), |
163
|
|
|
|
|
|
|
], |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
my $statement2 = Wikibase::Datatype::Statement->new( |
166
|
|
|
|
|
|
|
# sex or gender (P21) male (Q6581097) |
167
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Snak->new( |
168
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
169
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
170
|
|
|
|
|
|
|
'value' => 'Q6581097', |
171
|
|
|
|
|
|
|
), |
172
|
|
|
|
|
|
|
'property' => 'P21', |
173
|
|
|
|
|
|
|
), |
174
|
|
|
|
|
|
|
'references' => [ |
175
|
|
|
|
|
|
|
Wikibase::Datatype::Reference->new( |
176
|
|
|
|
|
|
|
'snaks' => [ |
177
|
|
|
|
|
|
|
# stated in (P248) Virtual International Authority File (Q53919) |
178
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
179
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
180
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
181
|
|
|
|
|
|
|
'value' => 'Q53919', |
182
|
|
|
|
|
|
|
), |
183
|
|
|
|
|
|
|
'property' => 'P248', |
184
|
|
|
|
|
|
|
), |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# VIAF ID (P214) 113230702 |
187
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
188
|
|
|
|
|
|
|
'datatype' => 'external-id', |
189
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::String->new( |
190
|
|
|
|
|
|
|
'value' => '113230702', |
191
|
|
|
|
|
|
|
), |
192
|
|
|
|
|
|
|
'property' => 'P214', |
193
|
|
|
|
|
|
|
), |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# retrieved (P813) 7 December 2013 |
196
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
197
|
|
|
|
|
|
|
'datatype' => 'time', |
198
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Time->new( |
199
|
|
|
|
|
|
|
'value' => '+2013-12-07T00:00:00Z', |
200
|
|
|
|
|
|
|
), |
201
|
|
|
|
|
|
|
'property' => 'P813', |
202
|
|
|
|
|
|
|
), |
203
|
|
|
|
|
|
|
], |
204
|
|
|
|
|
|
|
), |
205
|
|
|
|
|
|
|
], |
206
|
|
|
|
|
|
|
); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# Main item. |
209
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Item->new( |
210
|
|
|
|
|
|
|
'aliases' => [ |
211
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
212
|
|
|
|
|
|
|
'language' => 'cs', |
213
|
|
|
|
|
|
|
'value' => decode_utf8('Douglas Noël Adams'), |
214
|
|
|
|
|
|
|
), |
215
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
216
|
|
|
|
|
|
|
'language' => 'cs', |
217
|
|
|
|
|
|
|
'value' => 'Douglas Noel Adams', |
218
|
|
|
|
|
|
|
), |
219
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
220
|
|
|
|
|
|
|
'language' => 'cs', |
221
|
|
|
|
|
|
|
'value' => 'Douglas N. Adams', |
222
|
|
|
|
|
|
|
), |
223
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
224
|
|
|
|
|
|
|
'language' => 'en', |
225
|
|
|
|
|
|
|
'value' => 'Douglas Noel Adams', |
226
|
|
|
|
|
|
|
), |
227
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
228
|
|
|
|
|
|
|
'language' => 'en', |
229
|
|
|
|
|
|
|
'value' => decode_utf8('Douglas Noël Adams'), |
230
|
|
|
|
|
|
|
), |
231
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
232
|
|
|
|
|
|
|
'language' => 'en', |
233
|
|
|
|
|
|
|
'value' => 'Douglas N. Adams', |
234
|
|
|
|
|
|
|
), |
235
|
|
|
|
|
|
|
], |
236
|
|
|
|
|
|
|
'descriptions' => [ |
237
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
238
|
|
|
|
|
|
|
'language' => 'cs', |
239
|
|
|
|
|
|
|
'value' => decode_utf8('anglický spisovatel, humorista a dramatik'), |
240
|
|
|
|
|
|
|
), |
241
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
242
|
|
|
|
|
|
|
'language' => 'en', |
243
|
|
|
|
|
|
|
'value' => 'English writer and humorist', |
244
|
|
|
|
|
|
|
), |
245
|
|
|
|
|
|
|
], |
246
|
|
|
|
|
|
|
'id' => 'Q42', |
247
|
|
|
|
|
|
|
'labels' => [ |
248
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
249
|
|
|
|
|
|
|
'language' => 'cs', |
250
|
|
|
|
|
|
|
'value' => 'Douglas Adams', |
251
|
|
|
|
|
|
|
), |
252
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
253
|
|
|
|
|
|
|
'language' => 'en', |
254
|
|
|
|
|
|
|
'value' => 'Douglas Adams', |
255
|
|
|
|
|
|
|
), |
256
|
|
|
|
|
|
|
], |
257
|
|
|
|
|
|
|
'page_id' => 123, |
258
|
|
|
|
|
|
|
'sitelinks' => [ |
259
|
|
|
|
|
|
|
Wikibase::Datatype::Sitelink->new( |
260
|
|
|
|
|
|
|
'site' => 'cswiki', |
261
|
|
|
|
|
|
|
'title' => 'Douglas Adams', |
262
|
|
|
|
|
|
|
), |
263
|
|
|
|
|
|
|
Wikibase::Datatype::Sitelink->new( |
264
|
|
|
|
|
|
|
'site' => 'enwiki', |
265
|
|
|
|
|
|
|
'title' => 'Douglas Adams', |
266
|
|
|
|
|
|
|
), |
267
|
|
|
|
|
|
|
], |
268
|
|
|
|
|
|
|
'statements' => [ |
269
|
|
|
|
|
|
|
$statement1, |
270
|
|
|
|
|
|
|
$statement2, |
271
|
|
|
|
|
|
|
], |
272
|
|
|
|
|
|
|
'title' => 'Q42', |
273
|
|
|
|
|
|
|
); |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
# Print. |
276
|
|
|
|
|
|
|
print encode_utf8(scalar Wikibase::Datatype::Print::Item::print($obj))."\n"; |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
# Output: |
279
|
|
|
|
|
|
|
# Label: Douglas Adams (en) |
280
|
|
|
|
|
|
|
# Description: English writer and humorist (en) |
281
|
|
|
|
|
|
|
# Aliases: |
282
|
|
|
|
|
|
|
# Douglas Noel Adams (en) |
283
|
|
|
|
|
|
|
# Douglas Noël Adams (en) |
284
|
|
|
|
|
|
|
# Douglas N. Adams (en) |
285
|
|
|
|
|
|
|
# Sitelinks: |
286
|
|
|
|
|
|
|
# Douglas Adams (cswiki) |
287
|
|
|
|
|
|
|
# Douglas Adams (enwiki) |
288
|
|
|
|
|
|
|
# Statements: |
289
|
|
|
|
|
|
|
# P31: Q5 (normal) |
290
|
|
|
|
|
|
|
# P642: Q474741 |
291
|
|
|
|
|
|
|
# References: |
292
|
|
|
|
|
|
|
# { |
293
|
|
|
|
|
|
|
# P248: Q53919 |
294
|
|
|
|
|
|
|
# P214: 113230702 |
295
|
|
|
|
|
|
|
# P813: 7 December 2013 (Q1985727) |
296
|
|
|
|
|
|
|
# } |
297
|
|
|
|
|
|
|
# P21: Q6581097 (normal) |
298
|
|
|
|
|
|
|
# References: |
299
|
|
|
|
|
|
|
# { |
300
|
|
|
|
|
|
|
# P248: Q53919 |
301
|
|
|
|
|
|
|
# P214: 113230702 |
302
|
|
|
|
|
|
|
# P813: 7 December 2013 (Q1985727) |
303
|
|
|
|
|
|
|
# } |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
L<Error::Pure>, |
308
|
|
|
|
|
|
|
L<Exporter>, |
309
|
|
|
|
|
|
|
L<Readonly>, |
310
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Sitelink>, |
311
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Statement>, |
312
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Utils>, |
313
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Value::Monolingual>. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head1 SEE ALSO |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=over |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Item> |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Wikibase item datatype. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=back |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head1 REPOSITORY |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print> |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=head1 AUTHOR |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
L<http://skim.cz> |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
© 2020-2023 Michal Josef Špaček |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
BSD 2-Clause License |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=head1 VERSION |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
0.12 |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=cut |
346
|
|
|
|
|
|
|
|