line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Sah::Coerce::perl::date::str_alami_en; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-07-25'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.009'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
25813
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
450
|
use Data::Dmp; |
|
1
|
|
|
|
|
1743
|
|
|
1
|
|
|
|
|
273
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# TMP |
13
|
|
|
|
|
|
|
our $time_zone; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub meta { |
16
|
|
|
|
|
|
|
+{ |
17
|
4
|
|
|
4
|
0
|
529401
|
v => 4, |
18
|
|
|
|
|
|
|
might_fail => 1, |
19
|
|
|
|
|
|
|
prio => 60, # a bit lower than normal |
20
|
|
|
|
|
|
|
precludes => [qr/\Astr_alami(_.+)?\z/, 'str_natural', 'str_flexible'], |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub coerce { |
25
|
4
|
|
|
4
|
0
|
55
|
my %args = @_; |
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
|
|
9
|
my $dt = $args{data_term}; |
28
|
4
|
|
100
|
|
|
19
|
my $coerce_to = $args{coerce_to} // 'float(epoch)'; |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
10
|
my $res = {}; |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
14
|
$res->{expr_match} = "!ref($dt)"; |
33
|
4
|
|
50
|
|
|
30
|
$res->{modules}{"DateTime::Format::Alami::EN"} //= 0; |
34
|
4
|
50
|
|
|
|
22
|
$res->{expr_coerce} = join( |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
35
|
|
|
|
|
|
|
"", |
36
|
|
|
|
|
|
|
"do { my \$datetime; eval { \$datetime = DateTime::Format::Alami::EN->new->parse_datetime($dt, {_time_zone => ".dmp($time_zone)."}) }; my \$err = \$@; ", |
37
|
|
|
|
|
|
|
($coerce_to eq 'float(epoch)' ? "if (\$err) { \$err =~ s/ at .+//s; [\$err] } else { [undef, \$datetime->epoch ] } " : |
38
|
|
|
|
|
|
|
$coerce_to eq 'Time::Moment' ? "if (\$err) { \$err =~ s/ at .+//s; [\$err] } else { [undef, Time::Moment->from_object(\$datetime) ] } " : |
39
|
|
|
|
|
|
|
$coerce_to eq 'DateTime' ? "if (\$err) { \$err =~ s/ at .+//s; [\$err] } else { [undef, \$datetime] } " : |
40
|
|
|
|
|
|
|
(die "BUG: Unknown coerce_to '$coerce_to'")), |
41
|
|
|
|
|
|
|
"}", |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
147
|
$res; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
# ABSTRACT: Coerce date from string parsed by DateTime::Format::Alami::EN |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=pod |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=encoding UTF-8 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Data::Sah::Coerce::perl::date::str_alami_en - Coerce date from string parsed by DateTime::Format::Alami::EN |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 VERSION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This document describes version 0.009 of Data::Sah::Coerce::perl::date::str_alami_en (from Perl distribution Data-Sah-Coerce-perl-date-str_alami_en), released on 2019-07-25. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The rule is not enabled by default. You can enable it in a schema using e.g.: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
["date", "x.perl.coerce_rules"=>["str_alami_en"]] |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=for Pod::Coverage ^(meta|coerce)$ |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 HOMEPAGE |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Data-Sah-Coerce-perl-date-str_alami_en>. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SOURCE |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Data-Sah-Coerce-perl-date-str_alami_en>. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 BUGS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah-Coerce-perl-date-str_alami_en> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
85
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
86
|
|
|
|
|
|
|
feature. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This software is copyright (c) 2019, 2018, 2016 by perlancar@cpan.org. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
97
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |