blib/lib/Schedule/Easing.pm

filter: Statementstmt 90.4% 76 / 84 Branchbran 73.3% 22 / 30 Conditioncond 60.0% 6 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 4 totaltotal 79.8% 115 / 144 CC 25 SCAR 19.3
CC
25
Cov
84%
schedule
10.3
matches
9.1
init
6.2
CRAP 6.9
« blib/lib/Schedule/Easing/Ease.pm ↑ Summary blib/lib/Schedule/Easing/Numeric.pm »
1 package Schedule::Easing;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION='0.1.4';
7  
8 1 ▶use Carp qw/carp confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Schedule::Easing::Block;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Schedule::Easing::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Schedule::Easing::Numeric;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub new {
15 18 ▶ my ($ref,%opt)=@_;
Subroutine new: called CC=4 SCAR=14.6
Pod undocumented
16 18 ▶ my $class=ref($ref)||$ref;
Condition33%1/3
ref $ref || $ref
l!l&&r!l&&!r
0180
MC/DC0%0/2
ref $ref || $ref
ref $ref $ref
Truth table33%1/3
A || B
A= ref $refB= $ref
ABresult
1X1
011
000
17 my %self=(
18 schedule =>$opt{schedule}//[],
19 18 ▶ warnExpired=>$opt{warnExpired}//0,
Condition75%3/4
$opt{"schedule"} // []
l!l
180
$opt{"warnExpired"} // 0
l!l
153
MC/DC0%0/1
$opt{"schedule"} // []
$opt{"schedule"}
MC/DC100%1/1
$opt{"warnExpired"} // 0
$opt{"warnExpired"}
Truth table50%1/2
A
A= $opt{"schedule"}
Aresult
11
00
Truth table100%2/2
A
A= $opt{"warnExpired"}
Aresult
11
00
20 );
21 18 return bless(\%self,$class)->init();
22 }
23  
24 1 my %builder=(
25 'block' =>'Schedule::Easing::Block',
26 'md5' =>'Schedule::Easing::MD5',
27 'numeric'=>'Schedule::Easing::Numeric',
28 );
29  
30 sub init {
31 18 ▶ my ($self)=@_;
Subroutine init: called CC=6 SCAR=18.3
Pod undocumented
32 18 ▶ if(ref($$self{schedule}) ne 'ARRAY') { confess('Schedule must be an array') }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"schedule"} ne "ARRAY") 1 17 18
33 17 foreach my $ease (@{$$self{schedule}}) {
34 20 ▶ if(ref($ease) ne 'HASH') { confess('Schedule entry must be a hash') }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ease ne "HASH") 1 19 20
35 19 ▶ if(my $builder=$builder{$$ease{type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $builder = $builder{$ease->{'type'}}) { } 19 0 19
36 19 $ease=$builder->new(%$ease,_warnExpired=>$$self{warnExpired});
37 18 ▶ if($$ease{_err}) { $$self{_err}=1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ease->{"_err"}) 0 18 18
38 }
39 0 else { confess("Unsupported entry type $$ease{type}") }
40 }
41 15 return $self;
42 }
43  
44 sub matches {
45 16111 ▶ my ($self,%opt)=@_;
Subroutine matches: called CC=9 SCAR=22.1
Pod undocumented
46 16111 ▶ $opt{ts}//=time();
Condition66%2/3
$opt{"ts"} //= time
l!l&&r!l&&!r
1611010
MC/DC0%0/2
$opt{"ts"} //= time
$opt{"ts"} time
Truth table66%2/3
A //= B
A= $opt{"ts"}B= time
ABresult
1X1
011
000
47 16111 my @res;
48 16111 foreach my $event (@{$opt{events}}) {
49 192023 my $message;
50 192023 my $eref=ref($event);
51 192023 ▶ if(!$eref) { $message=$event }
Branch: 3 branches
BranchTrueFalseTotal
if (not $eref) { } 192019 4 192023
elsif ($eref eq 'HASH') { } 2 2 4
elsif ($eref eq 'ARRAY') { } 2 0 2
52 2 elsif($eref eq 'HASH') { $message=$$event{message} } # UNTESTED
53 2 elsif($eref eq 'ARRAY') { $message=$$event[0] } # UNTESTED
54 0 else { carp("Invalid event structure ($eref)"); next }
55 192023 my $includes=1;
56 192023 foreach my $ease (@{$$self{schedule}}) {
57 192038 ▶ if(my %data=$ease->matches($message)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%data) = $ease->matches($message)) 192006 32 192038
58 192006 $includes=$ease->includes($opt{ts},message=>$message,%data);
59 192006 last;
60 }
61 }
62 192023 ▶ if($includes) { push @res,$event }
Branch: 1 branch
BranchTrueFalseTotal
if ($includes) 95977 96046 192023
63 }
64 16111 return @res;
65 }
66  
67 sub schedule {
68 8016 ▶ my ($self,%opt)=@_;
Subroutine schedule: called CC=9 SCAR=23.3
Pod undocumented
69 8016 my @res;
70 8016 foreach my $event (@{$opt{events}}) {
71 8016 my $message;
72 8016 my $eref=ref($event);
73 8016 ▶ if(!$eref) { $message=$event }
Branch: 3 branches
BranchTrueFalseTotal
if (not $eref) { } 8016 0 8016
elsif ($eref eq 'HASH') { } 0 0 0
elsif ($eref eq 'ARRAY') { } 0 0 0
74 0 elsif($eref eq 'HASH') { $message=$$event{message} } # UNTESTED
75 0 elsif($eref eq 'ARRAY') { $message=$$event[0] } # UNTESTED
76 0 else { carp("Invalid event structure ($eref)"); next }
77 8016 my $scheduled=0;
78 8016 foreach my $ease (@{$$self{schedule}}) {
79 8032 ▶ if(my %data=$ease->matches($message)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%data) = $ease->matches($message)) 8008 24 8032
80 8008 $scheduled=$ease->schedule(message=>$message,%data);
81 8008 ▶ if(defined($scheduled)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scheduled) 8000 8 8008
82 8000 my $intsched=int($scheduled);
83 8000 ▶ if($scheduled>$intsched) { $scheduled=1+$intsched }
Branch: 1 branch
BranchTrueFalseTotal
if ($scheduled > $intsched) 4441 3559 8000
84 }
85 8008 last;
86 }
87 }
88 8016 push @res,[$scheduled,$event];
89 }
90 8016 return @res;
91 }
92  
93 1 1;
94  
95 __END__
« blib/lib/Schedule/Easing/Ease.pm ↑ Summary blib/lib/Schedule/Easing/Numeric.pm »