line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Struct::Sitelink; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
372049
|
use base qw(Exporter); |
|
8
|
|
|
|
|
58
|
|
|
8
|
|
|
|
|
1151
|
|
4
|
8
|
|
|
8
|
|
60
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
177
|
|
5
|
8
|
|
|
8
|
|
39
|
use warnings; |
|
8
|
|
|
|
|
28
|
|
|
8
|
|
|
|
|
295
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
1704
|
use Error::Pure qw(err); |
|
8
|
|
|
|
|
38288
|
|
|
8
|
|
|
|
|
320
|
|
8
|
8
|
|
|
8
|
|
246
|
use Readonly; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
347
|
|
9
|
8
|
|
|
8
|
|
3930
|
use Wikibase::Datatype::Sitelink; |
|
8
|
|
|
|
|
19263
|
|
|
8
|
|
|
|
|
253
|
|
10
|
8
|
|
|
8
|
|
4349
|
use Wikibase::Datatype::Value::Item; |
|
8
|
|
|
|
|
16695
|
|
|
8
|
|
|
|
|
2124
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.08; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub obj2struct { |
17
|
5
|
|
|
5
|
1
|
22699
|
my $obj = shift; |
18
|
|
|
|
|
|
|
|
19
|
5
|
100
|
|
|
|
20
|
if (! defined $obj) { |
20
|
1
|
|
|
|
|
7
|
err "Object doesn't exist."; |
21
|
|
|
|
|
|
|
} |
22
|
4
|
100
|
|
|
|
26
|
if (! $obj->isa('Wikibase::Datatype::Sitelink')) { |
23
|
1
|
|
|
|
|
7
|
err "Object isn't 'Wikibase::Datatype::Sitelink'."; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $struct_hr = { |
27
|
|
|
|
|
|
|
'badges' => [ |
28
|
3
|
|
|
|
|
8
|
map { $_->value } @{$obj->badges}, |
|
2
|
|
|
|
|
30
|
|
|
3
|
|
|
|
|
12
|
|
29
|
|
|
|
|
|
|
], |
30
|
|
|
|
|
|
|
'site' => $obj->site, |
31
|
|
|
|
|
|
|
'title' => $obj->title, |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
61
|
return $struct_hr; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub struct2obj { |
38
|
3
|
|
|
3
|
1
|
98
|
my $struct_hr = shift; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Sitelink->new( |
41
|
|
|
|
|
|
|
'badges' => [ |
42
|
2
|
|
|
|
|
133
|
map { Wikibase::Datatype::Value::Item->new('value' => $_); } |
43
|
3
|
|
|
|
|
17
|
@{$struct_hr->{'badges'}}, |
44
|
|
|
|
|
|
|
], |
45
|
|
|
|
|
|
|
'site' => $struct_hr->{'site'}, |
46
|
3
|
|
|
|
|
8
|
'title' => $struct_hr->{'title'}, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
3
|
|
|
|
|
273
|
return $obj; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=pod |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=encoding utf8 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 NAME |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Wikibase::Datatype::Struct::Sitelink - Wikibase sitelink structure serialization. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SYNOPSIS |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Sitelink qw(obj2struct struct2obj); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
69
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This conversion is between objects defined in Wikibase::Datatype and structures |
74
|
|
|
|
|
|
|
serialized via JSON to MediaWiki. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SUBROUTINES |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 C<obj2struct> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Convert Wikibase::Datatype::Sitelink instance to structure. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Returns reference to hash with structure. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 C<struct2obj> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Convert structure of sitelink to object. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Returns Wikibase::Datatype::Sitelink instance. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 ERRORS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
obj2struct(): |
97
|
|
|
|
|
|
|
Object doesn't exist. |
98
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Sitelink'. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
use strict; |
103
|
|
|
|
|
|
|
use warnings; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
use Data::Printer; |
106
|
|
|
|
|
|
|
use Wikibase::Datatype::Sitelink; |
107
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Sitelink qw(obj2struct); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Object. |
110
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Sitelink->new( |
111
|
|
|
|
|
|
|
'site' => 'enwiki', |
112
|
|
|
|
|
|
|
'title' => 'Main page', |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Get structure. |
116
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Dump to output. |
119
|
|
|
|
|
|
|
p $struct_hr; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Output: |
122
|
|
|
|
|
|
|
# \ { |
123
|
|
|
|
|
|
|
# badges [], |
124
|
|
|
|
|
|
|
# site "enwiki", |
125
|
|
|
|
|
|
|
# title "Main page" |
126
|
|
|
|
|
|
|
# } |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
use strict; |
131
|
|
|
|
|
|
|
use warnings; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Sitelink qw(struct2obj); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Item structure. |
136
|
|
|
|
|
|
|
my $struct_hr = { |
137
|
|
|
|
|
|
|
'badges' => [], |
138
|
|
|
|
|
|
|
'site' => 'enwiki', |
139
|
|
|
|
|
|
|
'title' => 'Main page', |
140
|
|
|
|
|
|
|
}; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Get object. |
143
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Get badges. |
146
|
|
|
|
|
|
|
my $badges_ar = [map { $_->value } @{$obj->badges}]; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Get site. |
149
|
|
|
|
|
|
|
my $site = $obj->site; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# Get title. |
152
|
|
|
|
|
|
|
my $title = $obj->title; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Print out. |
155
|
|
|
|
|
|
|
print 'Badges: '.(join ', ', @{$badges_ar})."\n"; |
156
|
|
|
|
|
|
|
print "Site: $site\n"; |
157
|
|
|
|
|
|
|
print "Title: $title\n"; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Output: |
160
|
|
|
|
|
|
|
# Badges: |
161
|
|
|
|
|
|
|
# Site: enwiki |
162
|
|
|
|
|
|
|
# Title: Main page |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<Error::Pure>, |
167
|
|
|
|
|
|
|
L<Exporter>, |
168
|
|
|
|
|
|
|
L<Readonly>, |
169
|
|
|
|
|
|
|
L<Wikibase::Datatype::Sitelink>, |
170
|
|
|
|
|
|
|
L<Wikibase::Datatype::Value::Item>. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 SEE ALSO |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Struct> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Wikibase structure serialization. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Sitelink> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Wikibase sitelink datatype. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 REPOSITORY |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 AUTHOR |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L<http://skim.cz> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
© Michal Josef Špaček 2020-2021 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
BSD 2-Clause License |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 VERSION |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
0.08 |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |