line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Print::Form; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
347532
|
use base qw(Exporter); |
|
7
|
|
|
|
|
37
|
|
|
7
|
|
|
|
|
704
|
|
4
|
7
|
|
|
7
|
|
45
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
136
|
|
5
|
7
|
|
|
7
|
|
40
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
227
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
1431
|
use Error::Pure qw(err); |
|
7
|
|
|
|
|
24084
|
|
|
7
|
|
|
|
|
211
|
|
8
|
7
|
|
|
7
|
|
180
|
use Readonly; |
|
7
|
|
|
|
|
27
|
|
|
7
|
|
|
|
|
280
|
|
9
|
7
|
|
|
7
|
|
3118
|
use Wikibase::Datatype::Print::Statement; |
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
346
|
|
10
|
7
|
|
|
7
|
|
54
|
use Wikibase::Datatype::Print::Utils qw(print_statements); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
353
|
|
11
|
7
|
|
|
7
|
|
44
|
use Wikibase::Datatype::Print::Value::Item; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
237
|
|
12
|
7
|
|
|
7
|
|
44
|
use Wikibase::Datatype::Print::Value::Monolingual; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
2119
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(print); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.13; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub print { |
19
|
5
|
|
|
5
|
1
|
7590
|
my ($obj, $opts_hr) = @_; |
20
|
|
|
|
|
|
|
|
21
|
5
|
100
|
|
|
|
19
|
if (! defined $opts_hr) { |
22
|
2
|
|
|
|
|
5
|
$opts_hr = {}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
5
|
100
|
|
|
|
16
|
if (! exists $opts_hr->{'lang'}) { |
26
|
4
|
|
|
|
|
14
|
$opts_hr->{'lang'} = 'en'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
5
|
100
|
|
|
|
67
|
if (! $obj->isa('Wikibase::Datatype::Form')) { |
30
|
1
|
|
|
|
|
6
|
err "Object isn't 'Wikibase::Datatype::Form'."; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
27
|
my @ret = ( |
34
|
|
|
|
|
|
|
'Id: '.$obj->id, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Representation. |
38
|
|
|
|
|
|
|
# XXX In every time one? |
39
|
4
|
|
|
|
|
46
|
my ($representation) = @{$obj->representations}; |
|
4
|
|
|
|
|
17
|
|
40
|
4
|
50
|
|
|
|
55
|
if (defined $representation) { |
41
|
4
|
|
|
|
|
21
|
push @ret, 'Representation: '. |
42
|
|
|
|
|
|
|
Wikibase::Datatype::Print::Value::Monolingual::print($representation, $opts_hr); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Grammatical features |
46
|
4
|
|
|
|
|
59
|
my @gr_features; |
47
|
4
|
|
|
|
|
8
|
foreach my $gr_feature (@{$obj->grammatical_features}) { |
|
4
|
|
|
|
|
16
|
|
48
|
8
|
|
|
|
|
68
|
push @gr_features, |
49
|
|
|
|
|
|
|
Wikibase::Datatype::Print::Value::Item::print($gr_feature, $opts_hr); |
50
|
|
|
|
|
|
|
} |
51
|
4
|
50
|
|
|
|
18
|
if (@gr_features) { |
52
|
4
|
|
|
|
|
17
|
push @ret, 'Grammatical features: '.(join ', ', @gr_features); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Statements. |
56
|
4
|
|
|
|
|
23
|
push @ret, print_statements($obj, $opts_hr, |
57
|
|
|
|
|
|
|
\&Wikibase::Datatype::Print::Statement::print); |
58
|
|
|
|
|
|
|
|
59
|
4
|
100
|
|
|
|
40
|
return wantarray ? @ret : (join "\n", @ret); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=encoding utf8 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Wikibase::Datatype::Print::Form - Wikibase form pretty print helpers. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SYNOPSIS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Form qw(print); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
79
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SUBROUTINES |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 C<print> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
86
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Construct pretty print output for L<Wikibase::Datatype::Form> |
89
|
|
|
|
|
|
|
object. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns string in scalar context. |
92
|
|
|
|
|
|
|
Returns list of lines in array context. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 ERRORS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
print(): |
97
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Form'. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 EXAMPLE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=for comment filename=create_and_print_form.pl |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use strict; |
104
|
|
|
|
|
|
|
use warnings; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
use Unicode::UTF8 qw(decode_utf8 encode_utf8); |
107
|
|
|
|
|
|
|
use Wikibase::Datatype::Form; |
108
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Form; |
109
|
|
|
|
|
|
|
use Wikibase::Datatype::Snak; |
110
|
|
|
|
|
|
|
use Wikibase::Datatype::Statement; |
111
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Item; |
112
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::String; |
113
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Monolingual; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Object. |
116
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Form->new( |
117
|
|
|
|
|
|
|
'grammatical_features' => [ |
118
|
|
|
|
|
|
|
# singular |
119
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Item->new( |
120
|
|
|
|
|
|
|
'value' => 'Q110786', |
121
|
|
|
|
|
|
|
), |
122
|
|
|
|
|
|
|
# nominative case |
123
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Item->new( |
124
|
|
|
|
|
|
|
'value' => 'Q131105', |
125
|
|
|
|
|
|
|
), |
126
|
|
|
|
|
|
|
], |
127
|
|
|
|
|
|
|
'id' => 'L469-F1', |
128
|
|
|
|
|
|
|
'representations' => [ |
129
|
|
|
|
|
|
|
Wikibase::Datatype::Value::Monolingual->new( |
130
|
|
|
|
|
|
|
'language' => 'cs', |
131
|
|
|
|
|
|
|
'value' => 'pes', |
132
|
|
|
|
|
|
|
), |
133
|
|
|
|
|
|
|
], |
134
|
|
|
|
|
|
|
'statements' => [ |
135
|
|
|
|
|
|
|
Wikibase::Datatype::Statement->new( |
136
|
|
|
|
|
|
|
'snak' => Wikibase::Datatype::Snak->new( |
137
|
|
|
|
|
|
|
'datatype' => 'string', |
138
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::String->new( |
139
|
|
|
|
|
|
|
'value' => decode_utf8('pɛs'), |
140
|
|
|
|
|
|
|
), |
141
|
|
|
|
|
|
|
'property' => 'P898', |
142
|
|
|
|
|
|
|
), |
143
|
|
|
|
|
|
|
), |
144
|
|
|
|
|
|
|
], |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Print. |
148
|
|
|
|
|
|
|
print encode_utf8(scalar Wikibase::Datatype::Print::Form::print($obj))."\n"; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# Output: |
151
|
|
|
|
|
|
|
# Id: L469-F1 |
152
|
|
|
|
|
|
|
# Representation: pes (cs) |
153
|
|
|
|
|
|
|
# Grammatical features: Q110786, Q131105 |
154
|
|
|
|
|
|
|
# Statements: |
155
|
|
|
|
|
|
|
# P898: pɛs (normal) |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L<Error::Pure>, |
160
|
|
|
|
|
|
|
L<Exporter>, |
161
|
|
|
|
|
|
|
L<Readonly>, |
162
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Statement>, |
163
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Utils>, |
164
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Value::Item>, |
165
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Value::Monolingual>. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 SEE ALSO |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Form> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Wikibase form datatype. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 REPOSITORY |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L<http://skim.cz> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
© 2020-2023 Michal Josef Špaček |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
BSD 2-Clause License |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 VERSION |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
0.13 |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
198
|
|
|
|
|
|
|
|