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