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