File Coverage

blib/lib/Data/Sah/Coerce/perl/num/str_num_en.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition 1 2 50.0
subroutine 5 5 100.0
pod 0 2 0.0
total 22 25 88.0


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