line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Print::Property; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
927190
|
use base qw(Exporter); |
|
3
|
|
|
|
|
39
|
|
|
3
|
|
|
|
|
413
|
|
4
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
59
|
|
5
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
82
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
961
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
23317
|
|
|
3
|
|
|
|
|
90
|
|
8
|
3
|
|
|
3
|
|
116
|
use Readonly; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
106
|
|
9
|
3
|
|
|
3
|
|
1431
|
use Wikibase::Datatype::Print::Statement; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
157
|
|
10
|
3
|
|
|
|
|
144
|
use Wikibase::Datatype::Print::Utils qw(print_aliases print_descriptions |
11
|
3
|
|
|
3
|
|
25
|
print_labels print_statements); |
|
3
|
|
|
|
|
10
|
|
12
|
3
|
|
|
3
|
|
17
|
use Wikibase::Datatype::Print::Value::Monolingual; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
809
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(print); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.13; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub print { |
19
|
2
|
|
|
2
|
1
|
9379
|
my ($obj, $opts_hr) = @_; |
20
|
|
|
|
|
|
|
|
21
|
2
|
50
|
|
|
|
9
|
if (! defined $opts_hr) { |
22
|
2
|
|
|
|
|
5
|
$opts_hr = {}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
2
|
50
|
|
|
|
8
|
if (! exists $opts_hr->{'lang'}) { |
26
|
2
|
|
|
|
|
6
|
$opts_hr->{'lang'} = 'en'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
2
|
100
|
|
|
|
13
|
if (! $obj->isa('Wikibase::Datatype::Property')) { |
30
|
1
|
|
|
|
|
7
|
err "Object isn't 'Wikibase::Datatype::Property'."; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
27
|
my @ret = ( |
34
|
|
|
|
|
|
|
'Data type: '.$obj->datatype, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Label. |
38
|
1
|
|
|
|
|
16
|
push @ret, print_labels($obj, $opts_hr, |
39
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Value::Monolingual::print); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Description. |
42
|
1
|
|
|
|
|
7
|
push @ret, print_descriptions($obj, $opts_hr, |
43
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Value::Monolingual::print); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Aliases. |
46
|
1
|
|
|
|
|
6
|
push @ret, print_aliases($obj, $opts_hr, |
47
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Value::Monolingual::print); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Statements. |
50
|
1
|
|
|
|
|
7
|
push @ret, print_statements($obj, $opts_hr, |
51
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Statement::print); |
52
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
10
|
return wantarray ? @ret : (join "\n", @ret); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=pod |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=encoding utf8 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Wikibase::Datatype::Print::Property - Wikibase property pretty print helpers. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Property qw(print); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
73
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SUBROUTINES |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 C<print> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
80
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Construct pretty print output for L<Wikibase::Datatype::Property> |
83
|
|
|
|
|
|
|
object. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Returns string in scalar context. |
86
|
|
|
|
|
|
|
Returns list of lines in array context. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 ERRORS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
print(): |
91
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Property'. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 EXAMPLE |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=for comment filename=create_and_print_property.pl |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use strict; |
98
|
|
|
|
|
|
|
use warnings; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use Unicode::UTF8 qw(decode_utf8 encode_utf8); |
101
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Property; |
102
|
|
|
|
|
|
|
use Wikibase::Datatype::Property; |
103
|
|
|
|
|
|
|
use Wikibase::Datatype::Reference; |
104
|
|
|
|
|
|
|
use Wikibase::Datatype::Sitelink; |
105
|
|
|
|
|
|
|
use Wikibase::Datatype::Snak; |
106
|
|
|
|
|
|
|
use Wikibase::Datatype::Statement; |
107
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Item; |
108
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Monolingual; |
109
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::String; |
110
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Time; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Statement. |
113
|
|
|
|
|
|
|
my $statement1 = Wikibase::Datatype::Statement->new( |
114
|
|
|
|
|
|
|
# instance of (P31) Wikidata property (Q18616576) |
115
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Snak->new( |
116
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
117
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Item->new( |
118
|
|
|
|
|
|
|
'value' => 'Q18616576', |
119
|
|
|
|
|
|
|
), |
120
|
|
|
|
|
|
|
'property' => 'P31', |
121
|
|
|
|
|
|
|
), |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Main item. |
125
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Property->new( |
126
|
|
|
|
|
|
|
'aliases' => [ |
127
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
128
|
|
|
|
|
|
|
'language' => 'cs', |
129
|
|
|
|
|
|
|
'value' => 'je', |
130
|
|
|
|
|
|
|
), |
131
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
132
|
|
|
|
|
|
|
'language' => 'en', |
133
|
|
|
|
|
|
|
'value' => 'is a', |
134
|
|
|
|
|
|
|
), |
135
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
136
|
|
|
|
|
|
|
'language' => 'en', |
137
|
|
|
|
|
|
|
'value' => 'is an', |
138
|
|
|
|
|
|
|
), |
139
|
|
|
|
|
|
|
], |
140
|
|
|
|
|
|
|
'datatype' => 'wikibase-item', |
141
|
|
|
|
|
|
|
'descriptions' => [ |
142
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
143
|
|
|
|
|
|
|
'language' => 'cs', |
144
|
|
|
|
|
|
|
'value' => decode_utf8('tato položka je jedna konkrétní věc (exemplář, '. |
145
|
|
|
|
|
|
|
'příklad) patřící do této třídy, kategorie nebo skupiny předmětů'), |
146
|
|
|
|
|
|
|
), |
147
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
148
|
|
|
|
|
|
|
'language' => 'en', |
149
|
|
|
|
|
|
|
'value' => 'that class of which this subject is a particular example and member', |
150
|
|
|
|
|
|
|
), |
151
|
|
|
|
|
|
|
], |
152
|
|
|
|
|
|
|
'id' => 'P31', |
153
|
|
|
|
|
|
|
'labels' => [ |
154
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
155
|
|
|
|
|
|
|
'language' => 'cs', |
156
|
|
|
|
|
|
|
'value' => decode_utf8('instance (čeho)'), |
157
|
|
|
|
|
|
|
), |
158
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
159
|
|
|
|
|
|
|
'language' => 'en', |
160
|
|
|
|
|
|
|
'value' => 'instance of', |
161
|
|
|
|
|
|
|
), |
162
|
|
|
|
|
|
|
], |
163
|
|
|
|
|
|
|
'page_id' => 3918489, |
164
|
|
|
|
|
|
|
'statements' => [ |
165
|
|
|
|
|
|
|
$statement1, |
166
|
|
|
|
|
|
|
], |
167
|
|
|
|
|
|
|
'title' => 'Property:P31', |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# Print. |
171
|
|
|
|
|
|
|
print encode_utf8(scalar Wikibase::Datatype::Print::Property::print($obj))."\n"; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Output: |
174
|
|
|
|
|
|
|
# Data type: wikibase-item |
175
|
|
|
|
|
|
|
# Label: instance of (en) |
176
|
|
|
|
|
|
|
# Description: that class of which this subject is a particular example and member (en) |
177
|
|
|
|
|
|
|
# Aliases: |
178
|
|
|
|
|
|
|
# is a (en) |
179
|
|
|
|
|
|
|
# is an (en) |
180
|
|
|
|
|
|
|
# Statements: |
181
|
|
|
|
|
|
|
# P31: Q18616576 (normal) |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L<Exporter>, |
186
|
|
|
|
|
|
|
L<Error::Pure>, |
187
|
|
|
|
|
|
|
L<Readonly>, |
188
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Statement>, |
189
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Utils>, |
190
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Value::Monolingual>. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 SEE ALSO |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=over |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Property> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Wikibase property datatype. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=back |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 REPOSITORY |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 AUTHOR |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L<http://skim.cz> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
© 2020-2023 Michal Josef Špaček |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
BSD 2-Clause License |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 VERSION |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
0.13 |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=cut |
223
|
|
|
|
|
|
|
|