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