| 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
| |||||||||||
| 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
| |||||||||||
| 33 | 29 | ▶ | return unless $_[1] eq 'plus_or_minus_pct'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | 6 | ▶ | return unless defined (my $base = $self->normalize_number($_[0])); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 6 | ▶ | return unless defined (my $var = $self->normalize_number($_[2])); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 5 | return ($base, $var); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 25 | 1; | |||||||||
| 42 | |||||||||||
| 43 | __END__ | ||||||||||