Print/Value/Quantity.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 24 / 24 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 97.9% 94 / 96 CC 16 SCAR 24.8
CC
16
Cov
99%
print
16.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.9
« Print/Value/Time.pm ↑ Summary Print/Mediainfo.pm »
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
BranchTrueFalseTotal
unless (defined $opts_hr) 9 8 17
20 9 $opts_hr = {};
21 }
22 17 ▶ if (! exists $opts_hr->{'print_name'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts_hr->{"print_name"}) 15 2 17
23 15 $opts_hr->{'print_name'} = 1;
24 }
25  
26 17 ▶ if (! $obj->isa('Wikibase::Datatype::Value::Quantity')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->isa("Wikibase::Datatype::Value::Quantity")) 1 16 17
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
BranchTrueFalseTotal
if (exists $opts_hr->{"cb"} and not $opts_hr->{"cb"}->isa("Wikibase::Cache")) 1 15 16
Condition100%3/3
exists $opts_hr->{"cb"} and not $opts_hr->{"cb"}->isa("Wikibase::Cache")
!ll&&!rl&&r
1321
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($obj->unit) 11 4 15
37 11 ▶ if ($opts_hr->{'print_name'} && exists $opts_hr->{'cb'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts_hr->{"print_name"} and exists $opts_hr->{"cb"}) 2 9 11
Condition66%2/3
$opts_hr->{"print_name"} and exists $opts_hr->{"cb"}
!ll&&!rl&&r
092
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"}
ABresult
0X0
100
111
38 2 $unit = $opts_hr->{'cb'}->get('label', $obj->unit);
39 }
40 11 ▶ if (! defined $unit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $unit) 10 1 11
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
BranchTrueFalseTotal
if ($obj->lower_bound) { } 5 10 15
48 5 ▶ if ($obj->upper_bound) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->upper_bound) { } 4 1 5
49 4 my $tolerance = $obj->upper_bound - $obj->value;
50 4 ▶ if ($obj->value != $obj->lower_bound
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->value != $obj->lower_bound and $tolerance != $obj->value - $obj->lower_bound) 1 3 4
Condition100%3/3
$obj->value != $obj->lower_bound and $tolerance != $obj->value - $obj->lower_bound
!ll&&!rl&&r
121
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($obj->upper_bound) 1 9 10
61 1 err 'Unsupported upper bound without lower bound.';
62 }
63 }
64 12 ▶ if ($unit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit) 8 4 12
65 8 $ret .= ' ('.$unit.')';
66 }
67  
68 12 return $ret;
69 }
70  
71 47 1;
72  
73 __END__
« Print/Value/Time.pm ↑ Summary Print/Mediainfo.pm »