File Coverage

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