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