| 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
| |||||||||||
| 25 | if ($string =~ m!\A($number)\s*<=$X<=\s*($number)\z!); | ||||||||||
| 26 | 25 | ▶ | return $factory->new("$2", 'to', "$1") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | if ($string =~ m!\A($number)\s*>=$X>=\s*($number)\z!); | ||||||||||
| 28 | 24 | ▶ | return $factory->new("$1", 'to', "$2") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 37 | 46 | ▶ | return unless $_[1] eq 'to'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | 33 | ▶ | return unless defined (my $from = $self->normalize_number($_[0])); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 33 | ▶ | return unless defined (my $to = $self->normalize_number($_[2])); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | |||||||||||
| 42 | 32 | return ($from, $to); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 25 | 1; | |||||||||
| 46 | |||||||||||
| 47 | __END__ | ||||||||||