| 1 | package Wikibase::Datatype::Print::Value::Quantity; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 47 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 47 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 47 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 47 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 47 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 47 | ▶ | use Unicode::UTF8 qw(decode_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 47 | Readonly::Array our @EXPORT_OK => qw(print); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 47 | our $VERSION = 0.21; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 17 | ▶ | sub print { | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 17 | my ($obj, $opts_hr) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Default options. | ||||||||||||||||||||||||||||
| 19 | 17 | ▶ | if (! defined $opts_hr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 9 | $opts_hr = {}; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 17 | ▶ | if (! exists $opts_hr->{'print_name'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 15 | $opts_hr->{'print_name'} = 1; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 17 | ▶ | if (! $obj->isa('Wikibase::Datatype::Value::Quantity')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 1 | err "Object isn't 'Wikibase::Datatype::Value::Quantity'."; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 16 | ▶ | if (exists $opts_hr->{'cb'} && ! $opts_hr->{'cb'}->isa('Wikibase::Cache')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $opts_hr->{"cb"} and not $opts_hr->{"cb"}->isa("Wikibase::Cache")
MC/DC100%2/2
exists $opts_hr->{"cb"} and not $opts_hr->{"cb"}->isa("Wikibase::Cache")
exists $opts_hr->{"cb"}
not $opts_hr->{"cb"}->isa("Wikibase::Cache")
Truth table100%3/3
A and not(B)
A= exists $opts_hr->{"cb"}B= not $opts_hr->{"cb"}->isa("Wikibase::Cache")
| |||||||||||||||||||||||||||||
| 31 | 1 | err "Option 'cb' must be a instance of Wikibase::Cache."; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Unit. | ||||||||||||||||||||||||||||
| 35 | 15 | my $unit; | |||||||||||||||||||||||||||
| 36 | 15 | ▶ | if ($obj->unit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 11 | ▶ | if ($opts_hr->{'print_name'} && exists $opts_hr->{'cb'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opts_hr->{"print_name"} and exists $opts_hr->{"cb"}
MC/DC50%1/2
$opts_hr->{"print_name"} and exists $opts_hr->{"cb"}
$opts_hr->{"print_name"}
exists $opts_hr->{"cb"}
Truth table66%2/3
A and B
A= $opts_hr->{"print_name"}B= exists $opts_hr->{"cb"}
| |||||||||||||||||||||||||||||
| 38 | 2 | $unit = $opts_hr->{'cb'}->get('label', $obj->unit); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 11 | ▶ | if (! defined $unit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 10 | $unit = $obj->unit; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # Output. | ||||||||||||||||||||||||||||
| 46 | 15 | my $ret = $obj->value; | |||||||||||||||||||||||||||
| 47 | 15 | ▶ | if ($obj->lower_bound) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 5 | ▶ | if ($obj->upper_bound) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 4 | my $tolerance = $obj->upper_bound - $obj->value; | |||||||||||||||||||||||||||
| 50 | 4 | ▶ | if ($obj->value != $obj->lower_bound | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$obj->value != $obj->lower_bound and $tolerance != $obj->value - $obj->lower_bound
MC/DC100%2/2
$obj->value != $obj->lower_bound and $tolerance != $obj->value - $obj->lower_bound
$obj->value != $obj->lower_bound
$tolerance != $obj->value - $obj->lower_bound
Truth table100%3/3
A and B
A= $obj->value != $obj->lower_boundB= $tolerance != $obj->value - $obj->lower_bound
| |||||||||||||||||||||||||||||
| 51 | && $tolerance != $obj->value - $obj->lower_bound) { | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | err 'Unsupported asymetric tolerance.'; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 3 | $ret .= decode_utf8('±').$tolerance; | |||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||
| 57 | 1 | err 'Unsupported lower bound without upper bound.'; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||
| 60 | 10 | ▶ | if ($obj->upper_bound) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 1 | err 'Unsupported upper bound without lower bound.'; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 12 | ▶ | if ($unit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 8 | $ret .= ' ('.$unit.')'; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 12 | return $ret; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 47 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||