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