|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package DateTime::Format::Natural::Extract;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
26
 | 
 
 | 
 
 | 
  
26
  
 | 
 
 | 
240
 | 
 use strict;  | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
86
 | 
    | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
773
 | 
    | 
| 
4
 | 
26
 | 
 
 | 
 
 | 
  
26
  
 | 
 
 | 
145
 | 
 use warnings;  | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
63
 | 
    | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
782
 | 
    | 
| 
5
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13070
 | 
 use base qw(  | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     DateTime::Format::Natural::Duration::Checks  | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     DateTime::Format::Natural::Formatted  | 
| 
8
 | 
26
 | 
 
 | 
 
 | 
  
26
  
 | 
 
 | 
146
 | 
 );  | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
54
 | 
    | 
| 
9
 | 
26
 | 
 
 | 
 
 | 
  
26
  
 | 
 
 | 
222
 | 
 use boolean qw(true false);  | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
63
 | 
    | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
132
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
26
 | 
 
 | 
 
 | 
  
26
  
 | 
 
 | 
1622
 | 
 use constant DATE_TYPE     => 0x01;  | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
72
 | 
    | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1396
 | 
    | 
| 
12
 | 
26
 | 
 
 | 
 
 | 
  
26
  
 | 
 
 | 
178
 | 
 use constant GRAMMAR_TYPE  => 0x02;  | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
78
 | 
    | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1328
 | 
    | 
| 
13
 | 
26
 | 
 
 | 
 
 | 
  
26
  
 | 
 
 | 
176
 | 
 use constant DURATION_TYPE => 0x04;  | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
73
 | 
    | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1429
 | 
    | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
15
 | 
26
 | 
 
 | 
 
 | 
  
26
  
 | 
 
 | 
202
 | 
 use DateTime::Format::Natural::Utils qw(trim);  | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
84
 | 
    | 
| 
 
 | 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
57900
 | 
    | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.13';  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my %grammar_durations = map { $_ => true } qw(for_count_unit);  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my $get_range = sub  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my ($aref, $index) = @_;  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     return [ grep defined, @$aref[$index, $index + 1] ];  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 };  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my $extract_duration = sub  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my ($skip, $indexes, $index) = @_;  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     return false unless defined $indexes->[$index] && defined $indexes->[$index + 1];  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my ($left_index, $right_index) = ($indexes->[$index][1], $indexes->[$index + 1][0]);  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     return ($skip->{$left_index} || $skip->{$right_index}) ? false : true;  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 };  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _extract_expressions  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
39
 | 
209
 | 
 
 | 
 
 | 
  
209
  
 | 
 
 | 
476
 | 
     my $self = shift;  | 
| 
40
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
463
 | 
     my ($extract_string) = @_;  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
42
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
582
 | 
     $extract_string =~ s/^[,;.]//;  | 
| 
43
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
699
 | 
     $extract_string =~ s/[,;.]$//;  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
45
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1042
 | 
     while ($extract_string =~ /([,;.])/g) {  | 
| 
46
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
79
 | 
         my $mark = $1;  | 
| 
47
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
222
 | 
         my %patterns = (  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             ',' => qr/(?!\d{4})/,  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             ';' => qr/(?=\w)/,  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             '.' => qr/(?=\w)/,  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         );  | 
| 
52
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
59
 | 
         my $pattern = $patterns{$mark};  | 
| 
53
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
392
 | 
         $extract_string =~ s/\Q$mark\E \s+? $pattern/ [token] /x; # pretend punctuation marks are tokens  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
56
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1641
 | 
     my $timespan_sep = $self->{data}->__timespan('literal');  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
58
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1978
 | 
     1 while $extract_string =~ s/^$timespan_sep\s+//i;  | 
| 
59
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1471
 | 
     1 while $extract_string =~ s/\s+$timespan_sep$//i;  | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
61
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1079
 | 
     $self->_rewrite(\$extract_string);  | 
| 
62
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
63
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2119
 | 
     my @tokens = split /\s+/, $extract_string;  | 
| 
64
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
472
 | 
     my %entries = %{$self->{data}->__grammar('')};  | 
| 
 
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1417
 | 
    | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
66
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1246
 | 
     my (@expressions, %skip);  | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
68
 | 
209
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1513
 | 
     if ($extract_string =~ /\s+ $timespan_sep \s+/ix) {  | 
| 
69
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
591
 | 
         $self->_extract_duration($extract_string, \@tokens, \@expressions, \%skip);  | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
72
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2407
 | 
     my (%expand, %lengths);  | 
| 
73
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2074
 | 
     foreach my $keyword (keys %entries) {  | 
| 
74
 | 
14003
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27648
 | 
         $expand{$keyword}  = $self->_expand_for($keyword);  | 
| 
75
 | 
14003
 | 
 
 | 
 
 | 
 
 | 
 
 | 
44136
 | 
         $lengths{$keyword} = @{$entries{$keyword}->[0]};  | 
| 
 
 | 
14003
 | 
 
 | 
 
 | 
 
 | 
 
 | 
28788
 | 
    | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
78
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1025
 | 
     my $seen_expression;  | 
| 
79
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
480
 | 
     do {  | 
| 
80
 | 
439
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3533
 | 
         $seen_expression = false;  | 
| 
81
 | 
439
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1604
 | 
         my $date_index;  | 
| 
82
 | 
439
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2207
 | 
         for (my $i = 0; $i < @tokens; $i++) {  | 
| 
83
 | 
1844
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
16962
 | 
             next if $skip{$i};  | 
| 
84
 | 
1085
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
3664
 | 
             if ($self->_check_for_date($tokens[$i], $i, \$date_index)) {  | 
| 
85
 | 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
257
 | 
                 last;  | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         GRAMMAR:  | 
| 
89
 | 
439
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9596
 | 
         foreach my $keyword (sort { $lengths{$b} <=> $lengths{$a} } grep { $lengths{$_} <= @tokens } keys %entries) {  | 
| 
 
 | 
97957
 | 
 
 | 
 
 | 
 
 | 
 
 | 
139673
 | 
    | 
| 
 
 | 
29413
 | 
 
 | 
 
 | 
 
 | 
 
 | 
55686
 | 
    | 
| 
90
 | 
19339
 | 
 
 | 
 
 | 
 
 | 
 
 | 
389342
 | 
             my @grammar = @{$entries{$keyword}};  | 
| 
 
 | 
19339
 | 
 
 | 
 
 | 
 
 | 
 
 | 
107314
 | 
    | 
| 
91
 | 
19339
 | 
 
 | 
 
 | 
 
 | 
 
 | 
33116
 | 
             my $types_entry = shift @grammar;  | 
| 
92
 | 
19339
 | 
 
 | 
 
 | 
 
 | 
 
 | 
56217
 | 
             my @grammars = [ [ @grammar ], false ];  | 
| 
93
 | 
19339
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
86770
 | 
             if ($expand{$keyword} && @$types_entry + 1 <= @tokens) {  | 
| 
94
 | 
4457
 | 
 
 | 
 
 | 
 
 | 
 
 | 
52024
 | 
                 @grammar = $self->_expand($keyword, $types_entry, \@grammar);  | 
| 
95
 | 
4457
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20705
 | 
                 unshift @grammars, [ [ @grammar ], true ];  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
97
 | 
19339
 | 
 
 | 
 
 | 
 
 | 
 
 | 
133329
 | 
             foreach my $grammar (@grammars) {  | 
| 
98
 | 
23793
 | 
 
 | 
 
 | 
 
 | 
 
 | 
70711
 | 
                 my $expanded = $grammar->[1];  | 
| 
99
 | 
23793
 | 
 
 | 
 
 | 
 
 | 
 
 | 
44012
 | 
                 my $length = $lengths{$keyword};  | 
| 
100
 | 
23793
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
52361
 | 
                    $length++ if $expanded;  | 
| 
101
 | 
23793
 | 
 
 | 
 
 | 
 
 | 
 
 | 
158635
 | 
                 foreach my $entry (@{$grammar->[0]}) {  | 
| 
 
 | 
23793
 | 
 
 | 
 
 | 
 
 | 
 
 | 
47497
 | 
    | 
| 
102
 | 
150791
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1054289
 | 
                     my ($types, $expression) = $expanded ? @$entry : ($types_entry, $entry);  | 
| 
103
 | 
150791
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1161468
 | 
                     my $definition = $expression->[0];  | 
| 
104
 | 
150791
 | 
 
 | 
 
 | 
 
 | 
 
 | 
276991
 | 
                     my $matched = false;  | 
| 
105
 | 
150791
 | 
 
 | 
 
 | 
 
 | 
 
 | 
439405
 | 
                     my $pos = 0;  | 
| 
106
 | 
150791
 | 
 
 | 
 
 | 
 
 | 
 
 | 
224303
 | 
                     my @indexes;  | 
| 
107
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     my $date_index;  | 
| 
108
 | 
150791
 | 
 
 | 
 
 | 
 
 | 
 
 | 
333381
 | 
                     for (my $i = 0; $i < @tokens; $i++) {  | 
| 
109
 | 
844021
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
5994412
 | 
                         next if $skip{$i};  | 
| 
110
 | 
493242
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1012454
 | 
                         last unless defined $types->[$pos];  | 
| 
111
 | 
493150
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1124097
 | 
                         if ($self->_check_for_date($tokens[$i], $i, \$date_index)) {  | 
| 
112
 | 
9875
 | 
 
 | 
 
 | 
 
 | 
 
 | 
120150
 | 
                             next;  | 
| 
113
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         }  | 
| 
114
 | 
483275
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
8700584
 | 
                         if ($types->[$pos] eq 'SCALAR' && defined $definition->{$pos} && $tokens[$i] =~ /^$definition->{$pos}$/i  | 
| 
 
 | 
 
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
115
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                          or $types->[$pos] eq 'REGEXP'                                && $tokens[$i] =~   $definition->{$pos}  | 
| 
116
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         && (@indexes ? ($i - $indexes[-1] == 1) : true)  | 
| 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         ) {  | 
| 
118
 | 
8046
 | 
 
 | 
 
 | 
 
 | 
 
 | 
97335
 | 
                             $matched = true;  | 
| 
119
 | 
8046
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27913
 | 
                             push @indexes, $i;  | 
| 
120
 | 
8046
 | 
 
 | 
 
 | 
 
 | 
 
 | 
22852
 | 
                             $pos++;  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         }  | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         elsif ($matched) {  | 
| 
123
 | 
5391
 | 
 
 | 
 
 | 
 
 | 
 
 | 
40020
 | 
                             last;  | 
| 
124
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         }  | 
| 
125
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     }  | 
| 
126
 | 
150791
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
1199713
 | 
                     if ($matched  | 
| 
 
 | 
 
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
127
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                      && @indexes == $length  | 
| 
128
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                      && (defined $date_index ? ($indexes[0] - $date_index == 1) : true)  | 
| 
129
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     ) {  | 
| 
130
 | 
223
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
6466
 | 
                         my $expression = join ' ', (defined $date_index ? $tokens[$date_index] : (), @tokens[@indexes]);  | 
| 
131
 | 
223
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
956
 | 
                         my $start_index = defined $date_index ? $indexes[0] - 1 : $indexes[0];  | 
| 
132
 | 
223
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
778
 | 
                         my $type = $grammar_durations{$keyword} ? DURATION_TYPE : GRAMMAR_TYPE;  | 
| 
133
 | 
223
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1326
 | 
                         push @expressions, [ [ $start_index, $indexes[-1] ], $expression, { flags => $type } ];  | 
| 
134
 | 
223
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1273
 | 
                         $skip{$_} = true foreach (defined $date_index ? $date_index : (), @indexes);  | 
| 
135
 | 
223
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1710
 | 
                         $seen_expression = true;  | 
| 
136
 | 
223
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2011
 | 
                         last GRAMMAR;  | 
| 
137
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     }  | 
| 
138
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 }  | 
| 
139
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
140
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
141
 | 
439
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
8580
 | 
         if (defined $date_index && !$seen_expression) {  | 
| 
142
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
180
 | 
             push @expressions, [ [ ($date_index) x 2 ], $tokens[$date_index], { flags => DATE_TYPE } ];  | 
| 
143
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27
 | 
             $skip{$date_index} = true;  | 
| 
144
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
48
 | 
             $seen_expression = true;  | 
| 
145
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
146
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } while ($seen_expression);  | 
| 
147
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
148
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2890
 | 
     return $self->_finalize_expressions(\@expressions, \@tokens);  | 
| 
149
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
150
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
151
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _extract_duration  | 
| 
152
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
153
 | 
97
 | 
 
 | 
 
 | 
  
97
  
 | 
 
 | 
304
 | 
     my $self = shift;  | 
| 
154
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
367
 | 
     my ($extract_string, $tokens, $expressions, $skip) = @_;  | 
| 
155
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
156
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
787
 | 
     my $timespan_sep = $self->{data}->__timespan('literal');  | 
| 
157
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
158
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1636
 | 
     my @strings = grep /\S/, map trim($_), split /\b $timespan_sep \b/ix, $extract_string;  | 
| 
159
 | 
97
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
615
 | 
     if (@strings) {  | 
| 
160
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
274
 | 
         my $index = 0;  | 
| 
161
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
232
 | 
         my @indexes;  | 
| 
162
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
395
 | 
         foreach my $string (@strings) {  | 
| 
163
 | 
208
 | 
 
 | 
 
 | 
 
 | 
 
 | 
805
 | 
             my @string_tokens = split /\s+/, $string;  | 
| 
164
 | 
208
 | 
 
 | 
 
 | 
 
 | 
 
 | 
632
 | 
             push @indexes, [ $index, $index + $#string_tokens ];  | 
| 
165
 | 
208
 | 
 
 | 
 
 | 
 
 | 
 
 | 
433
 | 
             $index += $#string_tokens + 1;  | 
| 
166
 | 
208
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
1953
 | 
             $index++ while defined $tokens->[$index] && $tokens->[$index] =~ /^$timespan_sep$/i;  | 
| 
167
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
168
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         DURATION: {  | 
| 
169
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
276
 | 
             for (my $i = 0; $i <= $#strings - 1; $i++) {  | 
| 
 
 | 
160
 | 
 
 | 
 
 | 
 
 | 
 
 | 
842
 | 
    | 
| 
170
 | 
179
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
808
 | 
                 next unless $extract_duration->($skip, \@indexes, $i);  | 
| 
171
 | 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1550
 | 
                 my $save_expression = false;  | 
| 
172
 | 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
428
 | 
                 my @chunks;  | 
| 
173
 | 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
354
 | 
                 foreach my $extract (qw(_first_to_last_extract _from_count_to_count_extract)) {  | 
| 
174
 | 
206
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
2229
 | 
                     if ($self->$extract($get_range->(\@strings, $i), $get_range->(\@indexes, $i), $tokens, \@chunks)) {  | 
| 
175
 | 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1491
 | 
                         $save_expression = true;  | 
| 
176
 | 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
274
 | 
                         last;  | 
| 
177
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     }  | 
| 
178
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 }  | 
| 
179
 | 
111
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1644
 | 
                 if ($save_expression) {  | 
| 
180
 | 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
665
 | 
                     my $timespan_sep_index = $chunks[0]->[0][1] + 1;  | 
| 
181
 | 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
338
 | 
                     my $expression = join ' ', ($chunks[0]->[1], $tokens->[$timespan_sep_index], $chunks[1]->[1]);  | 
| 
182
 | 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
203
 | 
                     my @indexes = ($chunks[0]->[0][0], $chunks[1]->[0][1]);  | 
| 
183
 | 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
322
 | 
                     push @$expressions, [ [ @indexes ], $expression, { flags => DURATION_TYPE } ];  | 
| 
184
 | 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
305
 | 
                     $skip->{$_} = true foreach ($indexes[0] .. $indexes[1]);  | 
| 
185
 | 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1044
 | 
                     redo DURATION;  | 
| 
186
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 }  | 
| 
187
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
188
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
189
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
190
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
191
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
192
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _finalize_expressions  | 
| 
193
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
194
 | 
209
 | 
 
 | 
 
 | 
  
209
  
 | 
 
 | 
565
 | 
     my $self = shift;  | 
| 
195
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
621
 | 
     my ($expressions, $tokens) = @_;  | 
| 
196
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
197
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1694
 | 
     my $timespan_sep = $self->{data}->__timespan('literal');  | 
| 
198
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
641
 | 
     my (@duration_indexes, @final_expressions);  | 
| 
199
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
200
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
814
 | 
     my $seen_duration = false;  | 
| 
201
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
202
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1519
 | 
     my @expressions = sort { $a->[0][0] <=> $b->[0][0] } @$expressions;  | 
| 
 
 | 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
585
 | 
    | 
| 
203
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
204
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1111
 | 
     for (my $i = 0; $i < @expressions; $i++) {  | 
| 
205
 | 
293
 | 
 
 | 
 
 | 
 
 | 
 
 | 
930
 | 
         my $expression = $expressions[$i];  | 
| 
206
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
207
 | 
293
 | 
 
 | 
 
 | 
 
 | 
 
 | 
818
 | 
         my $prev = $expression->[0][0] - 1;  | 
| 
208
 | 
293
 | 
 
 | 
 
 | 
 
 | 
 
 | 
635
 | 
         my $next = $expression->[0][1] + 1;  | 
| 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
210
 | 
293
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
2129
 | 
         if ($expression->[2]->{flags} & DATE_TYPE  | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
211
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
          || $expression->[2]->{flags} & GRAMMAR_TYPE  | 
| 
212
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         ) {  | 
| 
213
 | 
224
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
743
 | 
             if (!$seen_duration  | 
| 
 
 | 
 
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
214
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
              && defined $tokens->[$next]  | 
| 
215
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
              &&         $tokens->[$next] =~ /^$timespan_sep$/i  | 
| 
216
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
              && defined $expressions[$i + 1]  | 
| 
217
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
              &&        ($expressions[$i + 1]->[2]->{flags} & DATE_TYPE  | 
| 
218
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                      || $expressions[$i + 1]->[2]->{flags} & GRAMMAR_TYPE)  | 
| 
219
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
              &&         $expressions[$i + 1]->[0][0] - $next == 1  | 
| 
220
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             ) {  | 
| 
221
 | 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1338
 | 
                 push @duration_indexes, ($expression->[0][0] .. $expression->[0][1]);  | 
| 
222
 | 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
126
 | 
                 $seen_duration = true;  | 
| 
223
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
224
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             elsif ($seen_duration) {  | 
| 
225
 | 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
776
 | 
                 push @duration_indexes, ($prev, $expression->[0][0] .. $expression->[0][1]);  | 
| 
226
 | 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
246
 | 
                 push @final_expressions, join ' ', @$tokens[@duration_indexes];  | 
| 
227
 | 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
87
 | 
                 @duration_indexes = ();  | 
| 
228
 | 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
124
 | 
                 $seen_duration = false;  | 
| 
229
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
230
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             else {  | 
| 
231
 | 
162
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4741
 | 
                 push @final_expressions, $expression->[1];  | 
| 
232
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
233
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
234
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         elsif ($expression->[2]->{flags} & DURATION_TYPE) {  | 
| 
235
 | 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
328
 | 
             push @final_expressions, $expression->[1];  | 
| 
236
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
237
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
238
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
239
 | 
209
 | 
 
 | 
 
 | 
  
262
  
 | 
 
 | 
1421
 | 
     my $exclude = sub { $_[0] =~ /^\d{1,2}$/ };  | 
| 
 
 | 
262
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8182
 | 
    | 
| 
240
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
241
 | 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
851
 | 
     return grep !$exclude->($_), @final_expressions;  | 
| 
242
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
243
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
244
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _check_for_date  | 
| 
245
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 {  | 
| 
246
 | 
494235
 | 
 
 | 
 
 | 
  
494235
  
 | 
 
 | 
775290
 | 
     my $self = shift;  | 
| 
247
 | 
494235
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1050800
 | 
     my ($token, $index, $date_index) = @_;  | 
| 
248
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
249
 | 
494235
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2337357
 | 
     my ($formatted) = $token =~ $self->{data}->__regexes('format');  | 
| 
250
 | 
494235
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1509903
 | 
     my %count = $self->_count_separators($formatted);  | 
| 
251
 | 
494235
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1203057
 | 
     if ($self->_check_formatted('ymd', \%count)) {  | 
| 
252
 | 
9891
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20099
 | 
         $$date_index = $index;  | 
| 
253
 | 
9891
 | 
 
 | 
 
 | 
 
 | 
 
 | 
26242
 | 
         return true;  | 
| 
254
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
255
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     else {  | 
| 
256
 | 
484344
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1252282
 | 
         return false;  | 
| 
257
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
258
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
259
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
260
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
261
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  | 
| 
262
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
263
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 NAME  | 
| 
264
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
265
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 DateTime::Format::Natural::Extract - Extract parsable expressions from strings  | 
| 
266
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
267
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 SYNOPSIS  | 
| 
268
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
269
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  Please see the DateTime::Format::Natural documentation.  | 
| 
270
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
271
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 DESCRIPTION  | 
| 
272
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
273
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 C<DateTime::Format::Natural::Extract> extracts expressions from strings to be  | 
| 
274
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 processed by the parse methods.  | 
| 
275
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
276
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 SEE ALSO  | 
| 
277
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
278
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 L<DateTime::Format::Natural>  | 
| 
279
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
280
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 AUTHOR  | 
| 
281
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
282
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Steven Schubiger <schubiger@cpan.org>  | 
| 
283
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
284
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 LICENSE  | 
| 
285
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
286
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 This program is free software; you may redistribute it and/or  | 
| 
287
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 modify it under the same terms as Perl itself.  | 
| 
288
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
289
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 See L<http://dev.perl.org/licenses/>  | 
| 
290
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
291
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  |