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