File Coverage

blib/lib/Data/Sah/Compiler/human/TH/int.pm
Criterion Covered Total %
statement 34 39 87.1
branch 6 10 60.0
condition 8 15 53.3
subroutine 9 9 100.0
pod 0 4 0.0
total 57 77 74.0


line stmt bran cond sub pod time code
1              
2             use 5.010;
3 7     7   543 use strict;
  7         21  
4 7     7   32 use warnings;
  7         12  
  7         133  
5 7     7   28 #use Log::Any '$log';
  7         14  
  7         219  
6              
7             use Mo qw(build default);
8 7     7   70 use Role::Tiny::With;
  7         13  
  7         42  
9 7     7   1701  
  7         13  
  7         2844  
10             extends 'Data::Sah::Compiler::human::TH::num';
11             with 'Data::Sah::Type::int';
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              
19 688     688 0 2484 my ($self, $cd) = @_;
20             my $c = $self->compiler;
21              
22 692     692 0 1373 $c->add_ccl($cd, {
23 692         2112 type => 'noun',
24             fmt => ["integer", "integers"],
25 692         5509 });
26             }
27              
28             my ($self, $cd) = @_;
29             my $c = $self->compiler;
30             my $cv = $cd->{cl_value};
31              
32 73     73 0 150 if (!$cd->{cl_is_multi} && !$cd->{cl_is_expr} &&
33 73         182 $cv == 2) {
34 73         293 $c->add_ccl($cd, {
35             fmt => q[%(modal_verb)s be even],
36 73 100 66     406 });
      100        
37             return;
38 25         101 }
39              
40             $c->add_ccl($cd, {
41 25         66 fmt => q[%(modal_verb)s be divisible by %s],
42             expr => 1,
43             });
44 48         207 }
45              
46             my ($self, $cd) = @_;
47             my $c = $self->compiler;
48             my $cv = $cd->{cl_value};
49              
50             if (!$cd->{cl_is_multi} && !$cd->{cl_is_expr}) {
51 6     6 0 20 if ($cv->[0] == 2 && $cv->[1] == 0) {
52 6         23 $c->add_ccl($cd, {
53 6         60 fmt => q[%(modal_verb)s be even],
54             });
55 6 50 33     41 return;
56 6 50 33     53 } elsif ($cv->[0] == 2 && $cv->[1] == 1) {
    50 33        
57 0         0 $c->add_ccl($cd, {
58             fmt => q[%(modal_verb)s be odd],
59             });
60 0         0 return;
61             }
62 0         0 }
63              
64             my @ccls;
65 0         0 for my $cv ($cd->{cl_is_multi} ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
66             push @ccls, {
67             fmt => q[%(modal_verb)s leave a remainder of %2$s when divided by %1$s],
68             vals => $cv,
69 6         18 };
70 6 50       24 }
  0         0  
71 6         28 $c->add_ccl($cd, @ccls);
72             }
73              
74             1;
75             # ABSTRACT: human's type handler for type "int"
76 6         25  
77              
78             =pod
79              
80             =encoding UTF-8
81              
82             =head1 NAME
83              
84             Data::Sah::Compiler::human::TH::int - human's type handler for type "int"
85              
86             =head1 VERSION
87              
88             This document describes version 0.914 of Data::Sah::Compiler::human::TH::int (from Perl distribution Data-Sah), released on 2022-10-19.
89              
90             =for Pod::Coverage ^(name|clause_.+|superclause_.+|before_.+|after_.+)$
91              
92             =head1 HOMEPAGE
93              
94             Please visit the project's homepage at L<https://metacpan.org/release/Data-Sah>.
95              
96             =head1 SOURCE
97              
98             Source repository is at L<https://github.com/perlancar/perl-Data-Sah>.
99              
100             =head1 AUTHOR
101              
102             perlancar <perlancar@cpan.org>
103              
104             =head1 CONTRIBUTING
105              
106              
107             To contribute, you can send patches by email/via RT, or send pull requests on
108             GitHub.
109              
110             Most of the time, you don't need to build the distribution yourself. You can
111             simply modify the code, then test via:
112              
113             % prove -l
114              
115             If you want to build the distribution (e.g. to try to install it locally on your
116             system), you can install L<Dist::Zilla>,
117             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
118             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
119             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
120             that are considered a bug and can be reported to me.
121              
122             =head1 COPYRIGHT AND LICENSE
123              
124             This software is copyright (c) 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012 by perlancar <perlancar@cpan.org>.
125              
126             This is free software; you can redistribute it and/or modify it under
127             the same terms as the Perl 5 programming language system itself.
128              
129             =head1 BUGS
130              
131             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah>
132              
133             When submitting a bug or request, please include a test-file or a
134             patch to an existing test-file that illustrates the bug or desired
135             feature.
136              
137             =cut