OpeningHours/Calendar.pm

filter: Statementstmt 94.3% 50 / 53 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 9 totaltotal 82.7% 72 / 87 CC 7 SCAR 7.1
CC
7
Cov
91%
first_open_hour
4.4
is_open_on_week_day
2.0
next_open
2.0
CRAP 2.0
↑ Summary OpeningHours/Hours.pm »
1 package Data::OpeningHours::Calendar;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Data::OpeningHours::Hours;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 2 my ($class) = @_;
10 2 my $self = {};
11 2 $self->{parser} = DateTime::Format::Strptime->new(
12 pattern => '%a',
13 locale => 'en_US',
14 on_error => 'croak',
15 );
16 2 return bless $self, $class;
17 }
18  
19 14 ▶sub set_week_day {
Subroutine set_week_day: called CC=1 SCAR=0.0
Pod undocumented
20 14 my ($self, $day, $hours) = @_;
21 14 $self->{week}[$day] = Data::OpeningHours::Hours->new($hours);
22 14 return;
23 }
24  
25 6 ▶sub set_special_day {
Subroutine set_special_day: called CC=1 SCAR=0.0
Pod undocumented
26 6 my ($self, $date, $hours) = @_;
27 6 $self->{days}{$date} = Data::OpeningHours::Hours->new($hours);
28 6 return;
29 }
30 9 ▶sub is_special_day {
Subroutine is_special_day: called CC=1 SCAR=0.0
Pod undocumented
31 9 my ($self, $date) = @_;
32 9 return exists $self->{days}{$date};
33 }
34  
35 10 ▶sub is_open_on_week_day {
Subroutine is_open_on_week_day: called CC=2 SCAR=7.1
Pod undocumented
36 10 my ($self, $day_of_week, $hour) = @_;
37 10 ▶ return unless exists $self->{week}[$day_of_week];
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"week"}[$day_of_week] 0 10 10
38 10 return $self->{week}[$day_of_week]->is_open_between($hour);
39 }
40  
41 5 ▶sub is_open_on_special_day {
Subroutine is_open_on_special_day: called CC=1 SCAR=0.0
Pod undocumented
42 5 my ($self, $date, $hour) = @_;
43 5 return $self->{days}{$date}->is_open_between($hour);
44 }
45  
46 4 ▶sub is_open {
Subroutine is_open: called CC=2 SCAR=6.9
Pod undocumented
47 4 my ($self, $date) = @_;
48 4 ▶ if ($self->is_special_day($date->ymd('-'))){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_special_day($date->ymd("-"))) 2 2 4
49 2 return $self->is_open_on_special_day(
50 $date->ymd('-'),
51 sprintf('%02d:%02d', $date->hour, $date->minute));
52 }
53  
54 2 return $self->is_open_on_week_day(
55 $date->wday,
56 sprintf('%02d:%02d', $date->hour, $date->minute));
57 }
58  
59 5 ▶sub first_open_hour {
Subroutine first_open_hour: called CC=4 SCAR=14.8
Pod undocumented
60 5 my ($self, $date) = @_;
61 5 ▶ if ($self->is_special_day($date->ymd('-'))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_special_day($date->ymd("-"))) 1 4 5
62 1 my $hours = $self->{days}{$date->ymd('-')};
63 1 ▶ return $hours->first_hour() if $hours;
Branch: 1 branch
BranchTrueFalseTotal
if $hours 1 0 1
64 0 return;
65 }
66 4 my $hours = $self->{week}[$date->wday];
67 4 ▶ return $hours->first_hour() if $hours;
Branch: 1 branch
BranchTrueFalseTotal
if $hours 4 0 4
68 0 return;
69 }
70  
71 3 ▶sub next_open {
Subroutine next_open: called CC=2 SCAR=6.9
Pod undocumented
72 3 my ($self, $date) = @_;
73 3 my $open = $date->clone;
74 3 while (1) {
75 5 $open->add(days => 1);
76 5 my $hour = $self->first_open_hour($open);
77 5 ▶ if ($hour) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hour) 3 2 5
78 3 my ($h,$m) = split /:/, $hour;
79 3 $open->set_hour($h);
80 3 $open->set_minute($m);
81 3 return $open;
82 }
83 }
84 0 return;
85 }
86  
87 2 1;
88  
↑ Summary OpeningHours/Hours.pm »