blib/lib/Schedule/Easing/Numeric.pm

filter: Statementstmt 86.4% 70 / 81 Branchbran 80.0% 32 / 40 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 5 totaltotal 81.1% 116 / 143 CC 23 SCAR 19.0
CC
23
Cov
84%
schedule
10.6
validate
9.5
includes
7.0
CRAP 6.7
« blib/lib/Schedule/Easing.pm ↑ Summary blib/lib/Schedule/Easing/Function.pm »
1 package Schedule::Easing::Numeric;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use parent qw/Schedule::Easing::Ease/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw/carp confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Scalar::Util qw/looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION='0.1.4';
10  
11 sub _default_keys {
12 20 ▶ my ($self)=@_;
Subroutine _default_keys: called CC=1 SCAR=0.0
13 return (
14 20 $self->SUPER::_default_keys(),
15 qw/ymin ymax/,
16 );
17 }
18 sub _default {
19 20 ▶ my ($self)=@_;
Subroutine _default: called CC=1 SCAR=0.0
20 return (
21 20 $self->SUPER::_default(),
22 match=>qr/(?<value>\d+)/,
23 ymin=>0,
24 ymax=>1,
25 );
26 }
27  
28 sub new {
29 20 ▶ my ($ref,%opt)=@_;
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
30 20 ▶ my $class=ref($ref)||$ref;
Condition66%2/3
ref $ref || $ref
l!l&&r!l&&!r
2180
MC/DC0%0/2
ref $ref || $ref
ref $ref $ref
Truth table66%2/3
A || B
A= ref $refB= $ref
ABresult
1X1
011
000
31 my %self=(
32 type =>'numeric',
33 $class->_default(),
34 (ref($ref)?%$ref:()),
35 20 ▶ map {$_=>$opt{$_}} grep {defined($opt{$_})} $class->_default_keys()
Branch: 1 branch
BranchTrueFalseTotal
ref $ref ? : 2 18 20
36 );
37 20 return bless(\%self,$class)->validate()->init();
38 }
39  
40 sub validate {
41 20 ▶ my ($self)=@_;
Subroutine validate: called CC=7 SCAR=22.5
Pod undocumented
42 20 $self->SUPER::validate();
43 19 foreach my $k (qw/ymin ymax/) {
44 37 ▶ if(!defined($$self{$k})) { confess("Must be defined: $k") }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$k}) 0 37 37
45 37 ▶ if(!looks_like_number($$self{$k})) { confess("Must be numeric: $k") }
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($self->{$k})) 2 35 37
46 }
47 17 ▶ if($$self{ymin}>$$self{ymax}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'ymin'} > $self->{'ymax'}) { } 0 17 17
elsif ($self->{'ymin'} == $self->{'ymax'}) { } 0 17 17
48 0 (@$self{qw/ymin ymax/})=@$self{qw/ymax ymin/};
49 0 carp('ymin>ymax');
50 0 $$self{_err}=1;
51 }
52 elsif($$self{ymin}==$$self{ymax}) {
53 0 $$self{ymax}=1+$$self{ymin};
54 0 carp('ymin==ymax');
55 0 $$self{_err}=1;
56 }
57 17 ▶ if($$self{match}!~/\(\?<value>.*?\)/) { confess("Match pattern does not contain 'value': $$self{match}") }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"match"} =~ /\(\?<value>.*?\)/) 2 15 17
58 15 return $self;
59 }
60  
61 sub init {
62 15 ▶ my ($self)=@_;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
63 15 $self->SUPER::init();
64 15 $$self{yrange}=$$self{ymax}-$$self{ymin};
65 15 return $self;
66 }
67  
68 sub includes {
69 97353 ▶ my ($self,$ts,%D)=@_;
Subroutine includes: called CC=7 SCAR=19.5
Pod undocumented
70 97353 ▶ if(!defined($ts)) { return 1 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ts) 1 97352 97353
71 97352 ▶ if(!defined($D{value})) { return 1 } # possibly a configuration for the default, but should never be called
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $D{"value"}) 1 97351 97352
72 97351 ▶ if(!looks_like_number($D{value})) { return 1 } # possibly a config, but can't cast non-numerics at this time
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($D{"value"})) 1 97350 97351
73 97350 my $p=$$self{_shaper}->($ts,@$self{qw/tsA tsB begin final/},@{$$self{shapeopt}});
74 97350 ▶ if($p<=0) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($p <= 0) 12020 85330 97350
75 85330 ▶ if($p>=1) { return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($p >= 1) 12018 73312 85330
76 73312 ▶ if($D{value}-$$self{ymin}<=$p*$$self{yrange}) { return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($D{"value"} - $self->{"ymin"} <= $p * $self->{"yrange"}) 36687 36625 73312
77 36625 return 0;
78 }
79  
80 sub schedule {
81 4757 ▶ my ($self,%D)=@_;
Subroutine schedule: called CC=9 SCAR=23.6
Pod undocumented
82 4757 ▶ if(!defined($D{value})) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $D{"value"}) 0 4757 4757
83 4757 ▶ if(!looks_like_number($D{value})) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($D{"value"})) 0 4757 4757
84 4757 my $p=($D{value}-$$self{ymin})/$$self{yrange};
85 4757 ▶ if($$self{begin}<$$self{final}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'begin'} < $self->{'final'}) { } 2757 2000 4757
elsif ($self->{'begin'} > $self->{'final'}) { } 2000 0 2000
86 2757 ▶ if($p<$$self{begin}) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($p < $self->{"begin"}) 118 2639 2757
87 2639 ▶ if($p>$$self{final}) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($p > $self->{"final"}) 59 2580 2639
88 }
89 elsif($$self{begin}>$$self{final}) {
90 2000 ▶ if($p>$$self{begin}) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($p > $self->{"begin"}) 0 2000 2000
91 2000 ▶ if($p<$$self{final}) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($p < $self->{"final"}) 0 2000 2000
92 }
93 4580 return $$self{_unshaper}->($p,@$self{qw/tsA tsB begin final/},@{$$self{shapeopt}});
94 }
95  
96 2 1;
« blib/lib/Schedule/Easing.pm ↑ Summary blib/lib/Schedule/Easing/Function.pm »