line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wikibase::Datatype::Print::Value::Quantity; |
2
|
|
|
|
|
|
|
|
3
|
44
|
|
|
44
|
|
912618
|
use base qw(Exporter); |
|
44
|
|
|
|
|
155
|
|
|
44
|
|
|
|
|
4128
|
|
4
|
44
|
|
|
44
|
|
298
|
use strict; |
|
44
|
|
|
|
|
112
|
|
|
44
|
|
|
|
|
1420
|
|
5
|
44
|
|
|
44
|
|
269
|
use warnings; |
|
44
|
|
|
|
|
109
|
|
|
44
|
|
|
|
|
1347
|
|
6
|
|
|
|
|
|
|
|
7
|
44
|
|
|
44
|
|
1204
|
use Error::Pure qw(err); |
|
44
|
|
|
|
|
23432
|
|
|
44
|
|
|
|
|
1821
|
|
8
|
44
|
|
|
44
|
|
387
|
use Readonly; |
|
44
|
|
|
|
|
225
|
|
|
44
|
|
|
|
|
13153
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(print); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = 0.13; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub print { |
15
|
8
|
|
|
8
|
1
|
8593
|
my ($obj, $opts_hr) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Default options. |
18
|
8
|
100
|
|
|
|
27
|
if (! defined $opts_hr) { |
19
|
4
|
|
|
|
|
10
|
$opts_hr = {}; |
20
|
|
|
|
|
|
|
} |
21
|
8
|
100
|
|
|
|
21
|
if (! exists $opts_hr->{'print_name'}) { |
22
|
6
|
|
|
|
|
16
|
$opts_hr->{'print_name'} = 1; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
8
|
100
|
|
|
|
38
|
if (! $obj->isa('Wikibase::Datatype::Value::Quantity')) { |
26
|
1
|
|
|
|
|
5
|
err "Object isn't 'Wikibase::Datatype::Value::Quantity'."; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
7
|
100
|
100
|
|
|
37
|
if (exists $opts_hr->{'cb'} && ! $opts_hr->{'cb'}->isa('Wikibase::Cache')) { |
30
|
1
|
|
|
|
|
4
|
err "Option 'cb' must be a instance of Wikibase::Cache."; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Unit. |
34
|
6
|
|
|
|
|
11
|
my $unit; |
35
|
6
|
100
|
|
|
|
21
|
if ($obj->unit) { |
36
|
5
|
100
|
66
|
|
|
81
|
if ($opts_hr->{'print_name'} && exists $opts_hr->{'cb'}) { |
37
|
2
|
|
66
|
|
|
27
|
$unit = $opts_hr->{'cb'}->get('label', $obj->unit) || $obj->unit; |
38
|
|
|
|
|
|
|
} else { |
39
|
3
|
|
|
|
|
12
|
$unit = $obj->unit; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Output. |
44
|
6
|
|
|
|
|
207
|
my $ret = $obj->value; |
45
|
6
|
100
|
|
|
|
55
|
if ($unit) { |
46
|
5
|
|
|
|
|
17
|
$ret .= ' ('.$unit.')'; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
20
|
return $ret; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=pod |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=encoding utf8 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 NAME |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Wikibase::Datatype::Print::Value::Quantity - Wikibase quantity value pretty print helpers. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SYNOPSIS |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Value::Quantity qw(print); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
69
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SUBROUTINES |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 C<print> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $pretty_print_string = print($obj, $opts_hr); |
76
|
|
|
|
|
|
|
my @pretty_print_lines = print($obj, $opts_hr); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Construct pretty print output for L<Wikibase::Datatype::Value::Quantity> |
79
|
|
|
|
|
|
|
object. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Returns string in scalar context. |
82
|
|
|
|
|
|
|
Returns list of lines in array context. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 ERRORS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
print(): |
87
|
|
|
|
|
|
|
Object isn't 'Wikibase::Datatype::Value::Quantity'. |
88
|
|
|
|
|
|
|
Option 'cb' must be a instance of Wikibase::Cache. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=for comment filename=create_and_print_value_quantity.pl |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
use strict; |
95
|
|
|
|
|
|
|
use warnings; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Value::Quantity; |
98
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Quantity; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Object. |
101
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Value::Quantity->new( |
102
|
|
|
|
|
|
|
'unit' => 'Q190900', |
103
|
|
|
|
|
|
|
'value' => 10, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Print. |
107
|
|
|
|
|
|
|
print Wikibase::Datatype::Print::Value::Quantity::print($obj)."\n"; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Output: |
110
|
|
|
|
|
|
|
# 10 (Q190900) |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=for comment filename=create_and_print_value_quantity_translated.pl |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
use strict; |
117
|
|
|
|
|
|
|
use warnings; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
use Wikibase::Cache; |
120
|
|
|
|
|
|
|
use Wikibase::Cache::Backend::Basic; |
121
|
|
|
|
|
|
|
use Wikibase::Datatype::Print::Value::Quantity; |
122
|
|
|
|
|
|
|
use Wikibase::Datatype::Value::Quantity; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Object. |
125
|
|
|
|
|
|
|
my $obj = Wikibase::Datatype::Value::Quantity->new( |
126
|
|
|
|
|
|
|
'unit' => 'Q11573', |
127
|
|
|
|
|
|
|
'value' => 10, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Cache object. |
131
|
|
|
|
|
|
|
my $cache = Wikibase::Cache->new( |
132
|
|
|
|
|
|
|
'backend' => 'Basic', |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Print. |
136
|
|
|
|
|
|
|
print Wikibase::Datatype::Print::Value::Quantity::print($obj, { |
137
|
|
|
|
|
|
|
'cb' => $cache, |
138
|
|
|
|
|
|
|
})."\n"; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Output: |
141
|
|
|
|
|
|
|
# 10 (metre) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L<Error::Pure>, |
146
|
|
|
|
|
|
|
L<Exporter>, |
147
|
|
|
|
|
|
|
L<Readonly>. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SEE ALSO |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item L<Wikibase::Datatype::Value::Quantity> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Wikibase quantity value datatype. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 REPOSITORY |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print> |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 AUTHOR |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L<http://skim.cz> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
© 2020-2023 Michal Josef Špaček |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
BSD 2-Clause License |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 VERSION |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
0.13 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |