Natural.pm

filter: Statementstmt 95.3% 407 / 427 Branchbran 86.6% 130 / 150 Conditioncond 82.0% 114 / 139 MC/DCmcdc 60.0% 39 / 65 Subroutinesub 100% 68 / 68 Podpod 100% 7 / 7 totaltotal 89.3% 765 / 856 CC 140 SCAR 27.2
CC
140
Cov
91%
_advance_future
36.1
parse_datetime
29.0
_process
27.1
CRAP 15.1
« Natural/Extract.pm ↑ Summary Natural/Expand.pm »
1 package DateTime::Format::Natural;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use base qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
6 DateTime::Format::Natural::Calc
7 DateTime::Format::Natural::Calendar
8 DateTime::Format::Natural::Duration
9 DateTime::Format::Natural::Expand
10 DateTime::Format::Natural::Extract
11 DateTime::Format::Natural::Formatted
12 DateTime::Format::Natural::Helpers
13 DateTime::Format::Natural::Rewrite
14 27 );
15 27 ▶use boolean qw(true false);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 27 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 27 ▶use DateTime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 27 ▶use DateTime::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 27 ▶use DateTime::TimeZone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 27 ▶use List::Util 1.33 qw(all any none);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 27 ▶use Params::Validate ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 27 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 27 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 27 ▶use DateTime::Format::Natural::Utils qw(trim);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 27 our $VERSION = '1.27';
29  
30 validation_options(
31 on_fail => sub
32 1 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
33 1 my ($error) = @_;
34 1 chomp $error;
35 1 croak $error;
36 },
37 27 stack_skip => 2,
38 );
39  
40 sub new
41 10887 ▶{
Subroutine new: called CC=2 SCAR=7.2
Pod documented
42 10887 my $class = shift;
43  
44 10887 ▶ my $self = bless {}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0108870
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
45  
46 10887 $self->_init_check(@_);
47 10886 $self->_init(@_);
48  
49 10886 return $self;
50 }
51  
52 sub _init
53 10886 ▶{
Subroutine _init: called CC=6 SCAR=17.9
54 10886 my $self = shift;
55 10886 my %opts = @_;
56  
57 10886 my %presets = (
58 lang => 'en',
59 format => 'd/m/y',
60 demand_future => false,
61 prefer_future => false,
62 time_zone => 'floating',
63 calendar_class => undef,
64 );
65 10886 foreach my $opt (keys %presets) {
66 65316 $self->{ucfirst $opt} = $presets{$opt};
67 }
68 10886 foreach my $opt (keys %opts) {
69 7078 ▶ if (defined $opts{$opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{$opt}) 7041 37 7078
70 7041 $self->{ucfirst $opt} = $opts{$opt};
71 }
72 }
73 10886 ▶ $self->{Daytime} = $opts{daytime} || {};
Condition100%2/2
$opts{'daytime'} || {}
l!l
3910847
MC/DC100%1/1
$opts{'daytime'} || {}
$opts{'daytime'}
Truth table100%2/2
A
A= $opts{'daytime'}
Aresult
11
00
74  
75 10886 my $mod = join '::', (__PACKAGE__, 'Lang', uc $self->{Lang});
76 10886 ▶ eval "require $mod; 1" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $mod; 1" or die $@ 10886 0 10886
77  
78 10886 $self->{data} = $mod->__new();
79 10886 $self->{grammar_class} = $mod;
80  
81 10886 $self->{mode} = '';
82 }
83  
84 sub _init_check
85 10887 ▶{
Subroutine _init_check: called CC=1 SCAR=0.2
86 10887 my $self = shift;
87  
88 validate(@_, {
89 calendar_class => {
90 type => SCALAR | UNDEF,
91 optional => true,
92 callbacks => {
93 'calendar class exists' => sub
94 74 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
95 74 my $class = shift;
96 74 ▶ return true unless defined $class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class 37 37 74
97 37 ▶ return $class eq 'DateTime::Calendar::Julian' && eval "require $class; 1";
Condition33%1/3
$class eq 'DateTime::Calendar::Julian' && eval "require $class; 1"
!ll&&!rl&&r
0037
MC/DC0%0/2
$class eq 'DateTime::Calendar::Julian' && eval "require $class; 1"
$class eq 'DateTime::Calendar::Julian' eval "require $class; 1"
Truth table33%1/3
A && B
A= $class eq 'DateTime::Calendar::Julian'B= eval "require $class; 1"
ABresult
0X0
100
111
98 },
99 },
100 },
101 demand_future => {
102 # SCALARREF due to boolean.pm's implementation
103 type => BOOLEAN | SCALARREF,
104 optional => true,
105 callbacks => {
106 'mutually exclusive' => sub
107 1072 ▶ {
Subroutine __ANON__: called CC=2 SCAR=9.2
108 1072 ▶ return true unless exists $_[1]->{prefer_future};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[1]{"prefer_future"} 1072 0 1072
109 0 die "prefer_future provided\n";
110 },
111 },
112 },
113 lang => {
114 type => SCALAR,
115 optional => true,
116 regex => qr!^(?:en)$!i,
117 },
118 format => {
119 type => SCALAR,
120 optional => true,
121 regex => qr!^(?:
122 (?: (?: [dmy]{1,4}[-./] ){2}[dmy]{1,4} )
123 |
124 (?: [dm]{1,2}/[dm]{1,2} )
125 )$!ix,
126 },
127 prefer_future => {
128 # SCALARREF due to boolean.pm's implementation
129 type => BOOLEAN | SCALARREF,
130 optional => true,
131 callbacks => {
132 'mutually exclusive' => sub
133 1091 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
134 1091 ▶ return true unless exists $_[1]->{demand_future};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[1]{"demand_future"} 1090 1 1091
135 1 die "demand_future provided\n";
136 },
137 },
138 },
139 time_zone => {
140 type => SCALAR | OBJECT,
141 optional => true,
142 callbacks => {
143 'valid timezone' => sub
144 1562 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
145 1562 my $val = shift;
146 1562 ▶ if (blessed($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($val)) { } 1 1561 1562
147 1 return $val->isa('DateTime::TimeZone');
148 }
149 else {
150 1561 eval { DateTime::TimeZone->new(name => $val) };
151 1561 return !$@;
152 }
153 }
154 },
155 },
156 daytime => {
157 type => HASHREF,
158 optional => true,
159 callbacks => {
160 'valid daytime' => sub
161 39 ▶ {
Subroutine __ANON__: called CC=5 SCAR=18.7
162 39 my $href = shift;
163 39 my %daytimes = map { $_ => true } qw(morning afternoon evening);
164 39 ▶ if (any { !$daytimes{$_} } keys %$href) {
Subroutine __ANON__: called CC=1 SCAR=0.6
Branch: 4 branches
BranchTrueFalseTotal
if (&any(sub { not $daytimes{$_}; } , keys %$href)) { } 0 39 39
elsif (&any(sub { not defined $href->{$_}; } , keys %$href)) { } 0 39 39
elsif (&any(sub { not $href->{$_} =~ /^\d{1,2}$/; } , keys %$href)) { } 0 39 39
elsif (&any(sub { $href->{$_} < 0 or $href->{$_} > 23; } , keys %$href)) { } 0 39 39
165 0 die "spelling of daytime\n";
166 }
167 58 ▶ elsif (any { !defined $href->{$_} } keys %$href) {
Subroutine __ANON__: called CC=1 SCAR=0.0
168 0 die "undefined hour\n";
169 }
170 58 ▶ elsif (any { $href->{$_} !~ /^\d{1,2}$/ } keys %$href) {
Subroutine __ANON__: called CC=1 SCAR=0.0
171 0 die "not a valid number\n";
172 }
173 58 ▶ elsif (any { $href->{$_} < 0 || $href->{$_} > 23 } keys %$href) {
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$href->{$_} < 0 or $href->{$_} > 23 0 58 58
174 0 die "hour out of range\n";
175 }
176 else {
177 39 return true;
178 }
179 }
180 },
181 },
182 datetime => {
183 type => OBJECT,
184 optional => true,
185 callbacks => {
186 'valid object' => sub
187 26 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.2
188 26 my $obj = shift;
189 26 ▶ blessed($obj) && $obj->isa('DateTime');
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($obj) and $obj->isa("DateTime") 26 0 26
190 }
191 },
192 },
193 10887 });
194 }
195  
196 sub _init_vars
197 12007 ▶{
Subroutine _init_vars: called CC=1 SCAR=0.0
198 12007 my $self = shift;
199  
200 12007 delete @$self{qw(keyword modified postprocess)};
201 }
202  
203 sub parse_datetime
204 12007 ▶{
Subroutine parse_datetime: called CC=27 SCAR=33.7
Pod documented
205 12007 my $self = shift;
206  
207 12007 $self->_parse_init(@_);
208  
209 12007 $self->{input_string} = $self->{date_string};
210  
211 12007 $self->{mode} = 'parse';
212  
213 12007 my $date_string = $self->{date_string};
214  
215 12007 $self->_rewrite(\$date_string);
216  
217 12007 my ($formatted) = $date_string =~ $self->{data}->__regexes('format');
218 12007 my %count = $self->_count_separators($formatted);
219  
220 12007 $self->{tokens} = [];
221 12007 $self->{traces} = [];
222  
223 12007 ▶ if ($self->_check_formatted('ymd', \%count)) {
Branch: 5 branches
BranchTrueFalseTotal
if ($self->_check_formatted('ymd', \%count)) { } 271 11736 12007
elsif ($self->_check_formatted('md', \%count)) { } 193 11543 11736
elsif ($date_string =~ /^(\d{4}(?:-\d{2}){0,2})T(\d{2}(?::\d{2}){0,2})(?:[.,](\d+))?(Z|[+-]\d{2}(?::?\d{2})?)?$/) { } 29 11514 11543
elsif ($date_string =~ /^([+-]) (\d+?) ([a-zA-Z]+)$/x) { } 14 11500 11514
elsif ($date_string =~ /^\d{14}$/) { } 6 11494 11500
224 271 my $dt = $self->_parse_formatted_ymd($date_string, \%count);
225 271 ▶ return $dt if blessed($dt);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($dt) 1 270 271
226 }
227 elsif ($self->_check_formatted('md', \%count)) {
228 193 my $dt = $self->_parse_formatted_md($date_string);
229 193 ▶ return $dt if blessed($dt);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($dt) 1 192 193
230  
231 192 ▶ if ($self->{Prefer_future} || $self->{Demand_future}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Prefer_future"} or $self->{"Demand_future"}) 36 156 192
Condition100%3/3
$self->{"Prefer_future"} or $self->{"Demand_future"}
l!l&&r!l&&!r
1818156
MC/DC100%2/2
$self->{"Prefer_future"} or $self->{"Demand_future"}
$self->{"Prefer_future"} $self->{"Demand_future"}
Truth table100%3/3
A or B
A= $self->{"Prefer_future"}B= $self->{"Demand_future"}
ABresult
1X1
011
000
232 36 $self->_advance_future('md');
233 }
234 }
235 elsif ($date_string =~ /^(\d{4}(?:-\d{2}){0,2})T(\d{2}(?::\d{2}){0,2})(?:[.,](\d+))?(Z|[+-]\d{2}(?::?\d{2})?)?$/) {
236 29 my ($date, $time, $fractional, $tz) = ($1, $2, $3, $4);
237 29 my %args;
238  
239 29 ▶ if (defined $tz) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz) 15 14 29
240 15 ▶ if ($tz eq 'Z') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tz eq 'Z') { } 3 12 15
elsif ($tz =~ /^([+-])(\d{2})$/) { } 5 7 12
241 3 $self->{datetime}->set_time_zone('UTC');
242 } elsif ($tz =~ /^([+-])(\d{2})$/) {
243 5 $tz = "$1$2:00";
244 } else {
245 7 $tz =~ s/^([+-])(\d{2}):?(\d{2})$/$1$2:$3/;
246 }
247 15 $self->{datetime}->set_time_zone($tz);
248 }
249  
250 29 @args{qw(year month day)} = split /-/, $date;
251 29 ▶ $args{$_} ||= 01 foreach qw(month day);
Condition100%2/2
$args{$_} ||= 1
l!l
499
MC/DC100%1/1
$args{$_} ||= 1
$args{$_}
Truth table100%2/2
A
A= $args{$_}
Aresult
11
00
252  
253 29 @args{qw(hour minute second)} = split /:/, $time;
254 29 ▶ $args{$_} ||= 00 foreach qw(minute second);
Condition100%2/2
$args{$_} ||= 0
l!l
4414
MC/DC100%1/1
$args{$_} ||= 0
$args{$_}
Truth table100%2/2
A
A= $args{$_}
Aresult
11
00
255  
256 29 ▶ if (defined $fractional) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fractional) 7 22 29
257 7 my $nanosecond = $fractional;
258 7 ▶ if (length($nanosecond) < 9) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $nanosecond < 9) 6 1 7
259 6 $nanosecond .= '0' x (9 - length($nanosecond));
260 }
261 7 $args{nanosecond} = int($nanosecond);
262 }
263  
264 29 my $valid_date = $self->_check_date(map $args{$_}, qw(year month day));
265 29 my $valid_time = $self->_check_time(map $args{$_}, qw(hour minute second));
266  
267 29 ▶ if (not $valid_date && $valid_time) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid_date and $valid_time) 0 29 29
Condition33%1/3
$valid_date and $valid_time
!ll&&!rl&&r
0029
MC/DC0%0/2
$valid_date and $valid_time
$valid_date $valid_time
Truth table33%1/3
A and B
A= $valid_dateB= $valid_time
ABresult
0X0
100
111
268 0 ▶ my $type = !$valid_date ? 'date' : 'time';
Branch: 1 branch
BranchTrueFalseTotal
!$valid_date ? : 0 0 0
269 0 $self->_set_failure;
270 0 $self->_set_error("(invalid $type)");
271 0 return $self->_get_datetime_object;
272 }
273  
274 29 $self->_set(%args);
275 29 $self->_set_valid_exp;
276 }
277 elsif ($date_string =~ /^([+-]) (\d+?) ([a-zA-Z]+)$/x) {
278 14 my ($prefix, $value, $unit) = ($1, $2, lc $3);
279  
280 14 my %methods = (
281 '+' => '_add',
282 '-' => '_subtract',
283 );
284 14 my $method = $methods{$prefix};
285  
286 14 ▶ if (none { $unit =~ /^${_}s?$/ } @{$self->{data}->__units('ordered')}) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $unit =~ /^${_}s?$/; } , @{$self->{"data"}->__units("ordered");})) 2 12 14
287 2 $self->_set_failure;
288 2 $self->_set_error("(invalid unit)");
289 2 return $self->_get_datetime_object;
290 }
291 12 $self->$method($unit => $value);
292  
293 12 $self->_set_valid_exp;
294 }
295 elsif ($date_string =~ /^\d{14}$/) {
296 6 my %args;
297 6 @args{qw(year month day hour minute second)} = $date_string =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/;
298  
299 6 my $valid_date = $self->_check_date(map $args{$_}, qw(year month day));
300 6 my $valid_time = $self->_check_time(map $args{$_}, qw(hour minute second));
301  
302 6 ▶ if (not $valid_date && $valid_time) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid_date and $valid_time) 0 6 6
Condition33%1/3
$valid_date and $valid_time
!ll&&!rl&&r
006
MC/DC0%0/2
$valid_date and $valid_time
$valid_date $valid_time
Truth table33%1/3
A and B
A= $valid_dateB= $valid_time
ABresult
0X0
100
111
303 0 ▶ my $type = !$valid_date ? 'date' : 'time';
Branch: 1 branch
BranchTrueFalseTotal
!$valid_date ? : 0 0 0
304 0 $self->_set_failure;
305 0 $self->_set_error("(invalid $type)");
306 0 return $self->_get_datetime_object;
307 }
308  
309 6 $self->_set(%args);
310  
311 6 $self->{datetime}->truncate(to => 'second');
312 6 $self->_set_truncated;
313 6 $self->_set_valid_exp;
314 }
315 else {
316 11494 @{$self->{tokens}} = split /\s+/, $date_string;
317 11494 $self->{data}->__init('tokens')->($self);
318 11494 $self->{count}{tokens} = @{$self->{tokens}};
319  
320 11494 $self->_process;
321 }
322  
323 12003 my $trace = $self->_trace_string;
324 12003 ▶ if (defined $trace) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $trace) 11641 362 12003
325 11641 @{$self->{traces}} = $trace;
326 }
327  
328 12003 return $self->_get_datetime_object;
329 }
330  
331 sub _params_init
332 13474 ▶{
Subroutine _params_init: called CC=3 SCAR=13.1
333 13474 my $self = shift;
334 13474 my $params = pop;
335  
336 13474 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 0 13474 13474
337 0 validate(@_, { string => { type => SCALAR }});
338 0 my %opts = @_;
339 0 foreach my $opt (keys %opts) {
340 0 ${$params->{$opt}} = $opts{$opt};
341 }
342 }
343 else {
344 13474 validate_pos(@_, { type => SCALAR });
345 13474 (${$params->{string}}) = @_;
346 }
347  
348 13474 trim($params->{string});
349 }
350  
351 sub _parse_init
352 12007 ▶{
Subroutine _parse_init: called CC=2 SCAR=6.9
353 12007 my $self = shift;
354  
355 12007 $self->_params_init(@_, { string => \$self->{date_string} });
356  
357 my $set_datetime = sub
358 2929 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
359 2929 my ($method, $args) = @_;
360  
361 2929 ▶ if (exists $self->{Datetime} && $method eq 'now') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'Datetime'} and $method eq 'now') { } 24 2905 2929
Condition66%2/3
exists $self->{"Datetime"} and $method eq "now"
!ll&&!rl&&r
2905024
MC/DC50%1/2
exists $self->{"Datetime"} and $method eq "now"
exists $self->{"Datetime"} $method eq "now"
Truth table66%2/3
A and B
A= exists $self->{"Datetime"}B= $method eq "now"
ABresult
0X0
100
111
362 24 $self->{datetime} = dclone($self->{Datetime});
363 }
364 else {
365 $self->{datetime} = DateTime::HiRes->$method(
366 time_zone => $self->{Time_zone},
367 2905 %$args,
368 );
369 }
370 12007 };
371  
372 12007 ▶ if ($self->{running_tests}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'running_tests'}) { } 9078 2929 12007
373 9078 $self->{datetime} = $self->{datetime_test}->clone;
374 }
375 else {
376 2929 $set_datetime->('now', {});
377 }
378  
379 12007 $self->_init_vars;
380  
381 12007 $self->_unset_failure;
382 12007 $self->_unset_error;
383 12007 $self->_unset_valid_exp;
384 12007 $self->_unset_trace;
385 12007 $self->_unset_truncated;
386 }
387  
388 sub parse_datetime_duration
389 1258 ▶{
Subroutine parse_datetime_duration: called CC=7 SCAR=19.5
Pod documented
390 1258 my $self = shift;
391  
392 1258 my $duration_string;
393 1258 $self->_params_init(@_, { string => \$duration_string });
394 1258 my $timespan_sep = $self->{data}->__timespan('literal');
395  
396 my @date_strings = $duration_string =~ /\s+ $timespan_sep \s+/ix
397 1039 ? do { $self->{duration} = true;
398 1039 split /\s+ $timespan_sep \s+/ix, $duration_string }
399 1258 ▶ : do { $self->{duration} = false;
Branch: 1 branch
BranchTrueFalseTotal
$duration_string =~ /\s+ $timespan_sep \s+/xi ? : 1039 219 1258
400 219 ($duration_string) };
401  
402 1258 my $max = 2;
403  
404 1258 my $shrinked = false;
405 1258 ▶ if (@date_strings > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (@date_strings > $max) 1 1257 1258
406 1 my $offset = $max;
407 1 splice (@date_strings, $offset);
408 1 $shrinked = true;
409 }
410  
411 1258 $self->_rewrite_duration(\@date_strings);
412  
413 1258 $self->_pre_duration(\@date_strings);
414 1258 @$self{qw(state truncated_duration)} = ({}, []);
415  
416 1258 my (@queue, @traces, @truncated);
417 1258 foreach my $date_string (@date_strings) {
418 2297 push @queue, $self->parse_datetime($date_string);
419 2297 $self->_save_state(
420 valid_expression => $self->_get_valid_exp,
421 failure => $self->_get_failure,
422 error => $self->_get_error,
423 );
424 2297 ▶ if (@{$self->{traces}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"traces"};}) 2292 5 2297
425 2292 push @traces, $self->{traces}[0];
426 }
427 2297 ▶ if ($self->{running_tests}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"running_tests"}) 1932 365 2297
428 1932 push @truncated, $self->_get_truncated;
429 }
430 }
431  
432 1258 $self->_post_duration(\@queue, \@traces, \@truncated);
433 1258 $self->_restore_state;
434  
435 1258 delete @$self{qw(duration insert state)};
436  
437 1258 @{$self->{traces}} = @traces;
438 1258 @{$self->{truncated_duration}} = @truncated;
439 1258 $self->{input_string} = $duration_string;
440  
441 1258 ▶ if ($shrinked) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shrinked) 1 1257 1258
442 1 $self->_set_failure;
443 1 $self->_set_error("(limit of $max duration substrings exceeded)");
444 }
445  
446 1258 return @queue;
447 }
448  
449 sub extract_datetime
450 209 ▶{
Subroutine extract_datetime: called CC=3 SCAR=11.0
Pod documented
451 209 my $self = shift;
452  
453 209 my $extract_string;
454 209 $self->_params_init(@_, { string => \$extract_string });
455  
456 209 $self->_unset_failure;
457 209 $self->_unset_error;
458 209 $self->_unset_valid_exp;
459  
460 209 $self->{input_string} = $extract_string;
461  
462 209 $self->{mode} = 'extract';
463  
464 209 my @expressions = $self->_extract_expressions($extract_string);
465  
466 209 ▶ $self->_set_valid_exp if @expressions;
Branch: 1 branch
BranchTrueFalseTotal
if @expressions 208 1 209
467  
468 209 ▶ return wantarray ? @expressions : $expressions[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 207 2 209
469 }
470  
471 sub success
472 10906 ▶{
Subroutine success: called CC=3 SCAR=11.0
Pod documented
473 10906 my $self = shift;
474  
475 10906 ▶ return ($self->_get_valid_exp && !$self->_get_failure) ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$self->_get_valid_exp && !$self->_get_failure ? : 10542 364 10906
Condition100%3/3
$self->_get_valid_exp and not $self->_get_failure
!ll&&!rl&&r
363110542
MC/DC100%2/2
$self->_get_valid_exp and not $self->_get_failure
$self->_get_valid_exp not $self->_get_failure
Truth table100%3/3
A and not(B)
A= $self->_get_valid_expB= not $self->_get_failure
ABresult
0X0
100
111
476 }
477  
478 sub error
479 6 ▶{
Subroutine error: called CC=4 SCAR=13.9
Pod documented
480 6 my $self = shift;
481  
482 6 ▶ return '' if $self->success;
Branch: 1 branch
BranchTrueFalseTotal
if $self->success 1 5 6
483  
484 my $error = sub
485 5 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
486 5 ▶ return undef unless defined $self->{mode} && length $self->{mode};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"mode"} and length $self->{"mode"} 1 4 5
Condition66%2/3
defined $self->{"mode"} and length $self->{"mode"}
!ll&&!rl&&r
014
MC/DC50%1/2
defined $self->{"mode"} and length $self->{"mode"}
defined $self->{"mode"} length $self->{"mode"}
Truth table66%2/3
A and B
A= defined $self->{"mode"}B= length $self->{"mode"}
ABresult
0X0
100
111
487 4 my %errors = (
488 extract => "'$self->{input_string}' cannot be extracted from",
489 parse => "'$self->{input_string}' does not parse",
490 );
491 4 return $errors{$self->{mode}};
492 5 }->();
493  
494 5 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) { } 4 1 5
495 4 ▶ $error .= ' ' . ($self->_get_error || '(perhaps you have some garbage?)');
Condition100%2/2
$self->_get_error || '(perhaps you have some garbage?)'
l!l
13
MC/DC100%1/1
$self->_get_error || '(perhaps you have some garbage?)'
$self->_get_error
Truth table100%2/2
A
A= $self->_get_error
Aresult
11
00
496 }
497 else {
498 1 $error = 'neither extracting nor parsing method invoked';
499 }
500  
501 5 return $error;
502 }
503  
504 sub trace
505 7 ▶{
Subroutine trace: called CC=2 SCAR=6.9
Pod documented
506 7 my $self = shift;
507  
508 7 ▶ return @{$self->{traces} || []};
Condition100%2/2
$self->{'traces'} || []
l!l
61
MC/DC100%1/1
$self->{'traces'} || []
$self->{'traces'}
Truth table100%2/2
A
A= $self->{'traces'}
Aresult
11
00
509 }
510  
511 sub _process
512 11815 ▶{
Subroutine _process: called CC=27 SCAR=33.0
513 11815 my $self = shift;
514  
515 11815 my %opts;
516  
517 11815 ▶ if (!exists $self->{lookup}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"lookup"}) 10697 1118 11815
518 10697 foreach my $keyword (keys %{$self->{data}->__grammar('')}) {
519 770184 my $count = scalar @{$self->{data}->__grammar($keyword)->[0]};
520 770184 push @{$self->{lookup}{$count}}, [ $keyword, false ];
521 770184 ▶ if ($self->_expand_for($keyword)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_expand_for($keyword)) 203243 566941 770184
522 203243 push @{$self->{lookup}{$count + 1}}, [ $keyword, true ];
523 }
524 }
525 }
526  
527 11815 ▶ PARSE: foreach my $lookup (@{$self->{lookup}{$self->{count}{tokens}} || []}) {
Condition50%1/2
$self->{'lookup'}{$self->{'count'}{'tokens'}} || []
l!l
118150
MC/DC0%0/1
$self->{'lookup'}{$self->{'count'}{'tokens'}} || []
$self->{'lookup'}{$self->{'count'}{'tokens'}}
Truth table50%1/2
A
A= $self->{'lookup'}{$self->{'count'}{'tokens'}}
Aresult
11
00
528 102236 my ($keyword, $expandable) = @$lookup;
529  
530 102236 my @grammar = @{$self->{data}->__grammar($keyword)};
531 102236 my $types_entry = shift @grammar;
532  
533 102236 ▶ @grammar = $self->_expand($keyword, $types_entry, \@grammar) if $expandable;
Branch: 1 branch
BranchTrueFalseTotal
if $expandable 11513 90723 102236
534  
535 102236 foreach my $entry (@grammar) {
536 539492 ▶ my ($types, $expression) = $expandable ? @$entry : ($types_entry, $entry);
Branch: 1 branch
BranchTrueFalseTotal
$expandable ? : 180423 359069 539492
537 539492 my $valid_expression = true;
538 539492 my $definition = $expression->[0];
539 539492 my @positions = sort {$a <=> $b} keys %$definition;
540 539492 my (%first_stack, %rest_stack);
541 539492 foreach my $pos (@positions) {
542 650740 ▶ if ($types->[$pos] eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if ($types->[$pos] eq 'SCALAR') { } 62079 588661 650740
elsif ($types->[$pos] eq 'REGEXP') { } 588661 0 588661
543 62079 ▶ if (defined $definition->{$pos}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $definition->{$pos}) 62079 0 62079
544 62079 ▶ if (${$self->_token($pos)} =~ /^$definition->{$pos}$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$self->_token($pos);} =~ /^$definition->{$pos}$/i) { } 6645 55434 62079
545 6645 next;
546 }
547 else {
548 55434 $valid_expression = false;
549 55434 last;
550 }
551 }
552 }
553 elsif ($types->[$pos] eq 'REGEXP') {
554 588661 ▶ if (my @captured = ${$self->_token($pos)} =~ $definition->{$pos}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@captured) = ${$self->_token($pos);} =~ /$definition->{$pos}/) { } 116422 472239 588661
555 116422 $first_stack{$pos} = shift @captured;
556 116422 $rest_stack{$pos} = [ @captured ];
557 116422 next;
558 }
559 else {
560 472239 $valid_expression = false;
561 472239 last;
562 }
563 }
564 else {
565 0 die "grammar error at keyword \"$keyword\" within $self->{grammar_class}: ",
566 "unknown type $types->[$pos]\n";
567 }
568 }
569 539492 ▶ if ($valid_expression && @{$expression->[2]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valid_expression and @{$expression->[2];}) 8765 530727 539492
Condition100%3/3
$valid_expression and @{$expression->[2];}
!ll&&!rl&&r
52767330548765
MC/DC100%2/2
$valid_expression and @{$expression->[2];}
$valid_expression @{$expression->[2];}
Truth table100%3/3
A and B
A= $valid_expressionB= @{$expression->[2];}
ABresult
0X0
100
111
570 8765 my $i = 0;
571 8765 foreach my $check (@{$expression->[2]}) {
572 11067 my @pos = @{$expression->[1][$i++]};
573 11067 my $error;
574 11067 $valid_expression &= $check->(\%first_stack, \%rest_stack, \@pos, \$error);
575 11067 ▶ unless ($valid_expression) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid_expression) 366 10701 11067
576 366 $self->_set_error("($error)");
577 366 last;
578 }
579 }
580 }
581 539492 ▶ if ($valid_expression) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valid_expression) 11453 528039 539492
582 11453 $self->_set_valid_exp;
583 11453 ▶ my @truncate_to = @{$expression->[6]->{truncate_to} || []};
Condition100%2/2
$expression->[6]{'truncate_to'} || []
l!l
10796657
MC/DC100%1/1
$expression->[6]{'truncate_to'} || []
$expression->[6]{'truncate_to'}
Truth table100%2/2
A
A= $expression->[6]{'truncate_to'}
Aresult
11
00
584 11453 my $i = 0;
585 11453 foreach my $positions (@{$expression->[3]}) {
586 19923 my ($c, @values);
587 19923 foreach my $pos (@$positions) {
588 25059 ▶ my $index = ref $pos eq 'HASH' ? (keys %$pos)[0] : $pos;
Branch: 1 branch
BranchTrueFalseTotal
ref $pos eq 'HASH' ? : 18495 6564 25059
589 $values[$c++] = ref $pos
590 ? $index eq 'VALUE'
591 ? $pos->{$index}
592 : $self->SUPER::_helper($pos->{$index}, $first_stack{$index})
593 : exists $first_stack{$index}
594 ? $first_stack{$index}
595 0 ▶ : ${$self->_token($index)};
Branch: 3 branches
BranchTrueFalseTotal
ref $pos ? : 18495 6564 25059
$index eq 'VALUE' ? : 270 18225 18495
exists $first_stack{$index} ? : 6564 0 6564
596 }
597 19923 my $worker = "SUPER::$expression->[5]->[$i]";
598 19923 $self->$worker(@values, $expression->[4]->[$i++]);
599 19923 $self->_truncate(shift @truncate_to);
600 }
601 11453 %opts = %{$expression->[6]};
602 11453 $self->{keyword} = $keyword;
603 11453 last PARSE;
604 }
605 }
606 }
607  
608 11815 $self->_post_process(%opts);
609 }
610  
611 sub _truncate
612 19923 ▶{
Subroutine _truncate: called CC=6 SCAR=17.9
613 19923 my $self = shift;
614 19923 my ($truncate_to) = @_;
615  
616 19923 ▶ return unless defined $truncate_to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $truncate_to 7900 12023 19923
617  
618 12023 ▶ my @truncate_to = map { $_ =~ /_/ ? split /_/, $_ : $_ } $truncate_to;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /_/ ? : 8322 3701 12023
619 12023 my $i = 0;
620 12023 my @units = @{$self->{data}->__units('ordered')};
621 12023 my %indexes = map { $_ => $i++ } @units;
622 12023 foreach my $unit (@truncate_to) {
623 20955 my $index = $indexes{$unit} - 1;
624 20955 ▶ if (defined $units[$index] && !exists $self->{modified}{$units[$index]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $units[$index] and not exists $self->{"modified"}{$units[$index]}) 11969 8986 20955
Condition66%2/3
defined $units[$index] and not exists $self->{"modified"}{$units[$index]}
!ll&&!rl&&r
0898611969
MC/DC50%1/2
defined $units[$index] and not exists $self->{"modified"}{$units[$index]}
defined $units[$index] not exists $self->{"modified"}{$units[$index]}
Truth table66%2/3
A and not(B)
A= defined $units[$index]B= not exists $self->{"modified"}{$units[$index]}
ABresult
0X0
100
111
625 11969 $self->{datetime}->truncate(to => $unit);
626 11969 $self->_set_truncated;
627 11969 last;
628 }
629 }
630 }
631  
632 sub _post_process
633 11815 ▶{
Subroutine _post_process: called CC=5 SCAR=16.1
634 11815 my $self = shift;
635 11815 my %opts = @_;
636  
637 11815 delete $opts{truncate_to};
638  
639 11815 ▶ if (($self->{Prefer_future} || $self->{Demand_future})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Prefer_future"} || $self->{"Demand_future"} and (exists $opts{"advance_future"} and $opts{"advance_future"})) 2070 9745 11815
Condition88%8/9
$self->{"Prefer_future"} || $self->{"Demand_future"} and (exists $opts{"advance_future"} and $opts{"advance_future"})
!ll&&!rl&&r
9697482070
$self->{"Prefer_future"} or $self->{"Demand_future"}
l!l&&r!l&&!r
106810509697
exists $opts{"advance_future"} and $opts{"advance_future"}
!ll&&!rl&&r
4802070
MC/DC75%3/4
$self->{"Prefer_future"} || $self->{"Demand_future"} and (exists $opts{"advance_future"} and $opts{"advance_future"})
$self->{"Prefer_future"} $self->{"Demand_future"} exists $opts{"advance_future"} $opts{"advance_future"}
Truth table71%5/7
A or B and C and D
A= $self->{"Prefer_future"}B= $self->{"Demand_future"}C= exists $opts{"advance_future"}D= $opts{"advance_future"}
ABCDresult
00XX0
1X0X0
1X100
010X0
01100
1X111
01111
640 && (exists $opts{advance_future} && $opts{advance_future})
641 ) {
642 2070 $self->_advance_future;
643 }
644 }
645  
646 sub _advance_future
647 2106 ▶{
Subroutine _advance_future: called CC=35 SCAR=35.9
648 2106 my $self = shift;
649 2106 my %advance = map { $_ => true } @_;
650  
651 2106 my %modified = map { $_ => true } keys %{$self->{modified}};
652 my $token_contains = sub
653 2520 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
654 2520 my ($identifier) = @_;
655 27066 ▶ return any {
Subroutine __ANON__: called CC=1 SCAR=0.0
656 27066 my $data = $_;
657 43158 ▶ any {
Subroutine __ANON__: called CC=1 SCAR=0.0
658 43158 my $token = $_;
659 43158 $token =~ /^$data$/i;
660 27066 } @{$self->{tokens}}
661 2520 } @{$self->{data}->{$identifier}};
662 2106 };
663  
664 my $now = exists $self->{Datetime}
665 ? dclone($self->{Datetime})
666 2106 ▶ : DateTime::HiRes->now(time_zone => $self->{Time_zone});
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'Datetime'} ? : 18 2088 2106
667  
668 2106 ▶ my $day_of_week = sub { $_[0]->_Day_of_Week(map $_[0]->{datetime}->$_, qw(year month day)) };
Subroutine __ANON__: called CC=1 SCAR=0.0
669  
670 2106 my $skip_weekdays = false;
671  
672 2106 ▶ if ((all { /^(?:(?:nano)?second|minute|hour)$/ } keys %modified)
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 4 branches
BranchTrueFalseTotal
if (&all(sub { /^(?:(?:nano)?second|minute|hour)$/; } , keys %modified) and (exists $self->{'modified'}{'hour'} and $self->{'modified'}{'hour'} == 1) and $self->{'Prefer_future'} && $self->{'datetime'} < $now || $self->{'Demand_future'} && $self->{'datetime'} <= $now) { } 234 1872 2106
elsif (sub { return &false() unless @{$self->{'tokens'};} == 2; my($day, $weekday) = map($self->{'data'}->__RE($_), ('day', 'weekday')); if ($self->{'tokens'}[0] =~ /$day/ and $self->{'tokens'}[1] =~ /$weekday/) { $skip_weekdays = &true(); return &true(); } ; return &false(); } ->() and &all(sub { /^(?:day|month|year)$/; } , keys %modified) and $self->{'Prefer_future'} && $self->{'datetime'}->day < $now->day || $self->{'Demand_future'} && $self->{'datetime'}->day <= $now->day) { } 18 1854 1872
elsif (&$token_contains('weekdays_all') and not $skip_weekdays and (exists $self->{'modified'}{'day'} and $self->{'modified'}{'day'} == 1) and $self->{'Prefer_future'} && &$day_of_week($self) < $now->wday || $self->{'Demand_future'} && &$day_of_week($self) <= $now->wday) { } 1188 666 1854
elsif (&$token_contains('months_all') || $advance{'md'} and &all(sub { /^(?:day|month)$/; } , keys %modified) and (exists $self->{'modified'}{'month'} and $self->{'modified'}{'month'} == 1) and exists $self->{'modified'}{'day'} ? $self->{'modified'}{'day'} == 1 ? &true() : &false() : &true() and $self->{'Prefer_future'} && $self->{'datetime'}->day_of_year < $now->day_of_year || $self->{'Demand_future'} && $self->{'datetime'}->day_of_year <= $now->day_of_year) { } 72 1182 1254
Condition83%15/18
&all(sub { /^(?:(?:nano)?second|minute|hour)$/; } , keys %modified) and (exists $self->{"modified"}{"hour"} and $self->{"modified"}{"hour"} == 1) and $self->{"Prefer_future"} && $self->{"datetime"} < $now || $self->{"Demand_future"} && $self->{"datetime"} <= $now
!ll&&!rl&&r
1656216234
&all(sub { /^(?:(?:nano)?second|minute|hour)$/; } , keys %modified) and (exists $self->{"modified"}{"hour"} and $self->{"modified"}{"hour"} == 1)
!ll&&!rl&&r
16560450
exists $self->{"modified"}{"hour"} and $self->{"modified"}{"hour"} == 1
!ll&&!rl&&r
00450
$self->{"Prefer_future"} and $self->{"datetime"} < $now or $self->{"Demand_future"} and $self->{"datetime"} <= $now
l!l&&r!l&&!r
114120216
$self->{"Prefer_future"} and $self->{"datetime"} < $now
!ll&&!rl&&r
222114114
$self->{"Demand_future"} and $self->{"datetime"} <= $now
!ll&&!rl&&r
114102120
MC/DC57%4/7
&all(sub { /^(?:(?:nano)?second|minute|hour)$/; } , keys %modified) and (exists $self->{"modified"}{"hour"} and $self->{"modified"}{"hour"} == 1) and $self->{"Prefer_future"} && $self->{"datetime"} < $now || $self->{"Demand_future"} && $self->{"datetime"} <= $now
&all(sub { /^(?:(?:nano)?second|minute|hour)$/; } , keys %modified) exists $self->{"modified"}{"hour"} $self->{"modified"}{"hour"} == 1 $self->{"Prefer_future"} $self->{"datetime"} < $now $self->{"Demand_future"} $self->{"datetime"} <= $now
Truth table50%5/10
A and B and C and D and E or F and G
A= &all(sub { /^(?:(?:nano)?second|minute|hour)$/; } , keys %modified)B= exists $self->{"modified"}{"hour"}C= $self->{"modified"}{"hour"} == 1D= $self->{"Prefer_future"}E= $self->{"datetime"} < $nowF= $self->{"Demand_future"}G= $self->{"datetime"} <= $now
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110X0X0
1110X100
111100X0
11110100
11111XX1
1110X111
11110111
673 && (exists $self->{modified}{hour} && $self->{modified}{hour} == 1)
674 && (($self->{Prefer_future} && $self->{datetime} < $now)
675 || ($self->{Demand_future} && $self->{datetime} <= $now))
676 ) {
677 234 $self->{postprocess}{day} = 1;
678 }
679 1872 ▶ elsif (sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
Condition93%14/15
sub { return &false() unless @{$self->{"tokens"};} == 2; my($day, $weekday) = map($self->{"data"}->__RE($_), ("day", "weekday")); if ($self->{"tokens"}[0] =~ /$day/ and $self->{"tokens"}[1] =~ /$weekday/) { $skip_weekdays = &true(); return &true(); } ; return &false(); } ->() and &all(sub { /^(?:day|month|year)$/; } , keys %modified) and $self->{"Prefer_future"} && $self->{"datetime"}->day < $now->day || $self->{"Demand_future"} && $self->{"datetime"}->day <= $now->day
!ll&&!rl&&r
18361818
sub { return &false() unless @{$self->{"tokens"};} == 2; my($day, $weekday) = map($self->{"data"}->__RE($_), ("day", "weekday")); if ($self->{"tokens"}[0] =~ /$day/ and $self->{"tokens"}[1] =~ /$weekday/) { $skip_weekdays = &true(); return &true(); } ; return &false(); } ->() and &all(sub { /^(?:day|month|year)$/; } , keys %modified)
!ll&&!rl&&r
1836036
$self->{"Prefer_future"} and $self->{"datetime"}->day < $now->day or $self->{"Demand_future"} and $self->{"datetime"}->day <= $now->day
l!l&&r!l&&!r
61218
$self->{"Prefer_future"} and $self->{"datetime"}->day < $now->day
!ll&&!rl&&r
18126
$self->{"Demand_future"} and $self->{"datetime"}->day <= $now->day
!ll&&!rl&&r
12612
MC/DC66%4/6
sub { return &false() unless @{$self->{"tokens"};} == 2; my($day, $weekday) = map($self->{"data"}->__RE($_), ("day", "weekday")); if ($self->{"tokens"}[0] =~ /$day/ and $self->{"tokens"}[1] =~ /$weekday/) { $skip_weekdays = &true(); return &true(); } ; return &false(); } ->() and &all(sub { /^(?:day|month|year)$/; } , keys %modified) and $self->{"Prefer_future"} && $self->{"datetime"}->day < $now->day || $self->{"Demand_future"} && $self->{"datetime"}->day <= $now->day
sub { return &false() unless @{$self->{"tokens"};} == 2; my($day, $weekday) = map($self->{"data"}->__RE($_), ("day", "weekday")); if ($self->{"tokens"}[0] =~ /$day/ and $self->{"tokens"}[1] =~ /$weekday/) { $skip_weekdays = &true(); return &true(); } ; return &false(); } ->() &all(sub { /^(?:day|month|year)$/; } , keys %modified) $self->{"Prefer_future"} $self->{"datetime"}->day < $now->day $self->{"Demand_future"} $self->{"datetime"}->day <= $now->day
Truth table55%5/9
A and B and C and D or E and F
A= sub { return &false() unless @{$self->{"tokens"};} == 2; my($day, $weekday) = map($self->{"data"}->__RE($_), ("day", "weekday")); if ($self->{"tokens"}[0] =~ /$day/ and $self->{"tokens"}[1] =~ /$weekday/) { $skip_weekdays = &true(); return &true(); } ; return &false(); } ->()B= &all(sub { /^(?:day|month|year)$/; } , keys %modified)C= $self->{"Prefer_future"}D= $self->{"datetime"}->day < $now->dayE= $self->{"Demand_future"}F= $self->{"datetime"}->day <= $now->day
ABCDEFresult
0XXXXX0
10XXXX0
110X0X0
110X100
11100X0
1110100
1111XX1
110X111
1110111
680 1872 ▶ return false unless @{$self->{tokens}} == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"tokens"};} == 2 474 1398 1872
681 1398 my ($day, $weekday) = map $self->{data}->__RE($_), qw(day weekday);
682 1398 ▶ if ($self->{tokens}->[0] =~ $day
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"}[0] =~ /$day/ and $self->{"tokens"}[1] =~ /$weekday/) 36 1362 1398
Condition100%3/3
$self->{"tokens"}[0] =~ /$day/ and $self->{"tokens"}[1] =~ /$weekday/
!ll&&!rl&&r
13441836
MC/DC100%2/2
$self->{"tokens"}[0] =~ /$day/ and $self->{"tokens"}[1] =~ /$weekday/
$self->{"tokens"}[0] =~ /$day/ $self->{"tokens"}[1] =~ /$weekday/
Truth table100%3/3
A and B
A= $self->{"tokens"}[0] =~ /$day/B= $self->{"tokens"}[1] =~ /$weekday/
ABresult
0X0
100
111
683 && $self->{tokens}->[1] =~ $weekday) {
684 36 $skip_weekdays = true;
685 36 return true;
686 }
687 1362 return false;
688 }->()
689 108 ▶ && (all { /^(?:day|month|year)$/ } keys %modified)
Subroutine __ANON__: called CC=1 SCAR=0.0
690 && (($self->{Prefer_future} && $self->{datetime}->day < $now->day)
691 || ($self->{Demand_future} && $self->{datetime}->day <= $now->day))
692 ) {
693 18 $self->{postprocess}{week} = 4;
694 }
695 ▶ elsif (($token_contains->('weekdays_all') && !$skip_weekdays)
Condition85%18/21
&$token_contains("weekdays_all") and not $skip_weekdays and (exists $self->{"modified"}{"day"} and $self->{"modified"}{"day"} == 1) and $self->{"Prefer_future"} && &$day_of_week($self) < $now->wday || $self->{"Demand_future"} && &$day_of_week($self) <= $now->wday
!ll&&!rl&&r
3243421188
&$token_contains("weekdays_all") and not $skip_weekdays and (exists $self->{"modified"}{"day"} and $self->{"modified"}{"day"} == 1)
!ll&&!rl&&r
32401530
&$token_contains("weekdays_all") and not $skip_weekdays
!ll&&!rl&&r
306181530
exists $self->{"modified"}{"day"} and $self->{"modified"}{"day"} == 1
!ll&&!rl&&r
001530
$self->{"Prefer_future"} and &$day_of_week($self) < $now->wday or $self->{"Demand_future"} and &$day_of_week($self) <= $now->wday
l!l&&r!l&&!r
546642342
$self->{"Prefer_future"} and &$day_of_week($self) < $now->wday
!ll&&!rl&&r
762222546
$self->{"Demand_future"} and &$day_of_week($self) <= $now->wday
!ll&&!rl&&r
222120642
MC/DC62%5/8
&$token_contains("weekdays_all") and not $skip_weekdays and (exists $self->{"modified"}{"day"} and $self->{"modified"}{"day"} == 1) and $self->{"Prefer_future"} && &$day_of_week($self) < $now->wday || $self->{"Demand_future"} && &$day_of_week($self) <= $now->wday
&$token_contains("weekdays_all") not $skip_weekdays exists $self->{"modified"}{"day"} $self->{"modified"}{"day"} == 1 $self->{"Prefer_future"} &$day_of_week($self) < $now->wday $self->{"Demand_future"} &$day_of_week($self) <= $now->wday
Truth table54%6/11
A and not(B) and C and D and E and F or G and H
A= &$token_contains("weekdays_all")B= not $skip_weekdaysC= exists $self->{"modified"}{"day"}D= $self->{"modified"}{"day"} == 1E= $self->{"Prefer_future"}F= &$day_of_week($self) < $now->wdayG= $self->{"Demand_future"}H= &$day_of_week($self) <= $now->wday
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110X0X0
11110X100
1111100X0
111110100
111111XX1
11110X111
111110111
696 && (exists $self->{modified}{day} && $self->{modified}{day} == 1)
697 && (($self->{Prefer_future} && $day_of_week->($self) < $now->wday)
698 || ($self->{Demand_future} && $day_of_week->($self) <= $now->wday))
699 ) {
700 1188 $self->{postprocess}{day} = 7;
701 }
702 ▶ elsif (($token_contains->('months_all') || $advance{md})
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{'modified'}{'day'} ? : 66 24 90
$self->{'modified'}{'day'} == 1 ? : 66 0 66
Condition81%22/27
&$token_contains("months_all") || $advance{"md"} and &all(sub { /^(?:day|month)$/; } , keys %modified) and (exists $self->{"modified"}{"month"} and $self->{"modified"}{"month"} == 1) and exists $self->{"modified"}{"day"} ? $self->{"modified"}{"day"} == 1 ? &true() : &false() : &true() and $self->{"Prefer_future"} && $self->{"datetime"}->day_of_year < $now->day_of_year || $self->{"Demand_future"} && $self->{"datetime"}->day_of_year <= $now->day_of_year
!ll&&!rl&&r
5761872
&$token_contains("months_all") || $advance{"md"} and &all(sub { /^(?:day|month)$/; } , keys %modified) and (exists $self->{"modified"}{"month"} and $self->{"modified"}{"month"} == 1) and exists $self->{"modified"}{"day"} ? $self->{"modified"}{"day"} == 1 ? &true() : &false() : &true()
!ll&&!rl&&r
576090
&$token_contains("months_all") || $advance{"md"} and &all(sub { /^(?:day|month)$/; } , keys %modified) and (exists $self->{"modified"}{"month"} and $self->{"modified"}{"month"} == 1)
!ll&&!rl&&r
576090
&$token_contains("months_all") || $advance{"md"} and &all(sub { /^(?:day|month)$/; } , keys %modified)
!ll&&!rl&&r
576090
&$token_contains("months_all") or $advance{"md"}
l!l&&r!l&&!r
5436576
exists $self->{"modified"}{"month"} and $self->{"modified"}{"month"} == 1
!ll&&!rl&&r
0090
$self->{"Prefer_future"} and $self->{"datetime"}->day_of_year < $now->day_of_year or $self->{"Demand_future"} and $self->{"datetime"}->day_of_year <= $now->day_of_year
l!l&&r!l&&!r
363618
$self->{"Prefer_future"} and $self->{"datetime"}->day_of_year < $now->day_of_year
!ll&&!rl&&r
421236
$self->{"Demand_future"} and $self->{"datetime"}->day_of_year <= $now->day_of_year
!ll&&!rl&&r
12636
MC/DC50%5/10
&$token_contains("months_all") || $advance{"md"} and &all(sub { /^(?:day|month)$/; } , keys %modified) and (exists $self->{"modified"}{"month"} and $self->{"modified"}{"month"} == 1) and exists $self->{"modified"}{"day"} ? $self->{"modified"}{"day"} == 1 ? &true() : &false() : &true() and $self->{"Prefer_future"} && $self->{"datetime"}->day_of_year < $now->day_of_year || $self->{"Demand_future"} && $self->{"datetime"}->day_of_year <= $now->day_of_year
&$token_contains("months_all") $advance{"md"} &all(sub { /^(?:day|month)$/; } , keys %modified) exists $self->{"modified"}{"month"} $self->{"modified"}{"month"} == 1 exists $self->{"modified"}{"day"} ? $self->{"modified"}{"day"} == 1 ? &true() : &false() : &true() $self->{"Prefer_future"} $self->{"datetime"}->day_of_year < $now->day_of_year $self->{"Demand_future"} $self->{"datetime"}->day_of_year <= $now->day_of_year
Truth table30%7/23
A or B and C and D and E and F and G and H or I and J
A= &$token_contains("months_all")B= $advance{"md"}C= &all(sub { /^(?:day|month)$/; } , keys %modified)D= exists $self->{"modified"}{"month"}E= $self->{"modified"}{"month"} == 1F= exists $self->{"modified"}{"day"} ? $self->{"modified"}{"day"} == 1 ? &true() : &false() : &true()G= $self->{"Prefer_future"}H= $self->{"datetime"}->day_of_year < $now->day_of_yearI= $self->{"Demand_future"}J= $self->{"datetime"}->day_of_year <= $now->day_of_year
ABCDEFGHIJresult
00XXXXXXXX0
1X0XXXXXXX0
010XXXXXXX0
1X10XXXXXX0
1X110XXXXX0
0110XXXXXX0
01110XXXXX0
1X1110XXXX0
011110XXXX0
1X11110X0X0
1X11110X100
1X1111100X0
1X111110100
0111110X0X0
0111110X100
011111100X0
01111110100
1X111111XX1
1X11110X111
1X111110111
01111111XX1
0111110X111
01111110111
703 156 ▶ && (all { /^(?:day|month)$/ } keys %modified)
Subroutine __ANON__: called CC=1 SCAR=0.0
704 && (exists $self->{modified}{month} && $self->{modified}{month} == 1)
705 && (exists $self->{modified}{day}
706 ? $self->{modified}{day} == 1
707 ? true : false
708 : true)
709 && (($self->{Prefer_future} && $self->{datetime}->day_of_year < $now->day_of_year)
710 || ($self->{Demand_future} && $self->{datetime}->day_of_year <= $now->day_of_year))
711 ) {
712 72 $self->{postprocess}{year} = 1;
713 }
714 }
715  
716 sub _token
717 650740 ▶{
Subroutine _token: called CC=2 SCAR=7.0
718 650740 my $self = shift;
719 650740 my ($pos) = @_;
720  
721 650740 my $str = '';
722 650740 my $token = $self->{tokens}->[0 + $pos];
723  
724 650740 ▶ return defined $token
Branch: 1 branch
BranchTrueFalseTotal
defined $token ? : 650740 0 650740
725 ? \$token
726 : \$str;
727 }
728  
729 19923 ▶sub _register_trace { push @{$_[0]->{trace}}, (caller(1))[3] }
Subroutine _register_trace: called CC=1 SCAR=0.0
730 12007 ▶sub _unset_trace { @{$_[0]->{trace}} = () }
Subroutine _unset_trace: called CC=1 SCAR=0.0
731  
732 2652 ▶sub _get_error { $_[0]->{error} }
Subroutine _get_error: called CC=1 SCAR=0.0
733 372 ▶sub _set_error { $_[0]->{error} = $_[1] }
Subroutine _set_error: called CC=1 SCAR=0.0
734 12218 ▶sub _unset_error { $_[0]->{error} = undef }
Subroutine _unset_error: called CC=1 SCAR=0.0
735  
736 12840 ▶sub _get_failure { $_[0]->{failure} }
Subroutine _get_failure: called CC=1 SCAR=0.0
737 6 ▶sub _set_failure { $_[0]->{failure} = true }
Subroutine _set_failure: called CC=1 SCAR=0.0
738 12218 ▶sub _unset_failure { $_[0]->{failure} = false }
Subroutine _unset_failure: called CC=1 SCAR=0.0
739  
740 13203 ▶sub _get_valid_exp { $_[0]->{valid_expression} }
Subroutine _get_valid_exp: called CC=1 SCAR=0.0
741 12170 ▶sub _set_valid_exp { $_[0]->{valid_expression} = true }
Subroutine _set_valid_exp: called CC=1 SCAR=0.0
742 12540 ▶sub _unset_valid_exp { $_[0]->{valid_expression} = false }
Subroutine _unset_valid_exp: called CC=1 SCAR=0.0
743  
744 10980 ▶sub _get_truncated { $_[0]->{truncated} }
Subroutine _get_truncated: called CC=1 SCAR=0.0
745 12437 ▶sub _set_truncated { $_[0]->{truncated} = true }
Subroutine _set_truncated: called CC=1 SCAR=0.0
746 12328 ▶sub _unset_truncated { $_[0]->{truncated} = false }
Subroutine _unset_truncated: called CC=1 SCAR=0.0
747  
748 sub _get_datetime_object
749 12007 ▶{
Subroutine _get_datetime_object: called CC=2 SCAR=6.9
750 12007 my $self = shift;
751  
752 my $dt = DateTime->new(
753 time_zone => $self->{datetime}->time_zone,
754 year => $self->{datetime}->year,
755 month => $self->{datetime}->month,
756 day => $self->{datetime}->day_of_month,
757 hour => $self->{datetime}->hour,
758 minute => $self->{datetime}->minute,
759 second => $self->{datetime}->second,
760 nanosecond => $self->{datetime}->nanosecond,
761 12007 );
762  
763 12007 foreach my $unit (keys %{$self->{postprocess}}) {
764 1512 $dt->add("${unit}s" => $self->{postprocess}{$unit});
765 }
766  
767 12007 return $dt;
768 }
769  
770 # solely for testing purpose
771 sub _set_datetime
772 8088 ▶{
Subroutine _set_datetime: called CC=2 SCAR=6.9
773 8088 my $self = shift;
774 8088 my ($time, $tz) = @_;
775  
776 8088 ▶ $self->{datetime_test} = DateTime->new(
Condition100%2/2
$tz || 'floating'
l!l
15606528
MC/DC100%1/1
$tz || 'floating'
$tz
Truth table100%2/2
A
A= $tz
Aresult
11
00
777 time_zone => $tz || 'floating',
778 %$time,
779 );
780 8088 $self->{running_tests} = true;
781 }
782  
783 27 1;
784 __END__
« Natural/Extract.pm ↑ Summary Natural/Expand.pm »