lib/Schedule/Easing.pm

filter: Statementstmt 90.8% 79 / 87 Branchbran 73.3% 22 / 30 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 82.1% 120 / 146 CC 25 SCAR 19.1
CC
25
Cov
85%
schedule
10.3
matches
9.1
init
6.2
CRAP 6.7
« lib/Schedule/Easing/MD5.pm ↑ Summary 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.5';
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 1 ▶use Schedule::Easing::Pass;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 19 ▶sub new {
Subroutine new: called CC=4 SCAR=14.6
Pod undocumented
16 19 my ($ref,%opt)=@_;
17 19 ▶ my $class=ref($ref)||$ref;
Condition33%1/3
ref $ref || $ref
l!l&&r!l&&!r
0190
MC/DC0%0/2
ref $ref || $ref
ref $ref $ref
Truth table33%1/3
A || B
A= ref $refB= $ref
ABresult
1X1
011
000
18 my %self=(
19 schedule =>$opt{schedule}//[],
20 19 ▶ warnExpired=>$opt{warnExpired}//0,
Condition75%3/4
$opt{"schedule"} // []
l!l
190
$opt{"warnExpired"} // 0
l!l
163
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
21 );
22 19 return bless(\%self,$class)->init();
23 }
24  
25 1 my %builder=(
26 'block' =>'Schedule::Easing::Block',
27 'md5' =>'Schedule::Easing::MD5',
28 'numeric'=>'Schedule::Easing::Numeric',
29 'pass' =>'Schedule::Easing::Pass',
30 );
31  
32 19 ▶sub init {
Subroutine init: called CC=6 SCAR=18.3
Pod undocumented
33 19 my ($self)=@_;
34 19 ▶ if(ref($$self{schedule}) ne 'ARRAY') { confess('Schedule must be an array') }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"schedule"} ne "ARRAY") 1 18 19
35 18 foreach my $ease (@{$$self{schedule}}) {
36 21 ▶ if(ref($ease) ne 'HASH') { confess('Schedule entry must be a hash') }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ease ne "HASH") 1 20 21
37 20 ▶ if(my $builder=$builder{$$ease{type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $builder = $builder{$ease->{'type'}}) { } 20 0 20
38 20 $ease=$builder->new(%$ease,_warnExpired=>$$self{warnExpired});
39 0 ▶ if($$ease{_err}) { $$self{_err}=1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ease->{"_err"}) 0 19 19
40 }
41 0 else { confess("Unsupported entry type $$ease{type}") }
42 }
43 16 return $self;
44 }
45  
46 16136 ▶sub matches {
Subroutine matches: called CC=9 SCAR=22.0
Pod undocumented
47 16136 my ($self,%opt)=@_;
48 16136 ▶ $opt{ts}//=time();
Condition100%2/2
$opt{"ts"} //= time
l!l
161351
MC/DC100%1/1
$opt{"ts"} //= time
$opt{"ts"}
Truth table100%2/2
A
A= $opt{"ts"}
Aresult
11
00
49 16136 my @res;
50 16136 foreach my $event (@{$opt{events}}) {
51 242023 my $message;
52 242023 my $eref=ref($event);
53 242023 ▶ if(!$eref) { $message=$event }
Branch: 3 branches
BranchTrueFalseTotal
if (not $eref) { } 242019 4 242023
elsif ($eref eq 'HASH') { } 2 2 4
elsif ($eref eq 'ARRAY') { } 2 0 2
54 2 elsif($eref eq 'HASH') { $message=$$event{message} } # UNTESTED
55 2 elsif($eref eq 'ARRAY') { $message=$$event[0] } # UNTESTED
56 0 else { carp("Invalid event structure ($eref)"); next }
57 242023 my $includes=1;
58 242023 foreach my $ease (@{$$self{schedule}}) {
59 242038 ▶ if(my %data=$ease->matches($message)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%data) = $ease->matches($message)) 242006 32 242038
60 242006 $includes=$ease->includes($opt{ts},message=>$message,%data);
61 242006 last;
62 }
63 }
64 242023 ▶ if($includes) { push @res,$event }
Branch: 1 branch
BranchTrueFalseTotal
if ($includes) 119037 122986 242023
65 }
66 16136 return @res;
67 }
68  
69 8016 ▶sub schedule {
Subroutine schedule: called CC=9 SCAR=23.3
Pod undocumented
70 8016 my ($self,%opt)=@_;
71 8016 my @res;
72 8016 foreach my $event (@{$opt{events}}) {
73 8016 my $message;
74 8016 my $eref=ref($event);
75 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
76 0 elsif($eref eq 'HASH') { $message=$$event{message} } # UNTESTED
77 0 elsif($eref eq 'ARRAY') { $message=$$event[0] } # UNTESTED
78 0 else { carp("Invalid event structure ($eref)"); next }
79 8016 my $scheduled=0;
80 8016 foreach my $ease (@{$$self{schedule}}) {
81 8032 ▶ if(my %data=$ease->matches($message)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%data) = $ease->matches($message)) 8008 24 8032
82 8008 $scheduled=$ease->schedule(message=>$message,%data);
83 8008 ▶ if(defined($scheduled)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scheduled) 8000 8 8008
84 8000 my $intsched=int($scheduled);
85 8000 ▶ if($scheduled>$intsched) { $scheduled=1+$intsched }
Branch: 1 branch
BranchTrueFalseTotal
if ($scheduled > $intsched) 4441 3559 8000
86 }
87 8008 last;
88 }
89 }
90 8016 push @res,[$scheduled,$event];
91 }
92 8016 return @res;
93 }
94  
95 1 1;
96  
97 __END__
« lib/Schedule/Easing/MD5.pm ↑ Summary lib/Schedule/Easing/Numeric.pm »