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   538 use strict;
  3         11  
4 3     3   13 use warnings;
  3         5  
  3         52  
5 3     3   12 #use Log::Any '$log';
  3         5  
  3         82  
6              
7             use Mo qw(build default);
8 3     3   13 use Role::Tiny::With;
  3         5  
  3         13  
9 3     3   763  
  3         13  
  3         3671  
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-09-30'; # DATE
15             our $DIST = 'Data-Sah'; # DIST
16             our $VERSION = '0.913'; # VERSION
17              
18             my ($self, $cd) = @_;
19             my $c = $self->compiler;
20 666     666 0 2246  
21 666         2511 my $dt = $cd->{data_term};
22             if ($cd->{args}{core} || $cd->{args}{no_modules}) {
23 666         3111 $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     3651 } else {
25 60         173 $c->add_sun_module($cd);
26             # we use isnum = isint + isfloat, because isfloat(3) is false
27 606         3203 $cd->{_ccl_check_type} = "$cd->{_sun_module}::isnum($dt)";
28             }
29 606         3444 }
30              
31             my ($self, $cd) = @_;
32             my $c = $self->compiler;
33             my $ct = $cd->{cl_term};
34 19     19 0 61 my $dt = $cd->{data_term};
35 19         56  
36 19         81 if ($cd->{cl_is_expr}) {
37 19         33 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
38             $c->add_ccl(
39 19 50       35 $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       47 } else {
    50          
57 11 100 100     48 $c->add_ccl($cd, "$cd->{_sun_module}::isnan($dt)");
58 4         15 }
59             } elsif (defined $cd->{cl_value}) {
60 7         25 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     30 $c->add_ccl($cd, "!$cd->{_sun_module}::isnan($dt)");
64 4         14 }
65             }
66 4         17 }
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 64  
74 28         75 if ($cd->{cl_is_expr}) {
75 28         120 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
76 28         41 $c->add_ccl(
77             $cd, join(
78 28 50       58 '',
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       64 $c->add_ccl($cd, "$cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt)");
    50          
96 16 100 100     82 }
97 6         21 } elsif (defined $cd->{cl_value}) {
98             if ($cd->{args}{core} || $cd->{args}{no_modules}) {
99 10         47 $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     46 }
103 6         20 }
104             }
105 6         25 }
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 47 if ($cd->{cl_is_expr}) {
113 28         81 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
114 28         113 $c->add_ccl(
115 28         46 $cd, join(
116             '',
117 28 50       50 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       59 }
    50          
135 16 100 100     62 } elsif (defined $cd->{cl_value}) {
136 6         20 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
137             $c->add_ccl($cd, qq[$dt !~ /\\A\\s*inf(inity)?\\s*\\z/i]);
138 10         44 } else {
139             $c->add_ccl($cd, "!($cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt))");
140             }
141 12 100 100     41 }
142 6         20 }
143             }
144 6         30  
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 44 if ($cd->{args}{core} || $cd->{args}{no_modules}) {
152 28         76 $c->add_ccl(
153 28         114 $cd, join(
154 28         43 '',
155             qq[$ct ? $dt =~ /\\A\\s*-?inf(inity)?\\s*\\z/i : ],
156 28 50       54 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       63 } elsif (defined $cd->{cl_value}) {
    50          
170 16 100 100     61 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         35 $c->add_ccl($cd, "!$cd->{_sun_module}::isinf($dt)");
174             }
175             }
176 12 100 100     46 }
177 6         20 }
178              
179 6         23 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.913 of Data::Sah::Compiler::perl::TH::float (from Perl distribution Data-Sah), released on 2022-09-30.
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