blib/lib/Schedule/Easing/Ease.pm

filter: Statementstmt 93.9% 62 / 66 Branchbran 90.9% 20 / 22 Conditioncond 77.7% 7 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 6 totaltotal 84.3% 102 / 121 CC 17 SCAR 20.4
CC
17
Cov
92%
validate
14.1
new
3.0
includes
2.0
CRAP 7.7
« blib/lib/Schedule/Easing/MD5.pm ↑ Summary blib/lib/Schedule/Easing.pm »
1 package Schedule::Easing::Ease;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Carp qw/carp confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Scalar::Util qw/looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Schedule::Easing::Function;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 our $VERSION='0.1.4';
11  
12 61 ▶sub _default_keys { return qw/name match begin final tsA tsB shape shapeopt _warnExpired/ }
Subroutine _default_keys: called CC=1 SCAR=0.0
13 sub _default {
14 return (
15 61 ▶ name =>undef,
Subroutine _default: called CC=1 SCAR=0.0
16 match=>qr/./,
17 begin=>0,
18 final=>1,
19 tsA =>0,
20 tsB =>1,
21 shape=>'linear',
22 shapeopt=>[],
23 _warnExpired=>0,
24 );
25 }
26  
27 sub new {
28 19 ▶ my ($ref,%opt)=@_;
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
29 19 ▶ my $class=ref($ref)||$ref;
Condition66%2/3
ref $ref || $ref
l!l&&r!l&&!r
2170
MC/DC0%0/2
ref $ref || $ref
ref $ref $ref
Truth table66%2/3
A || B
A= ref $refB= $ref
ABresult
1X1
011
000
30 my %self=(
31 $class->_default(),
32 (ref($ref)?%$ref:()),
33 19 ▶ map {$_=>$opt{$_}} grep {defined($opt{$_})} $class->_default_keys()
Branch: 1 branch
BranchTrueFalseTotal
ref $ref ? : 2 17 19
34 );
35 19 return bless(\%self,$class)->validate()->init();
36 }
37  
38 sub validate {
39 61 ▶ my ($self)=@_;
Subroutine validate: called CC=14 SCAR=26.5
Pod undocumented
40 61 foreach my $k (qw/tsA tsB begin final/) {
41 232 ▶ if(!defined($$self{$k})) { confess("Must be defined: $k") }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$k}) 0 232 232
42 232 ▶ if(!looks_like_number($$self{$k})) { confess("Must be numeric: $k") }
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($self->{$k})) 8 224 232
43 }
44 53 ▶ if(ref($$self{match}) ne 'Regexp') { confess('Must be Regexp: match') }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"match"} ne "Regexp") 3 50 53
45 50 ▶ if(ref($$self{name})) { confess('Must be string: name') }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"name"}) 0 50 50
46 50 foreach my $k (qw/begin final/) {
47 100 ▶ if($$self{$k}<0) { $$self{$k}=0; carp("$k<0"); $$self{_err}=1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$k} < 0) 1 99 100
48 100 ▶ if($$self{$k}>1) { $$self{$k}=1; carp("$k>1"); $$self{_err}=1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$k} > 1) 1 99 100
49 }
50 50 ▶ if($$self{tsA}>=$$self{tsB}) { $$self{tsB}=1+$$self{tsA}; carp('tsA>=tsB'); $$self{_err}=1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tsA"} >= $self->{"tsB"}) 1 49 50
51 50 ▶ if($$self{_warnExpired}&&($$self{tsB}<time())&&(abs(0.5-$$self{final})>=0.5)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_warnExpired"} and $self->{"tsB"} < time and abs "0.5" - $self->{"final"} >= "0.5") 2 48 50
Condition83%5/6
$self->{"_warnExpired"} and $self->{"tsB"} < time and abs "0.5" - $self->{"final"} >= "0.5"
!ll&&!rl&&r
4712
$self->{"_warnExpired"} and $self->{"tsB"} < time
!ll&&!rl&&r
4703
MC/DC66%2/3
$self->{"_warnExpired"} and $self->{"tsB"} < time and abs "0.5" - $self->{"final"} >= "0.5"
$self->{"_warnExpired"} $self->{"tsB"} < time abs "0.5" - $self->{"final"} >= "0.5"
Truth table75%3/4
A and B and C
A= $self->{"_warnExpired"}B= $self->{"tsB"} < timeC= abs "0.5" - $self->{"final"} >= "0.5"
ABCresult
0XX0
10X0
1100
1111
52 2 ▶ if($$self{name}) { carp("Event has expired: $$self{name}"); $$self{_err}=1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'name'}) { } 1 1 2
53 1 else { carp("Event with tsB=$$self{tsB} has expired"); $$self{_err}=1 }
54 }
55 50 $$self{_shaper} =Schedule::Easing::Function::shape($$self{shape});
56 50 $$self{_unshaper}=Schedule::Easing::Function::inverse($$self{shape});
57 50 return $self;
58 }
59  
60 sub init {
61 46 ▶ my ($self)=@_;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
62 46 $$self{tsrange}=int($$self{tsB}-$$self{tsA});
63 46 return $self;
64 }
65  
66 0 ▶sub includes { die 'Abstract' }
Subroutine includes: not called CC=1 SCAR=6.9
Pod undocumented
67 0 ▶sub schedule { die 'Abstract' }
Subroutine schedule: not called CC=1 SCAR=6.9
Pod undocumented
68  
69 sub matches {
70 200078 ▶ my ($self,$message)=@_;
Subroutine matches: called CC=2 SCAR=6.9
Pod undocumented
71 200078 ▶ if($message=~$$self{match}) { return (matched=>1,%+) }
Branch: 1 branch
BranchTrueFalseTotal
if ($message =~ /$self->{"match"}/) 200018 60 200078
72 60 return;
73 }
74  
75 5 1;
« blib/lib/Schedule/Easing/MD5.pm ↑ Summary blib/lib/Schedule/Easing.pm »