xs/rule.xs

filter: Statementstmt 96.2% 103 / 107 Branchbran 88.2% 60 / 68 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 93.1% 163 / 175 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/tkr/tkr_zone.h ↑ Summary include/tkr/tkr_rrule.h »
1 # The rule: its three doors, what it says about itself, and the text back.
2  
3 MODULE = Time::Keeper::Recurrence PACKAGE = Time::Keeper::Recurrence
4  
5 SV *
6 new(class, ...)
7 SV *class
8 PREINIT:
9 2398 const char *what = "Time::Keeper::Recurrence->new";
10 tkr_opts o;
11 tkr_rule r;
12 char err[TKR_ERR];
13 STRLEN len;
14 const char *s;
15 CODE:
16 2398 tkr_opts_parse(aTHX_ &ST(1), items - 1, &o, "rsgoC", what);
17 2395 ▶ if (!o.rrule)
Branch: 1 branch
BranchTrueFalseTotal
if (!o.rrule) 1 2394 2395
18 1 croak("%s: rrule => is wanted", what);
19 2394 ▶ if (!o.start)
Branch: 1 branch
BranchTrueFalseTotal
if (!o.start) 1 2393 2394
20 1 croak("%s: start => a Time::Keeper value is wanted: a rule needs a start", what);
21 2393 tkr_rule_init(&r);
22 2393 r.gap = TKR_GAP_FORWARD;
23 2393 r.overlap = TKR_OVERLAP_EARLIER;
24 2393 tkr_start_from_sv(aTHX_ o.start, &r, what);
25 2392 s = SvPV(o.rrule, len);
26 2392 ▶ if (!tkr_rrule_parse(s, len, &r, err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_rrule_parse(s, len, &r, err)) 44 2348 2392
27 44 croak("%s: %s", what, err);
28 2348 ▶ if (o.calendar) {
Branch: 1 branch
BranchTrueFalseTotal
if (o.calendar) { 3 2345 2348
29 3 ▶ if (r.flags & TKR_F_RSCALE)
Branch: 1 branch
BranchTrueFalseTotal
if (r.flags & TKR_F_RSCALE) 1 2 3
30 1 croak("%s: calendar => and RSCALE in the rule both name a calendar: give one", what);
31 2 tkr_calendar_opt(aTHX_ o.calendar, &r, what);
32 }
33 2347 tkr_check_until_form(aTHX_ &r, what);
34 2345 tkr_gap_overlap(aTHX_ &o, &r, what);
35 2343 ▶ if (!tkr_can_fire(aTHX_ &r, 0, err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_can_fire(aTHX_ &r, 0, err)) 1 2342 2343
36 1 croak("%s: %s", what, err);
37 2342 RETVAL = tkr_rule_new_sv(aTHX_ tkr_stash_for(aTHX_ class), &r);
38 OUTPUT:
39 RETVAL
40  
41 SV *
42 cron(self, ...)
43 SV *self
44 PREINIT:
45 509 const char *what = "Time::Keeper::Recurrence->cron";
46 tkr_opts o;
47 tkr_rule r;
48 char err[TKR_ERR];
49 STRLEN len;
50 const char *s;
51 CODE:
52 509 ▶ if (SvROK(self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(self)) { 66 443 509
53 /* a method on a rule: its cron spelling */
54 66 const tkr_rule *me = tkr_rule_of(aTHX_ self, what);
55 66 ▶ if (items != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items != 1) 0 66 66
56 0 croak("%s: a rule's cron takes no arguments", what);
57 66 RETVAL = newSVpvs("");
58 66 ▶ if (!tkr_cron_write(aTHX_ me, RETVAL, err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_cron_write(aTHX_ me, RETVAL, err)) 10 56 66
59 10 croak("%s: %s", what, err);
60 }
61 else {
62 443 ▶ if (items < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 2) 0 443 443
63 0 croak("%s: a cron expression is wanted", what);
64 443 tkr_opts_parse(aTHX_ &ST(2), items - 2, &o, "szgo", what);
65 443 ▶ if (o.start && o.zone)
Branch: 2 branches
BranchTrueFalseTotal
if (o.start && o.zone) 6 437 443
if (o.start && o.zone) 1 5 6
66 1 croak("%s: start => carries the zone: not zone => as well", what);
67 442 tkr_rule_init(&r);
68 442 r.gap = TKR_GAP_SKIP;
69 442 r.overlap = TKR_OVERLAP_BOTH; /* every real minute of a doubled hour, a pinned minute once: Vixie's and Punk::Queue's rule */
70 442 ▶ if (o.start)
Branch: 1 branch
BranchTrueFalseTotal
if (o.start) 5 437 442
71 5 tkr_start_from_sv(aTHX_ o.start, &r, what);
72 437 ▶ else if (o.zone)
Branch: 1 branch
BranchTrueFalseTotal
else if (o.zone) 265 172 437
73 265 tkr_zone_from_sv(aTHX_ o.zone, &r, what);
74 441 s = SvPV(ST(1), len);
75 441 ▶ if (!tkr_cron_parse(s, len, &r, err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_cron_parse(s, len, &r, err)) 20 421 441
76 20 croak("%s: %s", what, err);
77 421 tkr_gap_overlap(aTHX_ &o, &r, what);
78 421 ▶ if (!tkr_can_fire(aTHX_ &r, tkr_now_sec(aTHX), err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_can_fire(aTHX_ &r, tkr_now_sec(aTHX), err)) 3 418 421
79 3 croak("%s: cron '%s' %s", what, s, err);
80 418 RETVAL = tkr_rule_new_sv(aTHX_ tkr_stash_for(aTHX_ self), &r);
81 }
82 OUTPUT:
83 RETVAL
84  
85 SV *
86 every(class, n, unit, ...)
87 SV *class
88 IV n
89 const char *unit
90 PREINIT:
91 35 const char *what = "Time::Keeper::Recurrence->every";
92 tkr_opts o;
93 tkr_rule r;
94 char err[TKR_ERR];
95 CODE:
96 35 tkr_opts_parse(aTHX_ &ST(3), items - 3, &o, "snaucsgoC", what);
97 34 ▶ if (!o.start)
Branch: 1 branch
BranchTrueFalseTotal
if (!o.start) 1 33 34
98 1 croak("%s: start => a Time::Keeper value is wanted: a rule needs a start", what);
99 33 tkr_rule_init(&r);
100 33 r.gap = TKR_GAP_FORWARD;
101 33 r.overlap = TKR_OVERLAP_EARLIER;
102 33 tkr_start_from_sv(aTHX_ o.start, &r, what);
103 33 tkr_every_build(aTHX_ n, unit, &o, &r, what);
104 22 ▶ if (o.calendar)
Branch: 1 branch
BranchTrueFalseTotal
if (o.calendar) 3 19 22
105 3 tkr_calendar_opt(aTHX_ o.calendar, &r, what);
106 21 tkr_check_until_form(aTHX_ &r, what);
107 20 tkr_gap_overlap(aTHX_ &o, &r, what);
108 20 ▶ if (!tkr_can_fire(aTHX_ &r, 0, err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_can_fire(aTHX_ &r, 0, err)) 0 20 20
109 0 croak("%s: %s", what, err);
110 20 RETVAL = tkr_rule_new_sv(aTHX_ tkr_stash_for(aTHX_ class), &r);
111 OUTPUT:
112 RETVAL
113  
114 IV
115 check(class, expr, ...)
116 SV *class
117 SV *expr
118 PREINIT:
119 23 ▶ const char *what = "Time::Keeper::Recurrence->check";
Branch: 1 branch
BranchTrueFalseTotal
const char *what = "Time::Keeper::Recurrence->check"; 23 0 23
120 tkr_rule r;
121 char err[TKR_ERR];
122 STRLEN len;
123 const char *s;
124 CODE:
125 PERL_UNUSED_VAR(class);
126 23 tkr_rule_init(&r);
127 23 s = SvPV(expr, len);
128 23 ▶ if (items > 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) 1 22 23
129 1 tkr_zone_from_sv(aTHX_ ST(2), &r, what);
130 23 ▶ if (!tkr_cron_parse(s, len, &r, err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_cron_parse(s, len, &r, err)) 20 3 23
131 20 croak("%s: %s", what, err);
132 3 ▶ if (!tkr_can_fire(aTHX_ &r, tkr_now_sec(aTHX), err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_can_fire(aTHX_ &r, tkr_now_sec(aTHX), err)) 1 2 3
133 1 croak("%s: cron '%s' %s", what, s, err);
134 2 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 2 2
135 OUTPUT:
136 RETVAL
137  
138 SV *
139 rrule(self)
140 SV *self
141 PREINIT:
142 const tkr_rule *r;
143 CODE:
144 906 r = tkr_rule_of(aTHX_ self, "Time::Keeper::Recurrence->rrule");
145 906 ▶ if (r->flags & TKR_F_EVERY)
Branch: 1 branch
BranchTrueFalseTotal
if (r->flags & TKR_F_EVERY) 1 905 906
146 1 croak("Time::Keeper::Recurrence->rrule: an @every cron is an interval from the last occurrence, which no RRULE says");
147 905 RETVAL = newSVpvs("");
148 905 tkr_rrule_write(aTHX_ r, RETVAL);
149 OUTPUT:
150 RETVAL
151  
152 SV *
153 describe(self)
154 SV *self
155 PREINIT:
156 const tkr_rule *r;
157 CODE:
158 98 r = tkr_rule_of(aTHX_ self, "Time::Keeper::Recurrence->describe");
159 98 RETVAL = newSVpvs("");
160 98 tkr_describe(aTHX_ r, RETVAL);
161 OUTPUT:
162 RETVAL
163  
164 SV *
165 freq(self)
166 SV *self
167 ALIAS:
168 interval = 1
169 count = 2
170 until = 3
171 start = 4
172 zone = 5
173 gap = 6
174 overlap = 7
175 is_finite = 8
176 wkst = 9
177 calendar = 10
178 skip = 11
179 PREINIT:
180 static const char *const whats[] = {
181 "Time::Keeper::Recurrence->freq", "Time::Keeper::Recurrence->interval", "Time::Keeper::Recurrence->count",
182 "Time::Keeper::Recurrence->until", "Time::Keeper::Recurrence->start", "Time::Keeper::Recurrence->zone",
183 "Time::Keeper::Recurrence->gap", "Time::Keeper::Recurrence->overlap", "Time::Keeper::Recurrence->is_finite",
184 "Time::Keeper::Recurrence->wkst", "Time::Keeper::Recurrence->calendar", "Time::Keeper::Recurrence->skip"
185 };
186 const tkr_rule *r;
187 CODE:
188 179 r = tkr_rule_of(aTHX_ self, whats[ix]);
189 178 switch (ix) {
190 3 ▶ case 0: RETVAL = (r->flags & TKR_F_EVERY) ? newSVpvs("every") : newSVpv(tkr_freq_lower[r->freq], 0); break;
Branch: 1 branch
BranchTrueFalseTotal
case 0: RETVAL = (r->flags & TKR_F_EVERY) ? newSVpvs("every") : newSVpv(tkr_freq_lower[r->freq], 0); break; 1 2 3
191 2 case 1: RETVAL = newSViv((IV)r->interval); break;
192 2 ▶ case 2: RETVAL = r->count ? newSViv((IV)r->count) : &PL_sv_undef; break;
Branch: 1 branch
BranchTrueFalseTotal
case 2: RETVAL = r->count ? newSViv((IV)r->count) : &PL_sv_undef; break; 1 1 2
193 6 case 3: RETVAL = tkr_until_sv(aTHX_ r, whats[ix]); break;
194 47 case 4:
195 47 ▶ if (!(r->flags & TKR_F_HAS_START)) { RETVAL = &PL_sv_undef; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (!(r->flags & TKR_F_HAS_START)) { RETVAL = &PL_sv_undef; break; } 2 45 47
196 45 RETVAL = tkr_occurrence_sv(aTHX_ r, r->start.sec, whats[ix]);
197 45 ▶ if (!RETVAL) croak("%s: the start is outside the years Time::Keeper holds", whats[ix]);
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("%s: the start is outside the years Time::Keeper holds", whats[ix]); 0 45 45
198 45 break;
199 68 case 5: RETVAL = tkr_zone_name_sv(aTHX_ r); break;
200 21 case 6: RETVAL = newSVpv(tkr_gap_names[r->gap], 0); break;
201 18 case 7: RETVAL = newSVpv(tkr_overlap_names[r->overlap], 0); break;
202 4 ▶ case 8: RETVAL = tkr_is_finite(r) ? &PL_sv_yes : &PL_sv_no; break;
Branch: 1 branch
BranchTrueFalseTotal
case 8: RETVAL = tkr_is_finite(r) ? &PL_sv_yes : &PL_sv_no; break; 1 3 4
203 1 case 9: RETVAL = newSViv(r->wkst + 1); break;
204 4 case 10: {
205 4 const char *id = NULL;
206 4 ▶ if (!(r->flags & TKR_F_RSCALE)) { RETVAL = &PL_sv_undef; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (!(r->flags & TKR_F_RSCALE)) { RETVAL = &PL_sv_undef; break; } 1 3 4
207 3 ▶ if ((tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id)
Branch: 2 branches
BranchTrueFalseTotal
if ((tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id) 3 0 3
if ((tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id) 0 3 3
208 0 croak("%s: a calendar this build does not know", whats[ix]);
209 3 RETVAL = newSVpv(id, 0);
210 3 break;
211 }
212 2 ▶ default: RETVAL = (r->flags & TKR_F_RSCALE) ? newSVpv(tkr_skip_names[r->skip], 0) : &PL_sv_undef; break;
Branch: 1 branch
BranchTrueFalseTotal
default: RETVAL = (r->flags & TKR_F_RSCALE) ? newSVpv(tkr_skip_names[r->skip], 0) : &PL_sv_undef; break; 1 1 2
213 }
214 OUTPUT:
215 RETVAL
« include/tkr/tkr_zone.h ↑ Summary include/tkr/tkr_rrule.h »