line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Print::Reference; |
2
|
|
|
|
|
|
|
|
3
|
32
|
|
|
32
|
|
353435
|
use base qw(Exporter); |
|
32
|
|
|
|
|
110
|
|
|
32
|
|
|
|
|
3170
|
|
4
|
32
|
|
|
32
|
|
217
|
use strict; |
|
32
|
|
|
|
|
77
|
|
|
32
|
|
|
|
|
673
|
|
5
|
32
|
|
|
32
|
|
191
|
use warnings; |
|
32
|
|
|
|
|
69
|
|
|
32
|
|
|
|
|
1068
|
|
6
|
|
|
|
|
|
|
|
7
|
32
|
|
|
32
|
|
1579
|
use Error::Pure qw(err); |
|
32
|
|
|
|
|
23746
|
|
|
32
|
|
|
|
|
1264
|
|
8
|
32
|
|
|
32
|
|
366
|
use Readonly; |
|
32
|
|
|
|
|
74
|
|
|
32
|
|
|
|
|
1340
|
|
9
|
32
|
|
|
32
|
|
13613
|
use Wikibase::Datatype::Print::Snak; |
|
32
|
|
|
|
|
112
|
|
|
32
|
|
|
|
|
6649
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(print); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.13; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub print { |
16
|
5
|
|
|
5
|
1
|
1580
|
my ($obj, $opts_hr) = @_; |
17
|
|
|
|
|
|
|
|
18
|
5
|
100
|
|
|
|
33
|
if (! $obj->isa('Wikibase::Datatype::Reference')) { |
19
|
1
|
|
|
|
|
8
|
err "Object isn't 'Wikibase::Datatype::Reference'."; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
|
|
36
|
my @ret = '{'; |
23
|
4
|
|
|
|
|
17
|
foreach my $snak (@{$obj->snaks}) { |
|
4
|
|
|
|
|
26
|
|
24
|
10
|
|
|
|
|
67
|
push @ret, map { ' '.$_ } Wikibase::Datatype::Print::Snak::print($snak, $opts_hr); |
|
10
|
|
|
|
|
47
|
|
25
|
|
|
|
|
|
|
} |
26
|
4
|
|
|
|
|
23
|
push @ret, '}'; |
27
|
|
|
|
|
|
|
|
28
|
4
|
100
|
|
|
|
50
|
return wantarray ? @ret : (join "\n", @ret); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=pod |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=encoding utf8 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Wikibase::Datatype::Print::Reference - Wikibase reference pretty print helpers. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Reference qw(print); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
48
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SUBROUTINES |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 C<print> |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
55
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Construct pretty print output for L<Wikibase::Datatype::Reference> |
58
|
|
|
|
|
|
|
object. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns string in scalar context. |
61
|
|
|
|
|
|
|
Returns list of lines in array context. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 ERRORS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
print(): |
66
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Reference'. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=for comment filename=create_and_print_reference.pl |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use strict; |
73
|
|
|
|
|
|
|
use warnings; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Reference; |
76
|
|
|
|
|
|
|
use Wikibase::Datatype::Reference; |
77
|
|
|
|
|
|
|
use Wikibase::Datatype::Snak; |
78
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::String; |
79
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Time; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Object. |
82
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Reference->new( |
83
|
|
|
|
|
|
|
'snaks' => [ |
84
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
85
|
|
|
|
|
|
|
'datatype' => 'url', |
86
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::String->new( |
87
|
|
|
|
|
|
|
'value' => 'https://skim.cz', |
88
|
|
|
|
|
|
|
), |
89
|
|
|
|
|
|
|
'property' => 'P854', |
90
|
|
|
|
|
|
|
), |
91
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
92
|
|
|
|
|
|
|
'datatype' => 'time', |
93
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Time->new( |
94
|
|
|
|
|
|
|
'value' => '+2013-12-07T00:00:00Z', |
95
|
|
|
|
|
|
|
), |
96
|
|
|
|
|
|
|
'property' => 'P813', |
97
|
|
|
|
|
|
|
), |
98
|
|
|
|
|
|
|
], |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Print. |
102
|
|
|
|
|
|
|
print Wikibase::Datatype::Print::Reference::print($obj)."\n"; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Output: |
105
|
|
|
|
|
|
|
# { |
106
|
|
|
|
|
|
|
# P854: https://skim.cz |
107
|
|
|
|
|
|
|
# P813: 7 December 2013 (Q1985727) |
108
|
|
|
|
|
|
|
# } |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=for comment filename=create_and_print_reference_translated.pl |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
use strict; |
115
|
|
|
|
|
|
|
use warnings; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
use Wikibase::Cache; |
118
|
|
|
|
|
|
|
use Wikibase::Cache::Backend::Basic; |
119
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Reference; |
120
|
|
|
|
|
|
|
use Wikibase::Datatype::Reference; |
121
|
|
|
|
|
|
|
use Wikibase::Datatype::Snak; |
122
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::String; |
123
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Time; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Object. |
126
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Reference->new( |
127
|
|
|
|
|
|
|
'snaks' => [ |
128
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
129
|
|
|
|
|
|
|
'datatype' => 'url', |
130
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::String->new( |
131
|
|
|
|
|
|
|
'value' => 'https://skim.cz', |
132
|
|
|
|
|
|
|
), |
133
|
|
|
|
|
|
|
'property' => 'P854', |
134
|
|
|
|
|
|
|
), |
135
|
|
|
|
|
|
|
Wikibase::Datatype::Snak->new( |
136
|
|
|
|
|
|
|
'datatype' => 'time', |
137
|
|
|
|
|
|
|
'datavalue' => Wikibase::Datatype::Value::Time->new( |
138
|
|
|
|
|
|
|
'value' => '+2013-12-07T00:00:00Z', |
139
|
|
|
|
|
|
|
), |
140
|
|
|
|
|
|
|
'property' => 'P813', |
141
|
|
|
|
|
|
|
), |
142
|
|
|
|
|
|
|
], |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Cache. |
146
|
|
|
|
|
|
|
my $cache = Wikibase::Cache->new( |
147
|
|
|
|
|
|
|
'backend' => 'Basic', |
148
|
|
|
|
|
|
|
); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# Print. |
151
|
|
|
|
|
|
|
print Wikibase::Datatype::Print::Reference::print($obj, { |
152
|
|
|
|
|
|
|
'cache' => $cache, |
153
|
|
|
|
|
|
|
})."\n"; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Output: |
156
|
|
|
|
|
|
|
# { |
157
|
|
|
|
|
|
|
# P854 (reference URL): https://skim.cz |
158
|
|
|
|
|
|
|
# P813 (retrieved): 7 December 2013 (Q1985727) |
159
|
|
|
|
|
|
|
# } |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L<Error::Pure>, |
164
|
|
|
|
|
|
|
L<Exporter>, |
165
|
|
|
|
|
|
|
L<Readonly>, |
166
|
|
|
|
|
|
|
L<Wikibase::Datatype::Print::Snak>. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 SEE ALSO |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=over |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Reference> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Wikibase reference datatype. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 REPOSITORY |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 AUTHOR |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L<http://skim.cz> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
© 2020-2023 Michal Josef Špaček |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
BSD 2-Clause License |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 VERSION |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
0.13 |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|