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