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