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