Number/Tolerant/Type/plus_or_minus_pct.pm

filter: Statementstmt 100% 24 / 24 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 97.7% 44 / 45 CC 6 SCAR 10.4
CC
6
Cov
97%
valid_args
5.0
parse
2.0
BEGIN
1.0
CRAP 2.8
« Number/Tolerant/Type/plus_or_minus.pm ↑ Summary Number/Tolerant/Type/or_less.pm »
1 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 # ABSTRACT: a tolerance "m +/- n%"
4  
5 package
6 Number::Tolerant::Type::plus_or_minus_pct;
7 25 ▶use parent qw(Number::Tolerant::Type);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶sub construct { shift;
Subroutine construct: called CC=1 SCAR=0.0
Pod documented
10 {
11 5 value => $_[0],
12 variance => $_[1],
13 min => $_[0] - $_[0]*($_[1]/100),
14 max => $_[0] + $_[0]*($_[1]/100)
15 }
16 }
17  
18 25 ▶sub parse {
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
19 25 my ($self, $string, $factory) = @_;
20 25 my $number = $self->number_re;
21  
22 25 ▶ return $factory->new("$1", 'plus_or_minus_pct', "$2")
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ m[\A($number)\s*\+/-\s*($number)%\z] 1 24 25
23 if $string =~ m!\A($number)\s*\+/-\s*($number)%\z!;
24 24 return;
25 }
26  
27 9 ▶sub stringify { "$_[0]->{value} +/- $_[0]->{variance}%" }
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
28  
29 102 ▶sub valid_args {
Subroutine valid_args: called CC=5 SCAR=16.1
Pod documented
30 102 my $self = shift;
31  
32 102 ▶ return unless 3 == grep { defined } @_;
Branch: 1 branch
BranchTrueFalseTotal
unless 3 == grep({defined $_;} @_) 73 29 102
33 29 ▶ return unless $_[1] eq 'plus_or_minus_pct';
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] eq "plus_or_minus_pct" 23 6 29
34  
35 6 ▶ return unless defined (my $base = $self->normalize_number($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $base = $self->normalize_number($_[0])) 0 6 6
36 6 ▶ return unless defined (my $var = $self->normalize_number($_[2]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $var = $self->normalize_number($_[2])) 1 5 6
37  
38 5 return ($base, $var);
39 }
40  
41 25 1;
42  
43 __END__
« Number/Tolerant/Type/plus_or_minus.pm ↑ Summary Number/Tolerant/Type/or_less.pm »