line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package X10::SchedEvent; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
846
|
use Time::ParseDate; |
|
1
|
|
|
|
|
12869
|
|
|
1
|
|
|
|
|
66
|
|
4
|
1
|
|
|
1
|
|
12
|
use POSIX; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
2410
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
773
|
use Astro::SunTime; |
|
1
|
|
|
|
|
2518
|
|
|
1
|
|
|
|
|
877
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new |
11
|
|
|
|
|
|
|
{ |
12
|
0
|
|
|
0
|
0
|
|
my $type = shift; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $self = bless { @_ }, $type; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
0
|
|
|
|
unless ($self->{macro} && $self->{macro}->isa('X10::Macro')) |
17
|
|
|
|
|
|
|
{ |
18
|
0
|
|
|
|
|
|
warn "No macro sent to create SchedEvent"; |
19
|
0
|
|
|
|
|
|
return undef; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
$self->{verbose} = 1 if $self->{debug}; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$self->{next_time} = int(time); |
25
|
0
|
|
|
|
|
|
$self->reschedule; |
26
|
0
|
|
|
|
|
|
$self->{last_time} = 0; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub run |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
0
|
|
|
|
$self->{logger}->('info', "Running %s", |
38
|
|
|
|
|
|
|
$self->{description} || 'unnamed event', |
39
|
|
|
|
|
|
|
) if $self->{verbose}; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->{macro}->run; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub reschedule |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
0
|
|
|
|
$self->{last_time} = $self->{next_time} || 0; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
0
|
|
|
|
my $current = $self->{last_time} || time; |
51
|
0
|
|
|
|
|
|
my $next; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
0
|
|
|
|
if (!exists $self->{repeat_type} || $self->{repeat_type} eq 'none') |
|
|
0
|
|
|
|
|
|
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
|
|
|
return 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ($self->{repeat_type} eq 'day') |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
|
my $new = parsedate(sprintf("today %s", $self->time('today'))); |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
0
|
|
|
|
if ($new <= time || $new <= $current) |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
|
|
|
$new = parsedate(sprintf("tomorrow %s", $self->time('tomorrow'))); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# check DOW loop here... |
67
|
0
|
0
|
0
|
|
|
|
if (exists $self->{dowmask} && $self->{dowmask} > 0) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
|
|
|
my @newarray = localtime($new); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
while ( ! ( (1 << $newarray[6]) & $self->{dowmask} ) ) |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
0
|
|
|
|
|
$self->{logger}->('info', "Skipping %s...", strftime("%a %b %e %Y", @newarray)) |
74
|
|
|
|
|
|
|
if $self->{debug}; |
75
|
0
|
|
|
|
|
|
$newarray[3] += 1; # add one day |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
@newarray = localtime(mktime(@newarray)); # normalize |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# find new time on that day... |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $datestr = strftime("%a %b %e %Y", @newarray); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $time = $self->time($datestr); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$new = parsedate(sprintf("%s %s", $time, $datestr), WHOLE => 1); |
86
|
0
|
|
|
|
|
|
@newarray = localtime($new); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$next = $new; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
|
$self->{logger}->('info', "Unsupported repeat type: %s", $self->{repeat_type}); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$self->{next_time} = $next; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub next_time |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $self->{next_time}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub controller |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
if (@_) |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
|
|
|
$self->{macro}->controller(shift); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return $self->{macro}->controller; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub description |
124
|
|
|
|
|
|
|
{ |
125
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if (@_) |
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
|
|
|
$self->{description} = shift; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return $self->{description}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub time |
136
|
|
|
|
|
|
|
{ |
137
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
138
|
0
|
|
|
|
|
|
my $date = shift; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# offsets assumed not to force time across day boundaries... |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $time; |
143
|
|
|
|
|
|
|
my $sign; |
144
|
0
|
|
|
|
|
|
my $offset; |
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
if ($self->{time} =~ /^\d?\d:\d\d$/) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
147
|
|
|
|
|
|
|
{ |
148
|
0
|
|
|
|
|
|
$time = $self->{time}; |
149
|
0
|
|
|
|
|
|
$offset = 0; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
elsif ($self->{time} =~ /^sunrise(\s*([+-])\s*(\d+))?$/) |
152
|
|
|
|
|
|
|
{ |
153
|
0
|
0
|
|
|
|
|
$sign = ($2 eq '-') ? -1 : 1; |
154
|
0
|
|
0
|
|
|
|
$offset = $3 || 0; |
155
|
0
|
|
|
|
|
|
$time = sun_time(type => 'rise', date => $date, |
156
|
|
|
|
|
|
|
latitude => $self->{latitude}, |
157
|
|
|
|
|
|
|
longitude => $self->{longitude}, |
158
|
|
|
|
|
|
|
); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
elsif ($self->{time} =~ /^sunset(\s*([+-])\s*(\d+))?$/) |
161
|
|
|
|
|
|
|
{ |
162
|
0
|
0
|
|
|
|
|
$sign = ($2 eq '-') ? -1 : 1; |
163
|
0
|
|
0
|
|
|
|
$offset = $3 || 0; |
164
|
0
|
|
|
|
|
|
$time = sun_time(type => 'set', date => $date, |
165
|
|
|
|
|
|
|
latitude => $self->{latitude}, |
166
|
|
|
|
|
|
|
longitude => $self->{longitude}, |
167
|
|
|
|
|
|
|
); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
else |
170
|
|
|
|
|
|
|
{ |
171
|
0
|
|
|
|
|
|
$self->{logger}->('info', "Unknown time string: %s", $self->{time}); |
172
|
0
|
|
|
|
|
|
return undef; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
|
return $time unless $offset; |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my ($hour, $minute) = $time =~ /^(\d?\d):(\d\d)$/; |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
$minute += $sign * $offset; |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
while ($minute >= 60) |
182
|
|
|
|
|
|
|
{ |
183
|
0
|
|
|
|
|
|
$minute -= 60; |
184
|
0
|
|
|
|
|
|
$hour++; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
while ($minute < 0) |
188
|
|
|
|
|
|
|
{ |
189
|
0
|
|
|
|
|
|
$minute += 60; |
190
|
0
|
|
|
|
|
|
$hour--; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
return sprintf("%s:%02s", $hour, $minute); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|