Number/Tolerant/Type/offset.pm

filter: Statementstmt 100% 27 / 27 Branchbran 75.0% 12 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 92.5% 50 / 54 CC 9 SCAR 16.2
CC
9
Cov
91%
valid_args
8.3
parse
2.0
BEGIN
1.0
CRAP 5.0
« Test/Tolerant.pm ↑ Summary Number/Tolerant/Union.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 (-l or +n)"
4  
5 package
6 Number::Tolerant::Type::offset;
7 25 ▶use parent qw(Number::Tolerant::Type);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶sub construct { shift;
Subroutine construct: called CC=1 SCAR=0.0
Pod documented
10 {
11 2 value => $_[0],
12 min => $_[0] + $_[1],
13 max => $_[0] + $_[2]
14 }
15 }
16  
17 27 ▶sub parse {
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
18 27 my ($self, $string, $factory) = @_;
19  
20 27 my $number = $self->number_re;
21 27 ▶ return $factory->new("$1", 'offset', "$2", "$3")
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /\A($number)\s+\(?\s*($number)\s+($number)\s*\)?\s*\z/ 1 26 27
22 if $string =~ m!\A($number)\s+\(?\s*($number)\s+($number)\s*\)?\s*\z!;
23  
24 26 return;
25 }
26  
27 2 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
28 2 my ($self) = @_;
29 return sprintf "%s (-%s +%s)",
30 $_[0]->{value},
31 ($_[0]->{value} - $_[0]->{min}),
32 2 ($_[0]->{max} - $_[0]->{value});
33 }
34  
35 110 ▶sub valid_args {
Subroutine valid_args: called CC=8 SCAR=21.2
Pod documented
36 110 my $self = shift;
37  
38 110 ▶ return if @_ > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 4 0 110 110
39  
40 110 ▶ return unless defined(my $lhs_number = $self->normalize_number($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $lhs_number = $self->normalize_number($_[0])) 23 87 110
41 87 ▶ return unless defined(my $minus_number = $self->normalize_number($_[2]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $minus_number = $self->normalize_number($_[2])) 56 31 87
42 31 ▶ return unless defined(my $plus_number = $self->normalize_number($_[3]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $plus_number = $self->normalize_number($_[3])) 29 2 31
43  
44 2 ▶ return unless $_[1] eq 'offset';
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] eq "offset" 0 2 2
45 2 ▶ return unless $minus_number <= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $minus_number <= 0 0 2 2
46 2 ▶ return unless $plus_number >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $plus_number >= 0 0 2 2
47  
48 2 return ($lhs_number, $minus_number, $plus_number)
49 }
50  
51 25 1;
52  
53 __END__
« Test/Tolerant.pm ↑ Summary Number/Tolerant/Union.pm »