File Coverage

blib/lib/Data/Sah/Compiler/perl/TH/float.pm
Criterion Covered Total %
statement 69 81 85.1
branch 34 50 68.0
condition 27 39 69.2
subroutine 10 10 100.0
pod 0 5 0.0
total 140 185 75.6


line stmt bran cond sub pod time code
1              
2             use 5.010;
3 3     3   486 use strict;
  3         9  
4 3     3   13 use warnings;
  3         4  
  3         63  
5 3     3   14 #use Log::Any '$log';
  3         5  
  3         80  
6              
7             use Mo qw(build default);
8 3     3   13 use Role::Tiny::With;
  3         6  
  3         14  
9 3     3   738  
  3         12  
  3         3431  
10             extends 'Data::Sah::Compiler::perl::TH::num';
11             with 'Data::Sah::Type::float';
12              
13             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
14             our $DATE = '2022-10-19'; # DATE
15             our $DIST = 'Data-Sah'; # DIST
16             our $VERSION = '0.914'; # VERSION
17              
18             my ($self, $cd) = @_;
19             my $c = $self->compiler;
20 666     666 0 1335  
21 666         2136 my $dt = $cd->{data_term};
22             if ($cd->{args}{core} || $cd->{args}{no_modules}) {
23 666         3165 $cd->{_ccl_check_type} = "$dt =~ ".'/\A(?:[+-]?(?:0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?|((?i)\s*nan\s*)|((?i)\s*[+-]?inf(inity)?)\s*)\z/';
24 666 100 100     3067 } else {
25 60         194 $c->add_sun_module($cd);
26             # we use isnum = isint + isfloat, because isfloat(3) is false
27 606         2107 $cd->{_ccl_check_type} = "$cd->{_sun_module}::isnum($dt)";
28             }
29 606         2705 }
30              
31             my ($self, $cd) = @_;
32             my $c = $self->compiler;
33             my $ct = $cd->{cl_term};
34 19     19 0 50 my $dt = $cd->{data_term};
35 19         56  
36 19         83 if ($cd->{cl_is_expr}) {
37 19         34 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
38             $c->add_ccl(
39 19 50       46 $cd,
40 0 0 0     0 qq[$ct ? lc($dt+0) eq "nan" : defined($ct) ? lc($dt+0) ne "nan" : 1],
41 0         0 );
42             } else {
43             $c->add_ccl(
44             $cd,
45             join(
46 0         0 "",
47             "$ct ? $cd->{_sun_module}::isnan($dt) : ",
48             "defined($ct) ? !$cd->{_sun_module}::isnan($dt) : 1",
49             )
50             );
51             }
52             } else {
53             if ($cd->{cl_value}) {
54             if ($cd->{args}{core} || $cd->{args}{no_modules}) {
55             $c->add_ccl($cd, qq[lc($dt+0) eq "nan"]);
56 19 100       54 } else {
    50          
57 11 100 100     49 $c->add_ccl($cd, "$cd->{_sun_module}::isnan($dt)");
58 4         16 }
59             } elsif (defined $cd->{cl_value}) {
60 7         34 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
61             $c->add_ccl($cd, qq[lc($dt+0) ne "nan"]);
62             } else {
63 8 100 100     35 $c->add_ccl($cd, "!$cd->{_sun_module}::isnan($dt)");
64 4         15 }
65             }
66 4         19 }
67             }
68              
69             my ($self, $cd) = @_;
70             my $c = $self->compiler;
71             my $ct = $cd->{cl_term};
72             my $dt = $cd->{data_term};
73 28     28 0 49  
74 28         84 if ($cd->{cl_is_expr}) {
75 28         118 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
76 28         44 $c->add_ccl(
77             $cd, join(
78 28 50       57 '',
79 0 0 0     0 qq[$ct ? $dt =~ /\\A\\s*-inf(inity)?\\s*\\z/i : ],
80 0         0 qq[defined($ct) ? $dt !~ /\\A\\s*inf(inity)?\\s*\\z/i : 1]
81             ));
82             } else {
83             $c->add_ccl(
84             $cd, join(
85             '',
86             "$ct ? $cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt) : ",
87 0         0 "defined($ct) ? !($cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt)) : 1",
88             ));
89             }
90             } else {
91             if ($cd->{cl_value}) {
92             if ($cd->{args}{core} || $cd->{args}{no_modules}) {
93             $c->add_ccl($cd, qq[$dt =~ /\\A\\s*-inf(inity)?\\s*\\z/i]);
94             } else {
95 28 100       79 $c->add_ccl($cd, "$cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt)");
    50          
96 16 100 100     72 }
97 6         20 } elsif (defined $cd->{cl_value}) {
98             if ($cd->{args}{core} || $cd->{args}{no_modules}) {
99 10         57 $c->add_ccl($cd, qq[$dt !~ /\\A\\s*-inf(inity)?\\s*\\z/i]);
100             } else {
101             $c->add_ccl($cd, "!($cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt))");
102 12 100 100     58 }
103 6         21 }
104             }
105 6         30 }
106              
107             my ($self, $cd) = @_;
108             my $c = $self->compiler;
109             my $ct = $cd->{cl_term};
110             my $dt = $cd->{data_term};
111              
112 28     28 0 59 if ($cd->{cl_is_expr}) {
113 28         80 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
114 28         120 $c->add_ccl(
115 28         55 $cd, join(
116             '',
117 28 50       64 qq[$ct ? $dt =~ /\\A\\s*inf(inity)?\\s*\\z/i : ],
118 0 0 0     0 qq[defined($ct) ? $dt !~ /\\A\\s*inf(inity)?\\s*\\z/i : 1]
119 0         0 ));
120             } else {
121             $c->add_ccl(
122             $cd, join(
123             '',
124             "$ct ? $cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt) : ",
125             "defined($ct) ? !($cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt)) : 1",
126 0         0 ));
127             }
128             } else {
129             if ($cd->{cl_value}) {
130             if ($cd->{args}{core} || $cd->{args}{no_modules}) {
131             $c->add_ccl($cd, qq[$dt =~ /\\A\\s*inf(inity)?\\s*\\z/i]);
132             } else {
133             $c->add_ccl($cd, "$cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt)");
134 28 100       79 }
    50          
135 16 100 100     75 } elsif (defined $cd->{cl_value}) {
136 6         25 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
137             $c->add_ccl($cd, qq[$dt !~ /\\A\\s*inf(inity)?\\s*\\z/i]);
138 10         49 } else {
139             $c->add_ccl($cd, "!($cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt))");
140             }
141 12 100 100     53 }
142 6         22 }
143             }
144 6         29  
145             my ($self, $cd) = @_;
146             my $c = $self->compiler;
147             my $ct = $cd->{cl_term};
148             my $dt = $cd->{data_term};
149              
150             if ($cd->{cl_is_expr}) {
151 28     28 0 58 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
152 28         82 $c->add_ccl(
153 28         111 $cd, join(
154 28         55 '',
155             qq[$ct ? $dt =~ /\\A\\s*-?inf(inity)?\\s*\\z/i : ],
156 28 50       57 qq[defined($ct) ? $dt+0 !~ /\\A-?inf\\z/ : 1]
157 0 0 0     0 ));
158 0         0 } else {
159             $c->add_ccl($cd, "$ct ? $cd->{_sun_module}::isinf($dt) : ".
160             "defined($ct) ? $cd->{_sun_module}::isinf($dt) : 1");
161             }
162             } else {
163             if ($cd->{cl_value}) {
164             if ($cd->{args}{core} || $cd->{args}{no_modules}) {
165 0         0 $c->add_ccl($cd, qq[$dt =~ /\\A\\s*-?inf(inity)?\\s*\\z/i]);
166             } else {
167             $c->add_ccl($cd, "$cd->{_sun_module}::isinf($dt)");
168             }
169 28 100       113 } elsif (defined $cd->{cl_value}) {
    50          
170 16 100 100     72 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
171 6         18 $c->add_ccl($cd, qq[$dt !~ /\\A\\s*-?inf(inity)?\\s*\\z/i]);
172             } else {
173 10         42 $c->add_ccl($cd, "!$cd->{_sun_module}::isinf($dt)");
174             }
175             }
176 12 100 100     59 }
177 6         23 }
178              
179 6         30 1;
180             # ABSTRACT: perl's type handler for type "float"
181              
182              
183             =pod
184              
185             =encoding UTF-8
186              
187             =head1 NAME
188              
189             Data::Sah::Compiler::perl::TH::float - perl's type handler for type "float"
190              
191             =head1 VERSION
192              
193             This document describes version 0.914 of Data::Sah::Compiler::perl::TH::float (from Perl distribution Data-Sah), released on 2022-10-19.
194              
195             =for Pod::Coverage ^(compiler|clause_.+|handle_.+)$
196              
197             =head1 HOMEPAGE
198              
199             Please visit the project's homepage at L<https://metacpan.org/release/Data-Sah>.
200              
201             =head1 SOURCE
202              
203             Source repository is at L<https://github.com/perlancar/perl-Data-Sah>.
204              
205             =head1 AUTHOR
206              
207             perlancar <perlancar@cpan.org>
208              
209             =head1 CONTRIBUTING
210              
211              
212             To contribute, you can send patches by email/via RT, or send pull requests on
213             GitHub.
214              
215             Most of the time, you don't need to build the distribution yourself. You can
216             simply modify the code, then test via:
217              
218             % prove -l
219              
220             If you want to build the distribution (e.g. to try to install it locally on your
221             system), you can install L<Dist::Zilla>,
222             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
223             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
224             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
225             that are considered a bug and can be reported to me.
226              
227             =head1 COPYRIGHT AND LICENSE
228              
229             This software is copyright (c) 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012 by perlancar <perlancar@cpan.org>.
230              
231             This is free software; you can redistribute it and/or modify it under
232             the same terms as the Perl 5 programming language system itself.
233              
234             =head1 BUGS
235              
236             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah>
237              
238             When submitting a bug or request, please include a test-file or a
239             patch to an existing test-file that illustrates the bug or desired
240             feature.
241              
242             =cut