File Coverage

blib/lib/Data/Sah/Coerce/perl/To_timeofday/From_obj/date_timeofday.pm
Criterion Covered Total %
statement 19 21 90.4
branch 3 6 50.0
condition 2 4 50.0
subroutine 5 5 100.0
pod 0 2 0.0
total 29 38 76.3


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