line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sort::Sub::date_in_text; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-04-06'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
931
|
use 5.010001; |
|
1
|
|
|
|
|
2
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
8
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
750
|
use DateTime; |
|
1
|
|
|
|
|
68199
|
|
|
1
|
|
|
|
|
182
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $DATE_EXTRACT_MODULE = $ENV{PERL_DATE_EXTRACT_MODULE} // "Date::Extract"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub gen_sorter { |
15
|
3
|
|
|
3
|
0
|
979
|
my ($is_reverse, $is_ci) = @_; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
9
|
my $re_is_num = qr/\A |
18
|
|
|
|
|
|
|
[+-]? |
19
|
|
|
|
|
|
|
(?:\d+|\d*(?:\.\d*)?) |
20
|
|
|
|
|
|
|
(?:[Ee][+-]?\d+)? |
21
|
|
|
|
|
|
|
\z/x; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
3
|
my $module = $DATE_EXTRACT_MODULE; |
24
|
3
|
50
|
|
|
|
11
|
$module = "Date::Extract::$module" unless $module =~ /::/; |
25
|
3
|
50
|
|
|
|
16
|
die "Invalid module '$module'" unless $module =~ /\A\w+(::\w+)*\z/; |
26
|
1
|
50
|
|
1
|
|
412
|
eval "use $module"; die if $@; |
|
1
|
|
|
1
|
|
39292
|
|
|
1
|
|
|
1
|
|
16
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
197
|
|
|
3
|
|
|
|
|
11
|
|
27
|
3
|
|
|
|
|
11
|
my $parser = $module->new; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub { |
30
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
169
|
|
31
|
|
|
|
|
|
|
|
32
|
21
|
|
|
21
|
|
147
|
my $caller = caller(); |
33
|
21
|
50
|
|
|
|
38
|
my $a = @_ ? $_[0] : ${"$caller\::a"}; |
|
21
|
|
|
|
|
56
|
|
34
|
21
|
50
|
|
|
|
29
|
my $b = @_ ? $_[1] : ${"$caller\::b"}; |
|
21
|
|
|
|
|
31
|
|
35
|
|
|
|
|
|
|
|
36
|
21
|
|
|
|
|
15
|
my $cmp; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# XXX cache |
39
|
|
|
|
|
|
|
|
40
|
21
|
|
|
|
|
47
|
my $dt_a = $parser->extract($a); |
41
|
21
|
|
|
|
|
136847
|
my $dt_b = $parser->extract($b); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
{ |
44
|
21
|
100
|
100
|
|
|
154542
|
if ($dt_a && $dt_b) { |
|
21
|
100
|
66
|
|
|
97
|
|
|
|
50
|
33
|
|
|
|
|
45
|
12
|
|
|
|
|
684
|
$cmp = DateTime->compare($dt_a, $dt_b); |
46
|
12
|
100
|
|
|
|
567
|
last if $cmp; |
47
|
|
|
|
|
|
|
} elsif ($dt_a && !$dt_b) { |
48
|
2
|
|
|
|
|
102
|
$cmp = -1; |
49
|
2
|
|
|
|
|
4
|
last; |
50
|
|
|
|
|
|
|
} elsif (!$dt_a && $dt_b) { |
51
|
7
|
|
|
|
|
262
|
$cmp = 1; |
52
|
7
|
|
|
|
|
10
|
last; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
3
|
100
|
|
|
|
10
|
if ($is_ci) { |
56
|
2
|
|
|
|
|
7
|
$cmp = lc($a) cmp lc($b); |
57
|
|
|
|
|
|
|
} else { |
58
|
1
|
|
|
|
|
2
|
$cmp = $a cmp $b; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
21
|
100
|
|
|
|
174
|
$is_reverse ? -1*$cmp : $cmp; |
63
|
3
|
|
|
|
|
54
|
}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
# ABSTRACT: Sort by date found in text or (if no date is found) ascibetically |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |