Number/Tolerant/Type/to.pm

filter: Statementstmt 100% 28 / 28 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 98.0% 50 / 51 CC 8 SCAR 12.4
CC
8
Cov
98%
valid_args
5.0
parse
4.0
BEGIN
1.0
CRAP 3.5
« Number/Tolerant/Type/more_than.pm ↑ Summary Number/Tolerant/Type.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 to n"
4  
5 package
6 Number::Tolerant::Type::to;
7 25 ▶use parent qw(Number::Tolerant::Type);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 32 ▶sub construct { shift;
Subroutine construct: called CC=1 SCAR=0.0
Pod documented
10 32 ($_[0],$_[1]) = sort { $a <=> $b } ($_[0],$_[1]);
11 {
12 32 value => ($_[0]+$_[1])/2,
13 variance => $_[1] - ($_[0]+$_[1])/2,
14 min => $_[0],
15 max => $_[1]
16 }
17 }
18  
19 26 ▶sub parse {
Subroutine parse: called CC=4 SCAR=13.9
Pod documented
20 26 my ($self, $string, $factory) = @_;
21 26 my $number = $self->number_re;
22 26 my $X = $self->variable_re;
23  
24 26 ▶ return $factory->new("$1", 'to', "$2")
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /\A($number)\s*<=$X<=\s*($number)\z/ 1 25 26
25 if ($string =~ m!\A($number)\s*<=$X<=\s*($number)\z!);
26 25 ▶ return $factory->new("$2", 'to', "$1")
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /\A($number)\s*>=$X>=\s*($number)\z/ 1 24 25
27 if ($string =~ m!\A($number)\s*>=$X>=\s*($number)\z!);
28 24 ▶ return $factory->new("$1", 'to', "$2")
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /\A($number)\s+to\s+($number)\z/ 1 23 24
29 if ($string =~ m!\A($number)\s+to\s+($number)\z!);
30 23 return;
31 }
32  
33 100 ▶sub valid_args {
Subroutine valid_args: called CC=5 SCAR=16.1
Pod documented
34 100 my $self = shift;
35  
36 100 ▶ return unless 3 == grep { defined } @_;
Branch: 1 branch
BranchTrueFalseTotal
unless 3 == grep({defined $_;} @_) 54 46 100
37 46 ▶ return unless $_[1] eq 'to';
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] eq "to" 13 33 46
38  
39 33 ▶ return unless defined (my $from = $self->normalize_number($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $from = $self->normalize_number($_[0])) 0 33 33
40 33 ▶ return unless defined (my $to = $self->normalize_number($_[2]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $to = $self->normalize_number($_[2])) 1 32 33
41  
42 32 return ($from, $to);
43 }
44  
45 25 1;
46  
47 __END__
« Number/Tolerant/Type/more_than.pm ↑ Summary Number/Tolerant/Type.pm »