line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Struct::Value::Monolingual; |
2
|
|
|
|
|
|
|
|
3
|
50
|
|
|
50
|
|
1031065
|
use base qw(Exporter); |
|
50
|
|
|
|
|
172
|
|
|
50
|
|
|
|
|
4938
|
|
4
|
50
|
|
|
50
|
|
357
|
use strict; |
|
50
|
|
|
|
|
135
|
|
|
50
|
|
|
|
|
1049
|
|
5
|
50
|
|
|
50
|
|
267
|
use warnings; |
|
50
|
|
|
|
|
124
|
|
|
50
|
|
|
|
|
1515
|
|
6
|
|
|
|
|
|
|
|
7
|
50
|
|
|
50
|
|
1679
|
use Error::Pure qw(err); |
|
50
|
|
|
|
|
34700
|
|
|
50
|
|
|
|
|
2209
|
|
8
|
50
|
|
|
50
|
|
541
|
use Readonly; |
|
50
|
|
|
|
|
147
|
|
|
50
|
|
|
|
|
2123
|
|
9
|
50
|
|
|
50
|
|
11565
|
use Wikibase::Datatype::Value::Monolingual; |
|
50
|
|
|
|
|
1714265
|
|
|
50
|
|
|
|
|
13232
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.11; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub obj2struct { |
16
|
4
|
|
|
4
|
1
|
6069
|
my $obj = shift; |
17
|
|
|
|
|
|
|
|
18
|
4
|
100
|
|
|
|
23
|
if (! defined $obj) { |
19
|
1
|
|
|
|
|
8
|
err "Object doesn't exist."; |
20
|
|
|
|
|
|
|
} |
21
|
3
|
100
|
|
|
|
36
|
if (! $obj->isa('Wikibase::Datatype::Value::Monolingual')) { |
22
|
1
|
|
|
|
|
5
|
err "Object isn't 'Wikibase::Datatype::Value::Monolingual'."; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
13
|
my $struct_hr = { |
26
|
|
|
|
|
|
|
'value' => { |
27
|
|
|
|
|
|
|
'language' => $obj->language, |
28
|
|
|
|
|
|
|
'text' => $obj->value, |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
'type' => 'monolingualtext', |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
47
|
return $struct_hr; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub struct2obj { |
37
|
2
|
|
|
2
|
1
|
152
|
my $struct_hr = shift; |
38
|
|
|
|
|
|
|
|
39
|
2
|
50
|
33
|
|
|
21
|
if (! exists $struct_hr->{'type'} |
40
|
|
|
|
|
|
|
|| $struct_hr->{'type'} ne 'monolingualtext') { |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
err "Structure isn't for 'monolingualtext' datatype."; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Value::Monolingual->new( |
46
|
|
|
|
|
|
|
'language' => $struct_hr->{'value'}->{'language'}, |
47
|
2
|
|
|
|
|
43
|
'value' => $struct_hr->{'value'}->{'text'}, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
4894
|
return $obj; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=pod |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=encoding utf8 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Wikibase::Datatype::Struct::Value::Monolingual - Wikibase monolingual value structure serialization. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SYNOPSIS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value::Monolingual qw(obj2struct struct2obj); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
70
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This conversion is between objects defined in Wikibase::Datatype and structures |
75
|
|
|
|
|
|
|
serialized via JSON to MediaWiki. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SUBROUTINES |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 C<obj2struct> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Convert Wikibase::Datatype::Value::Monolingual instance to structure. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Returns reference to hash with structure. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 C<struct2obj> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Convert structure of monolingual to object. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Returns Wikibase::Datatype::Value::Monolingual instance. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 ERRORS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
obj2struct(): |
98
|
|
|
|
|
|
|
Object doesn't exist. |
99
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Value::Monolingual'. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
struct2obj(): |
102
|
|
|
|
|
|
|
Structure isn't for 'monolingualtext' datatype. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=for comment filename=obj2struct_value_monolingual.pl |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
use strict; |
109
|
|
|
|
|
|
|
use warnings; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
use Data::Printer; |
112
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Monolingual; |
113
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value::Monolingual qw(obj2struct); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Object. |
116
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Value::Monolingual->new( |
117
|
|
|
|
|
|
|
'language' => 'en', |
118
|
|
|
|
|
|
|
'value' => 'English text', |
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 "monolingualtext", |
130
|
|
|
|
|
|
|
# value { |
131
|
|
|
|
|
|
|
# language "en", |
132
|
|
|
|
|
|
|
# text "English text" |
133
|
|
|
|
|
|
|
# } |
134
|
|
|
|
|
|
|
# } |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=for comment filename=struct2obj_value_monolingual.pl |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
use strict; |
141
|
|
|
|
|
|
|
use warnings; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
use Wikibase::Datatype::Struct::Value::Monolingual qw(struct2obj); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Monolingualtext structure. |
146
|
|
|
|
|
|
|
my $struct_hr = { |
147
|
|
|
|
|
|
|
'type' => 'monolingualtext', |
148
|
|
|
|
|
|
|
'value' => { |
149
|
|
|
|
|
|
|
'language' => 'en', |
150
|
|
|
|
|
|
|
'text' => 'English text', |
151
|
|
|
|
|
|
|
}, |
152
|
|
|
|
|
|
|
}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Get object. |
155
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# Get language. |
158
|
|
|
|
|
|
|
my $language = $obj->language; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# Get type. |
161
|
|
|
|
|
|
|
my $type = $obj->type; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Get value. |
164
|
|
|
|
|
|
|
my $value = $obj->value; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# Print out. |
167
|
|
|
|
|
|
|
print "Language: $language\n"; |
168
|
|
|
|
|
|
|
print "Type: $type\n"; |
169
|
|
|
|
|
|
|
print "Value: $value\n"; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Output: |
172
|
|
|
|
|
|
|
# Language: en |
173
|
|
|
|
|
|
|
# Type: monolingualtext |
174
|
|
|
|
|
|
|
# Value: English text |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L<Error::Pure>, |
179
|
|
|
|
|
|
|
L<Exporter>, |
180
|
|
|
|
|
|
|
L<Readonly>, |
181
|
|
|
|
|
|
|
L<Wikibase::Datatype::Value::Monolingual>. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SEE ALSO |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=over |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Struct> |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Wikibase structure serialization. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Monolingual> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Wikibase monolingual value datatype. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=back |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 REPOSITORY |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct> |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 AUTHOR |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L<http://skim.cz> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
© 2020-2023 Michal Josef Špaček |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
BSD 2-Clause License |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 VERSION |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
0.11 |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |