| 1 | package Schedule::ByClock; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Time::localtime; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | $VERSION='1.01'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my $class=shift; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my $self=[]; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | bless($self,$class); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | $self->_init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub get_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub get_control_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_control_list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | @$self; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub set_control_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_control_list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | @$self=(); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | foreach ($self->_check_params(@_)) { | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | push(@$self,$_); | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | @$self; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub get_control_on_second { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_control_on_second: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my($tm,$until); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $tm=localtime; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $until=$self->_find_next($tm->sec,$self->_check_params(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $until=$self->_find_next($tm->sec,@$self); | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return undef unless defined($until); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if($until>$tm->sec) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | sleep($until-$tm->sec); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | elsif($until<$tm->sec) { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | sleep($until+60-$tm->sec); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | sleep(60); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $until; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub get_control_on_minute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_control_on_minute: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my($tm,$until,$until_sec); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $tm=localtime; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if(@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $until=$self->_find_next($tm->min,$self->_check_params(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $until=$self->_find_next($tm->min,@$self); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return undef unless defined($until); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # Syncronize on top of a minute. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if($tm->sec) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $until_sec=$self->get_control_on_second(0); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # Which minute? | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $tm=localtime; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # Wait until... | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if($until>$tm->min) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | sleep(($until-$tm->min)*60); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | elsif($until<$tm->min) { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | sleep(($until+60-$tm->min)*60); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # On the minute. | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return $until if(defined($until_sec)); # We have slept for less than a minute. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | sleep(3600); # Wait for a full hour. | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $until; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # 'Internal' subs. Don't call these, since they may, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # and will, change without notice. | ||||||||||||||||||||||||||||||||||||||||||
| 111 | ######################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | foreach ($self->_check_params(@_)) { | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | push(@$self,$_); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub _check_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_params: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my @control; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | foreach (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if(m/\D/||$_<0||$_>59) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
/\D/ or $_ < 0 or $_ > 59
/\D/ or $_ < 0
MC/DC0%0/3
/\D/ or $_ < 0 or $_ > 59
/\D/
$_ < 0
$_ > 59
Truth table0%0/4
A or B or C
A= /\D/B= $_ < 0C= $_ > 59
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | carp("Control value $_ out of bounds") | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | push(@control,$_); | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | @control; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub _find_next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_next: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my ($self,$now,@control)=(@_); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my ($low,$high,$next); | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return undef unless @control; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $low=$high=$control[0]; # Must have an initial value. | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # Find highest and lowest values in list. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | foreach (@control) { | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if($_>$high) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $high=$_; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | elsif($_<$low) { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $low=$_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if($now<$high) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | # Search the closest that is higher than now. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $next=$high; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | foreach (@control) { $next=$_ if($_>$now&&$_<$next); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ > $now and $_ < $next
MC/DC0%0/2
$_ > $now and $_ < $next
$_ > $now
$_ < $next
Truth table0%0/3
A and B
A= $_ > $nowB= $_ < $next
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # Grab low value. | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $next=$low; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $next; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | 'Ymer'; | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | __END__ | ||||||||||||||||||||||||||||||||||||||||||