line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Sah::Coerce::perl::To_date::From_obj::time_moment; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1025
|
use 5.010001; |
|
4
|
|
|
|
|
16
|
|
4
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
83
|
|
5
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1315
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
8
|
|
|
|
|
|
|
our $DATE = '2021-11-28'; # DATE |
9
|
|
|
|
|
|
|
our $DIST = 'Data-Sah-Coerce'; # DIST |
10
|
|
|
|
|
|
|
our $VERSION = '0.052'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub meta { |
13
|
|
|
|
|
|
|
+{ |
14
|
15
|
|
|
15
|
0
|
67
|
v => 4, |
15
|
|
|
|
|
|
|
summary => 'Coerce date from Time::Moment object', |
16
|
|
|
|
|
|
|
prio => 50, |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub coerce { |
21
|
15
|
|
|
15
|
0
|
56
|
my %args = @_; |
22
|
|
|
|
|
|
|
|
23
|
15
|
|
|
|
|
40
|
my $dt = $args{data_term}; |
24
|
15
|
|
50
|
|
|
46
|
my $coerce_to = $args{coerce_to} // 'float(epoch)'; |
25
|
|
|
|
|
|
|
|
26
|
15
|
|
|
|
|
33
|
my $res = {}; |
27
|
|
|
|
|
|
|
|
28
|
15
|
|
50
|
|
|
87
|
$res->{modules}{'Scalar::Util'} //= 0; |
29
|
|
|
|
|
|
|
|
30
|
15
|
|
|
|
|
66
|
$res->{expr_match} = join( |
31
|
|
|
|
|
|
|
" && ", |
32
|
|
|
|
|
|
|
"Scalar::Util::blessed($dt)", |
33
|
|
|
|
|
|
|
"$dt\->isa('Time::Moment')", |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
15
|
100
|
|
|
|
65
|
if ($coerce_to eq 'float(epoch)') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
37
|
8
|
|
|
|
|
18
|
$res->{expr_coerce} = "$dt\->epoch"; |
38
|
|
|
|
|
|
|
} elsif ($coerce_to eq 'DateTime') { |
39
|
4
|
|
50
|
|
|
37
|
$res->{modules}{'DateTime'} //= 0; |
40
|
4
|
|
|
|
|
45
|
$res->{expr_coerce} = "DateTime->from_epoch(epoch => $dt\->epoch, time_zone => sprintf('%s%04d', $dt\->offset >= 0 ? '+':'-', abs(int($dt\->offset / 60)*100) + abs(int($dt\->offset % 60))))"; |
41
|
|
|
|
|
|
|
} elsif ($coerce_to eq 'Time::Moment') { |
42
|
3
|
|
|
|
|
9
|
$res->{expr_coerce} = $dt; |
43
|
|
|
|
|
|
|
} else { |
44
|
0
|
|
|
|
|
0
|
die "BUG: Unknown coerce_to value '$coerce_to', ". |
45
|
|
|
|
|
|
|
"please use float(epoch), DateTime, or Time::Moment"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
15
|
|
|
|
|
48
|
$res; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
# ABSTRACT: Coerce date from Time::Moment object |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=pod |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=encoding UTF-8 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 NAME |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Data::Sah::Coerce::perl::To_date::From_obj::time_moment - Coerce date from Time::Moment object |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 VERSION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This document describes version 0.052 of Data::Sah::Coerce::perl::To_date::From_obj::time_moment (from Perl distribution Data-Sah-Coerce), released on 2021-11-28. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
To use in a Sah schema: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
["date",{"x.perl.coerce_rules"=>["From_obj::time_moment"]}] |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This rule coerces date from a L<Time::Moment> object. If C<coerce_to> is |
77
|
|
|
|
|
|
|
"Time::Moment" that this rule does not do anything. Otherwise, it converts the |
78
|
|
|
|
|
|
|
Time::Moment object to epoch (if C<coerce_to>="float(epoch)") or L<DateTime> |
79
|
|
|
|
|
|
|
object (if C<coerce_to>="DateTime"). |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=for Pod::Coverage ^(meta|coerce)$ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 HOMEPAGE |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Data-Sah-Coerce>. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SOURCE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Data-Sah-Coerce>. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 CONTRIBUTING |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
To contribute, you can send patches by email/via RT, or send pull requests on |
99
|
|
|
|
|
|
|
GitHub. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Most of the time, you don't need to build the distribution yourself. You can |
102
|
|
|
|
|
|
|
simply modify the code, then test via: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
% prove -l |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
If you want to build the distribution (e.g. to try to install it locally on your |
107
|
|
|
|
|
|
|
system), you can install L<Dist::Zilla>, |
108
|
|
|
|
|
|
|
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>, and sometimes one or two other |
109
|
|
|
|
|
|
|
Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required |
110
|
|
|
|
|
|
|
beyond that are considered a bug and can be reported to me. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This software is copyright (c) 2021, 2020, 2019, 2018, 2017, 2016 by perlancar <perlancar@cpan.org>. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
117
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 BUGS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah-Coerce> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
124
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
125
|
|
|
|
|
|
|
feature. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |