| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package SortKey::date_in_text; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
417620
|
use 5.010001; |
|
|
1
|
|
|
|
|
4
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
72
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1838
|
use DateTime; |
|
|
1
|
|
|
|
|
792502
|
|
|
|
1
|
|
|
|
|
753
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $DATE_EXTRACT_MODULE = $ENV{PERL_DATE_EXTRACT_MODULE} // "Date::Extract"; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
12
|
|
|
|
|
|
|
our $DATE = '2024-05-15'; # DATE |
|
13
|
|
|
|
|
|
|
our $DIST = 'SortKey-date_in_text'; # DIST |
|
14
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub meta { |
|
17
|
|
|
|
|
|
|
return { |
|
18
|
0
|
|
|
0
|
0
|
|
v => 1, |
|
19
|
|
|
|
|
|
|
args => { |
|
20
|
|
|
|
|
|
|
}, |
|
21
|
|
|
|
|
|
|
}; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $re_is_num = qr/\A |
|
25
|
|
|
|
|
|
|
[+-]? |
|
26
|
|
|
|
|
|
|
(?:\d+|\d*(?:\.\d*)?) |
|
27
|
|
|
|
|
|
|
(?:[Ee][+-]?\d+)? |
|
28
|
|
|
|
|
|
|
\z/x; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub gen_keygen { |
|
31
|
0
|
|
|
0
|
0
|
|
my ($is_reverse, $is_ci) = @_; |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my ($parser, $code_parse); |
|
34
|
0
|
0
|
|
|
|
|
unless (defined $parser) { |
|
35
|
0
|
|
|
|
|
|
my $module = $DATE_EXTRACT_MODULE; |
|
36
|
0
|
0
|
|
|
|
|
$module = "Date::Extract::$module" unless $module =~ /::/; |
|
37
|
0
|
0
|
|
|
|
|
if ($module eq 'Date::Extract') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
require Date::Extract; |
|
39
|
0
|
|
|
|
|
|
$parser = Date::Extract->new(); |
|
40
|
0
|
|
|
0
|
|
|
$code_parse = sub { $parser->extract($_[0]) }; |
|
|
0
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} elsif ($module eq 'Date::Extract::ID') { |
|
42
|
0
|
|
|
|
|
|
require Date::Extract::ID; |
|
43
|
0
|
|
|
|
|
|
$parser = Date::Extract::ID->new(); |
|
44
|
0
|
|
|
0
|
|
|
$code_parse = sub { $parser->extract($_[0]) }; |
|
|
0
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} elsif ($module eq 'DateTime::Format::Alami::EN') { |
|
46
|
0
|
|
|
|
|
|
require DateTime::Format::Alami::EN; |
|
47
|
0
|
|
|
|
|
|
$parser = DateTime::Format::Alami::EN->new(); |
|
48
|
0
|
|
|
0
|
|
|
$code_parse = sub { my $h; eval { $h = $parser->parse_datetime($_[0]) }; $h }; ## no critic: BuiltinFunctions::ProhibitStringyEval |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} elsif ($module eq 'DateTime::Format::Alami::ID') { |
|
50
|
0
|
|
|
|
|
|
require DateTime::Format::Alami::ID; |
|
51
|
0
|
|
|
|
|
|
$parser = DateTime::Format::Alami::ID->new(); |
|
52
|
0
|
|
|
0
|
|
|
$code_parse = sub { my $h; eval { $h = $parser->parse_datetime($_[0]) }; $h }; ## no critic: BuiltinFunctions::ProhibitStringyEval |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} else { |
|
54
|
0
|
|
|
|
|
|
die "Invalid date extract module '$module'"; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
0
|
0
|
|
|
|
|
eval "use $module"; die if $@; ## no critic: BuiltinFunctions::ProhibitStringyEval |
|
|
0
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub { |
|
60
|
1
|
|
|
1
|
|
13
|
no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
218
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
0
|
|
|
my $arg = @_ ? $_[0] : $_; |
|
63
|
0
|
|
|
|
|
|
my $dt = $code_parse->($arg); |
|
64
|
0
|
0
|
|
|
|
|
return '' unless $dt; |
|
65
|
0
|
|
|
|
|
|
"$dt"; |
|
66
|
0
|
|
|
|
|
|
}; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
|
70
|
|
|
|
|
|
|
# ABSTRACT: Date found in text as sort key |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=pod |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=encoding UTF-8 |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
SortKey::date_in_text - Date found in text as sort key |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This document describes version 0.002 of SortKey::date_in_text (from Perl distribution SortKey-date_in_text), released on 2024-05-15. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
The generated keygen will extract date found in text (by default extracted using |
|
89
|
|
|
|
|
|
|
L<Date::Extract>, but other modules can be used, see |
|
90
|
|
|
|
|
|
|
L</PERL_DATE_EXTRACT_MODULE>) and return the date in ISO 8601 format. Will |
|
91
|
|
|
|
|
|
|
return empty string if string is not found. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=for Pod::Coverage ^(gen_keygen|meta)$ |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 ENVIRONMENT |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 DEBUG => bool |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
If set to true, will print stuffs to stderr. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 PERL_DATE_EXTRACT_MODULE => str |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Can be set to L<Date::Extract>, L<Date::Extract::ID>, or |
|
104
|
|
|
|
|
|
|
L<DateTime::Format::Alami::EN>, L<DateTime::Format::Alami::ID>. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 HOMEPAGE |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/SortKey-date_in_text>. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SOURCE |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-SortKey-date_in_text>. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Old incarnation: L<Sort::Sub::by_date_in_text>. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L<Comparer> version: L<Comparer::by_date_in_text>. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 CONTRIBUTING |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
To contribute, you can send patches by email/via RT, or send pull requests on |
|
128
|
|
|
|
|
|
|
GitHub. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Most of the time, you don't need to build the distribution yourself. You can |
|
131
|
|
|
|
|
|
|
simply modify the code, then test via: |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
% prove -l |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
If you want to build the distribution (e.g. to try to install it locally on your |
|
136
|
|
|
|
|
|
|
system), you can install L<Dist::Zilla>, |
|
137
|
|
|
|
|
|
|
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>, |
|
138
|
|
|
|
|
|
|
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other |
|
139
|
|
|
|
|
|
|
Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond |
|
140
|
|
|
|
|
|
|
that are considered a bug and can be reported to me. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This software is copyright (c) 2024 by perlancar <perlancar@cpan.org>. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
147
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 BUGS |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=SortKey-date_in_text> |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
|
154
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
|
155
|
|
|
|
|
|
|
feature. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |