line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use base qw(Exporter); |
3
|
50
|
|
|
50
|
|
429450
|
use strict; |
|
50
|
|
|
|
|
128
|
|
|
50
|
|
|
|
|
3642
|
|
4
|
50
|
|
|
50
|
|
263
|
use warnings; |
|
50
|
|
|
|
|
85
|
|
|
50
|
|
|
|
|
726
|
|
5
|
50
|
|
|
50
|
|
185
|
|
|
50
|
|
|
|
|
92
|
|
|
50
|
|
|
|
|
1052
|
|
6
|
|
|
|
|
|
|
use Error::Pure qw(err); |
7
|
50
|
|
|
50
|
|
1198
|
use Readonly; |
|
50
|
|
|
|
|
17567
|
|
|
50
|
|
|
|
|
1531
|
|
8
|
50
|
|
|
50
|
|
351
|
use URI; |
|
50
|
|
|
|
|
85
|
|
|
50
|
|
|
|
|
1385
|
|
9
|
50
|
|
|
50
|
|
20426
|
use Wikibase::Datatype::Value::Globecoordinate; |
|
50
|
|
|
|
|
171528
|
|
|
50
|
|
|
|
|
1208
|
|
10
|
50
|
|
|
50
|
|
16907
|
|
|
50
|
|
|
|
|
1048001
|
|
|
50
|
|
|
|
|
13081
|
|
11
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.09; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my ($obj, $base_uri) = @_; |
16
|
|
|
|
|
|
|
|
17
|
6
|
|
|
6
|
1
|
17964
|
if (! defined $obj) { |
18
|
|
|
|
|
|
|
err "Object doesn't exist."; |
19
|
6
|
100
|
|
|
|
19
|
} |
20
|
1
|
|
|
|
|
5
|
if (! $obj->isa('Wikibase::Datatype::Value::Globecoordinate')) { |
21
|
|
|
|
|
|
|
err "Object isn't 'Wikibase::Datatype::Value::Globecoordinate'."; |
22
|
5
|
100
|
|
|
|
42
|
} |
23
|
1
|
|
|
|
|
4
|
if (! defined $base_uri) { |
24
|
|
|
|
|
|
|
err 'Base URI is required.'; |
25
|
4
|
100
|
|
|
|
11
|
} |
26
|
1
|
|
|
|
|
3
|
|
27
|
|
|
|
|
|
|
my $struct_hr = { |
28
|
|
|
|
|
|
|
'value' => { |
29
|
3
|
100
|
|
|
|
12
|
'altitude' => $obj->altitude ? $obj->altitude : 'null', |
30
|
|
|
|
|
|
|
'globe' => $base_uri.$obj->globe, |
31
|
|
|
|
|
|
|
'latitude' => $obj->latitude, |
32
|
|
|
|
|
|
|
'longitude' => $obj->longitude, |
33
|
|
|
|
|
|
|
'precision' => $obj->precision, |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
'type' => $obj->type, |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return $struct_hr; |
39
|
|
|
|
|
|
|
} |
40
|
3
|
|
|
|
|
120
|
|
41
|
|
|
|
|
|
|
my $struct_hr = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
if (! exists $struct_hr->{'type'} |
44
|
6
|
|
|
6
|
1
|
25209
|
|| $struct_hr->{'type'} ne 'globecoordinate') { |
45
|
|
|
|
|
|
|
|
46
|
6
|
100
|
100
|
|
|
47
|
err "Structure isn't for 'globecoordinate' datatype."; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
11
|
my $u = URI->new($struct_hr->{'value'}->{'globe'}); |
50
|
|
|
|
|
|
|
my @path_segments = $u->path_segments; |
51
|
|
|
|
|
|
|
my $globe = $path_segments[-1]; |
52
|
4
|
|
|
|
|
31
|
my $obj = Wikibase::Datatype::Value::Globecoordinate->new( |
53
|
4
|
|
|
|
|
13626
|
defined $struct_hr->{'value'}->{'altitude'} ? ( |
54
|
4
|
|
|
|
|
273
|
'altitude' => $struct_hr->{'value'}->{'altitude'}, |
55
|
|
|
|
|
|
|
) : (), |
56
|
|
|
|
|
|
|
'globe' => $globe, |
57
|
|
|
|
|
|
|
'precision' => $struct_hr->{'value'}->{'precision'}, |
58
|
|
|
|
|
|
|
'value' => [ |
59
|
|
|
|
|
|
|
$struct_hr->{'value'}->{'latitude'}, |
60
|
|
|
|
|
|
|
$struct_hr->{'value'}->{'longitude'}, |
61
|
|
|
|
|
|
|
], |
62
|
|
|
|
|
|
|
); |
63
|
4
|
100
|
|
|
|
56
|
|
64
|
|
|
|
|
|
|
return $obj; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
550
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=pod |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=encoding utf8 |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Wikibase::Datatype::Struct::Value::Globecoordinate - Wikibase globe coordinate structure serialization. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SYNOPSIS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value::Globecoordinate qw(obj2struct struct2obj); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
83
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This conversion is between objects defined in Wikibase::Datatype and structures |
88
|
|
|
|
|
|
|
serialized via JSON to MediaWiki. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SUBROUTINES |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 C<obj2struct> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, $base_uri); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Convert Wikibase::Datatype::Value::Globecoordinate instance to structure. |
97
|
|
|
|
|
|
|
C<$base_uri> is base URI of Wikibase system (e.g. http://test.wikidata.org/entity/). |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns reference to hash with structure. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 C<struct2obj> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Convert structure of globe coordinate to object. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Returns Wikibase::Datatype::Value::Globecoordinate instance. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 ERRORS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
obj2struct(): |
112
|
|
|
|
|
|
|
Base URI is required. |
113
|
|
|
|
|
|
|
Object doesn't exist. |
114
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Value::Globecoordinate'. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
struct2obj(): |
117
|
|
|
|
|
|
|
Structure isn't for 'globecoordinate' datatype. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
use strict; |
122
|
|
|
|
|
|
|
use warnings; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
use Data::Printer; |
125
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Globecoordinate; |
126
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value::Globecoordinate qw(obj2struct); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Object. |
129
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Value::Globecoordinate->new( |
130
|
|
|
|
|
|
|
'value' => [49.6398383, 18.1484031], |
131
|
|
|
|
|
|
|
); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# Get structure. |
134
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/'); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Dump to output. |
137
|
|
|
|
|
|
|
p $struct_hr; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Output: |
140
|
|
|
|
|
|
|
# \ { |
141
|
|
|
|
|
|
|
# type "globecoordinate", |
142
|
|
|
|
|
|
|
# value { |
143
|
|
|
|
|
|
|
# altitude "null", |
144
|
|
|
|
|
|
|
# globe "http://test.wikidata.org/entity/Q2", |
145
|
|
|
|
|
|
|
# latitude 49.6398383, |
146
|
|
|
|
|
|
|
# longitude 18.1484031, |
147
|
|
|
|
|
|
|
# precision 1e-07 |
148
|
|
|
|
|
|
|
# } |
149
|
|
|
|
|
|
|
# } |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
use strict; |
154
|
|
|
|
|
|
|
use warnings; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value::Globecoordinate qw(struct2obj); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Globe coordinate structure. |
159
|
|
|
|
|
|
|
my $struct_hr = { |
160
|
|
|
|
|
|
|
'type' => 'globecoordinate', |
161
|
|
|
|
|
|
|
'value' => { |
162
|
|
|
|
|
|
|
'altitude' => 'null', |
163
|
|
|
|
|
|
|
'globe' => 'http://test.wikidata.org/entity/Q2', |
164
|
|
|
|
|
|
|
'latitude' => 49.6398383, |
165
|
|
|
|
|
|
|
'longitude' => 18.1484031, |
166
|
|
|
|
|
|
|
'precision' => 1e-07, |
167
|
|
|
|
|
|
|
}, |
168
|
|
|
|
|
|
|
}; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# Get object. |
171
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Get globe. |
174
|
|
|
|
|
|
|
my $globe = $obj->globe; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# Get longitude. |
177
|
|
|
|
|
|
|
my $longitude = $obj->longitude; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# Get latitude. |
180
|
|
|
|
|
|
|
my $latitude = $obj->latitude; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# Get precision. |
183
|
|
|
|
|
|
|
my $precision = $obj->precision; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Get type. |
186
|
|
|
|
|
|
|
my $type = $obj->type; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# Get value. |
189
|
|
|
|
|
|
|
my $value_ar = $obj->value; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Print out. |
192
|
|
|
|
|
|
|
print "Globe: $globe\n"; |
193
|
|
|
|
|
|
|
print "Latitude: $latitude\n"; |
194
|
|
|
|
|
|
|
print "Longitude: $longitude\n"; |
195
|
|
|
|
|
|
|
print "Precision: $precision\n"; |
196
|
|
|
|
|
|
|
print "Type: $type\n"; |
197
|
|
|
|
|
|
|
print 'Value: '.(join ', ', @{$value_ar})."\n"; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# Output: |
200
|
|
|
|
|
|
|
# Globe: Q2 |
201
|
|
|
|
|
|
|
# Latitude: 49.6398383 |
202
|
|
|
|
|
|
|
# Longitude: 18.1484031 |
203
|
|
|
|
|
|
|
# Precision: 1e-07 |
204
|
|
|
|
|
|
|
# Type: globecoordinate |
205
|
|
|
|
|
|
|
# Value: 49.6398383, 18.1484031 |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
L<Error::Pure>, |
210
|
|
|
|
|
|
|
L<Exporter>, |
211
|
|
|
|
|
|
|
L<Readonly>, |
212
|
|
|
|
|
|
|
L<URI>, |
213
|
|
|
|
|
|
|
L<Wikibase::Datatype::Value::Globecoordinate>. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 SEE ALSO |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=over |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Struct> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Wikibase structure serialization. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Globecoordinate> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Wikibase globe coordinate value datatype. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=back |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 REPOSITORY |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 AUTHOR |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
L<http://skim.cz> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
© 2020-2022 Michal Josef Špaček |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
BSD 2-Clause License |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 VERSION |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
0.09 |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |