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