| 1 | package Schedule::Week; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | our %EXPORT_TAGS = ( 'days' => [ qw( | |||||||||||||||||||||||||||
| 15 | $MONDAY $TUESDAY $WEDNESDAY $THURSDAY $FRIDAY $SATURDAY $SUNDAY | ||||||||||||||||||||||||||||
| 16 | ) ] ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'days'} } ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | our $VERSION = '1.0'; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | our Readonly::Scalar $SUNDAY = 0; | |||||||||||||||||||||||||||
| 23 | 1 | our Readonly::Scalar $MONDAY = 1; | |||||||||||||||||||||||||||
| 24 | 1 | our Readonly::Scalar $TUESDAY = 2; | |||||||||||||||||||||||||||
| 25 | 1 | our Readonly::Scalar $WEDNESDAY = 3; | |||||||||||||||||||||||||||
| 26 | 1 | our Readonly::Scalar $THURSDAY = 4; | |||||||||||||||||||||||||||
| 27 | 1 | our Readonly::Scalar $FRIDAY = 5; | |||||||||||||||||||||||||||
| 28 | 1 | our Readonly::Scalar $SATURDAY = 6; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 8 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 8 | my $class = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 8 | my $self = { | |||||||||||||||||||||||||||
| 35 | 'ts' => _initialize_schedule() | ||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 8 | return bless $self, $class; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # Day convenience accessors | ||||||||||||||||||||||||||||
| 42 | 20 | ▶ | sub sunday { | ||||||||||||||||||||||||||
|
Subroutine
sunday: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 20 | my ($self, $hours_array_ref, $state) = @_; | |||||||||||||||||||||||||||
| 44 | 20 | $self->hours_for_day($SUNDAY, $hours_array_ref, $state); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 15 | ▶ | sub monday { | ||||||||||||||||||||||||||
|
Subroutine
monday: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 15 | my ($self, $hours_array_ref, $state) = @_; | |||||||||||||||||||||||||||
| 49 | 15 | $self->hours_for_day($MONDAY, $hours_array_ref, $state); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 15 | ▶ | sub tuesday { | ||||||||||||||||||||||||||
|
Subroutine
tuesday: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 15 | my ($self, $hours_array_ref, $state) = @_; | |||||||||||||||||||||||||||
| 54 | 15 | $self->hours_for_day($TUESDAY, $hours_array_ref, $state); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 15 | ▶ | sub wednesday { | ||||||||||||||||||||||||||
|
Subroutine
wednesday: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 15 | my ($self, $hours_array_ref, $state) = @_; | |||||||||||||||||||||||||||
| 59 | 15 | $self->hours_for_day($WEDNESDAY, $hours_array_ref, $state); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 15 | ▶ | sub thursday { | ||||||||||||||||||||||||||
|
Subroutine
thursday: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 15 | my ($self, $hours_array_ref, $state) = @_; | |||||||||||||||||||||||||||
| 64 | 15 | $self->hours_for_day($THURSDAY, $hours_array_ref, $state); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 15 | ▶ | sub friday { | ||||||||||||||||||||||||||
|
Subroutine
friday: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 15 | my ($self, $hours_array_ref, $state) = @_; | |||||||||||||||||||||||||||
| 69 | 15 | $self->hours_for_day($FRIDAY, $hours_array_ref, $state); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 20 | ▶ | sub saturday { | ||||||||||||||||||||||||||
|
Subroutine
saturday: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 20 | my ($self, $hours_array_ref, $state) = @_; | |||||||||||||||||||||||||||
| 74 | 20 | $self->hours_for_day($SATURDAY, $hours_array_ref, $state); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # set or get hours across all days | ||||||||||||||||||||||||||||
| 78 | 80 | ▶ | sub hours { | ||||||||||||||||||||||||||
|
Subroutine
hours: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 80 | my ($self, $hours_array_ref, $state) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 80 | my @hour_states; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 80 | ▶ | if (! defined $hours_array_ref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 1 | croak 'Missing reference to array of hours to get/set!'; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 79 | ▶ | if (ref($hours_array_ref) ne 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 1 | croak "$hours_array_ref is not a reference to an array!"; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 78 | ▶ | if (defined $state) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 27 | ▶ | $state = ($state == 0) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 27 | for my $day ($SUNDAY ... $SATURDAY) { | |||||||||||||||||||||||||||
| 95 | 189 | $hour_states[$day] = []; | |||||||||||||||||||||||||||
| 96 | 189 | for my $hour (@{$hours_array_ref}) { | |||||||||||||||||||||||||||
| 97 | 364 | $self->{'ts'}->[$day]->[$hour] = $state; | |||||||||||||||||||||||||||
| 98 | 364 | push(@{$hour_states[$day]}, $state); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 78 | ▶ | if (scalar(@hour_states) == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 51 | for my $day ($SUNDAY ... $SATURDAY) { | |||||||||||||||||||||||||||
| 106 | 357 | $hour_states[$day] = []; | |||||||||||||||||||||||||||
| 107 | 357 | for my $hour (@{$hours_array_ref}) { | |||||||||||||||||||||||||||
| 108 | 385 | push(@{$hour_states[$day]}, | |||||||||||||||||||||||||||
| 109 | 385 | $self->{'ts'}->[$day]->[$hour]); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 78 | return @hour_states; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # Reset all bits in arrays to 0 | ||||||||||||||||||||||||||||
| 118 | 3 | ▶ | sub reset { | ||||||||||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 120 | 3 | $self->{'ts'} = _initialize_schedule(); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Does this day have any hours scheduled? | ||||||||||||||||||||||||||||
| 124 | 35 | ▶ | sub has_hours { | ||||||||||||||||||||||||||
|
Subroutine
has_hours: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 35 | my ($self, $day) = @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 35 | ▶ | if (($day < $SUNDAY) || ($day > $SATURDAY)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$day < $Schedule::Week::SUNDAY or $day > $Schedule::Week::SATURDAY
MC/DC0%0/2
$day < $Schedule::Week::SUNDAY or $day > $Schedule::Week::SATURDAY
$day < $Schedule::Week::SUNDAY
$day > $Schedule::Week::SATURDAY
Truth table33%1/3
A or B
A= $day < $Schedule::Week::SUNDAYB= $day > $Schedule::Week::SATURDAY
| |||||||||||||||||||||||||||||
| 129 | 0 | croak "Day number $day is invalid"; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 35 | return grep(/1/, @{$self->{'ts'}->[$day]}); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 235 | ▶ | sub hours_for_day { | ||||||||||||||||||||||||||
|
Subroutine
hours_for_day: called CC=11 SCAR=24.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 235 | my ($self, $day, $hours_ref, $state) = @_; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 235 | ▶ | if (($day < $SUNDAY) || ($day > $SATURDAY)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$day < $Schedule::Week::SUNDAY or $day > $Schedule::Week::SATURDAY
MC/DC0%0/2
$day < $Schedule::Week::SUNDAY or $day > $Schedule::Week::SATURDAY
$day < $Schedule::Week::SUNDAY
$day > $Schedule::Week::SATURDAY
Truth table33%1/3
A or B
A= $day < $Schedule::Week::SUNDAYB= $day > $Schedule::Week::SATURDAY
| |||||||||||||||||||||||||||||
| 139 | 0 | croak "Day number $day is invalid"; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 235 | ▶ | if ((defined $hours_ref) && (ref($hours_ref) ne 'ARRAY')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $hours_ref and ref $hours_ref ne "ARRAY"
MC/DC0%0/2
defined $hours_ref and ref $hours_ref ne "ARRAY"
defined $hours_ref
ref $hours_ref ne "ARRAY"
Truth table66%2/3
A and B
A= defined $hours_refB= ref $hours_ref ne "ARRAY"
| |||||||||||||||||||||||||||||
| 143 | 0 | croak "$hours_ref is not a reference to an array!"; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 235 | my @hour_states = (); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # Want all hour states for the day | ||||||||||||||||||||||||||||
| 149 | 235 | ▶ | if (! defined $hours_ref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 14 | return @{$self->{'ts'}->[$day]}; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 221 | ▶ | if (defined($state)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 31 | ▶ | $state = ($state == 0) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 31 | for my $h (@{$hours_ref}) { | |||||||||||||||||||||||||||
| 156 | 109 | $self->{'ts'}->[$day]->[$h] = $state; | |||||||||||||||||||||||||||
| 157 | 109 | push(@hour_states, $self->{'ts'}->[$day]->[$h]); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 221 | ▶ | if (scalar(@hour_states) == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 190 | for my $h (@{$hours_ref}) { | |||||||||||||||||||||||||||
| 163 | 352 | push(@hour_states, $self->{'ts'}->[$day]->[$h]); | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 221 | return @hour_states; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # Return 1 or 0 to indicate if the passed in time falls in the | ||||||||||||||||||||||||||||
| 171 | # active periods of this schedule. If no time stamp is passed | ||||||||||||||||||||||||||||
| 172 | # in, defaults to now. | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 4 | ▶ | sub is_active { | ||||||||||||||||||||||||||
|
Subroutine
is_active: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 4 | my ($self, $ts) = @_; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # Default to now | ||||||||||||||||||||||||||||
| 179 | 4 | ▶ | $ts = time() if not defined $ts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 4 | my ($hr, $day) = (localtime())[2, 6]; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 4 | ▶ | return ($self->{'ts'}->[$day]->[$hr] == 1) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # Serialize a schedule into a string of 168 1s and 0s | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 4 | ▶ | sub serialize { | ||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 188 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 4 | my $serialized = ""; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 4 | for my $day ($SUNDAY ... $SATURDAY) { | |||||||||||||||||||||||||||
| 193 | 28 | $serialized .= join('', @{$self->{'ts'}->[$day]}); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 4 | return $serialized; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | # Return an instantiated schedule made from the passed in | ||||||||||||||||||||||||||||
| 200 | # serialized string | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 5 | ▶ | sub deserialize { | ||||||||||||||||||||||||||
|
Subroutine
deserialize: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 203 | 5 | my $serialized = shift; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 5 | ▶ | if (! defined $serialized) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 1 | croak "Must pass in a serialized schedule!"; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 4 | ▶ | if (length($serialized) != 168) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 1 | croak "Passed in serialized schedule is not 168 hours (chars) long!"; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 3 | ▶ | if ($serialized =~ m/[^01]+/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 1 | croak "Passed in serialized schedule must be all 1s and 0s"; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 2 | my $offset = 0; | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 2 | my $hours_in_day = 24; | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 2 | my $schedule = Schedule::Week->new(); | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # Localize for map() in loop below | ||||||||||||||||||||||||||||
| 224 | 2 | local $_; | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 2 | for my $day ($SUNDAY ... $SATURDAY) { | |||||||||||||||||||||||||||
| 227 | 14 | my $day_template = substr($serialized, $offset, $hours_in_day); | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # Explicitly convert to integers to keep perl from guessing that | ||||||||||||||||||||||||||||
| 230 | # values are 1 character strings | ||||||||||||||||||||||||||||
| 231 | 14 | my @hours = map { int($_); } (split('', $day_template)); | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 14 | $schedule->{'ts'}->[$day] = \@hours; | |||||||||||||||||||||||||||
| 234 | 14 | $offset += $hours_in_day; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 2 | return $schedule; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | # Set hours on or off for all weekdays in one shot or retrieve values | ||||||||||||||||||||||||||||
| 241 | # for same. | ||||||||||||||||||||||||||||
| 242 | 0 | ▶ | sub weekday_hours { | ||||||||||||||||||||||||||
|
Subroutine
weekday_hours: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 243 | 0 | my ($self, $hours_ref, $state) = @_; | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | my @results; | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | for my $day ($MONDAY ... $FRIDAY) { | |||||||||||||||||||||||||||
| 248 | 0 | push(@results, [$self->hours_for_day($day, $hours_ref, $state)]); | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | return @results; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | # Set hours on or off for all weekends in one shot or retrieve values for | ||||||||||||||||||||||||||||
| 255 | # same. | ||||||||||||||||||||||||||||
| 256 | 1 | ▶ | sub weekend_hours { | ||||||||||||||||||||||||||
|
Subroutine
weekend_hours: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 257 | 1 | my ($self, $hours_ref, $state) = @_; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 1 | my @results; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 1 | for my $day ($SATURDAY, $SUNDAY) { | |||||||||||||||||||||||||||
| 262 | 2 | push(@results, [$self->hours_for_day($day, $hours_ref, $state)]); | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 1 | return @results; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | ### Private methods | ||||||||||||||||||||||||||||
| 269 | 11 | ▶ | sub _initialize_schedule { | ||||||||||||||||||||||||||
|
Subroutine
_initialize_schedule: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 11 | my @schedule = (); | |||||||||||||||||||||||||||
| 272 | 11 | $schedule[$SUNDAY] = _initialize_hours(0); | |||||||||||||||||||||||||||
| 273 | 11 | $schedule[$MONDAY] = _initialize_hours(0); | |||||||||||||||||||||||||||
| 274 | 11 | $schedule[$TUESDAY] = _initialize_hours(0); | |||||||||||||||||||||||||||
| 275 | 11 | $schedule[$WEDNESDAY] = _initialize_hours(0); | |||||||||||||||||||||||||||
| 276 | 11 | $schedule[$THURSDAY] = _initialize_hours(0); | |||||||||||||||||||||||||||
| 277 | 11 | $schedule[$FRIDAY] = _initialize_hours(0); | |||||||||||||||||||||||||||
| 278 | 11 | $schedule[$SATURDAY] = _initialize_hours(0); | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 11 | return \@schedule; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 77 | ▶ | sub _initialize_hours { | ||||||||||||||||||||||||||
|
Subroutine
_initialize_hours: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 77 | my $v = shift; | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | return [ | ||||||||||||||||||||||||||||
| 288 | # Hours of day, starting with 12 AM (hour 00 aka midnight) | ||||||||||||||||||||||||||||
| 289 | 77 | $v, $v, $v, $v, $v, $v, $v, $v, | |||||||||||||||||||||||||||
| 290 | $v, $v, $v, $v, $v, $v, $v, $v, | ||||||||||||||||||||||||||||
| 291 | $v, $v, $v, $v, $v, $v, $v, $v, | ||||||||||||||||||||||||||||
| 292 | ]; | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 1 | 1; | |||||||||||||||||||||||||||