| 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
MC/DC0%0/2
ref $ref || $ref
ref $ref
$ref
Truth table33%1/3
A || B
A= ref $refB= $ref
| |||||||||||||||||||||||
| 17 | my %self=( | ||||||||||||||||||||||
| 18 | schedule =>$opt{schedule}//[], | ||||||||||||||||||||||
| 19 | 18 | ▶ | warnExpired=>$opt{warnExpired}//0, | ||||||||||||||||||||
|
Condition75%3/4
$opt{"schedule"} // []
$opt{"warnExpired"} // 0
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"}
Truth table100%2/2
A
A= $opt{"warnExpired"}
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 33 | 17 | foreach my $ease (@{$$self{schedule}}) { | |||||||||||||||||||||
| 34 | 20 | ▶ | if(ref($ease) ne 'HASH') { confess('Schedule entry must be a hash') } | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 35 | 19 | ▶ | if(my $builder=$builder{$$ease{type}}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 36 | 19 | $ease=$builder->new(%$ease,_warnExpired=>$$self{warnExpired}); | |||||||||||||||||||||
| 37 | 18 | ▶ | if($$ease{_err}) { $$self{_err}=1 } | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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
MC/DC0%0/2
$opt{"ts"} //= time
$opt{"ts"}
time
Truth table66%2/3
A //= B
A= $opt{"ts"}B= time
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 80 | 8008 | $scheduled=$ease->schedule(message=>$message,%data); | |||||||||||||||||||||
| 81 | 8008 | ▶ | if(defined($scheduled)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 82 | 8000 | my $intsched=int($scheduled); | |||||||||||||||||||||
| 83 | 8000 | ▶ | if($scheduled>$intsched) { $scheduled=1+$intsched } | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||