Simple/Library/Numerical.pm

filter: Statementstmt 100% 21 / 21 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 100% 33 / 33 CC 3 SCAR 3.4
CC
3
Cov
100%
__ANON__
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.4
« Simple/Library/Base.pm ↑ Summary Simple/Result.pm »
1 =head1 NAME
2  
3 Declare::Constraints::Simple::Library::Numerical - Numerical Constraints
4  
5 =cut
6  
7 package Declare::Constraints::Simple::Library::Numerical;
8 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 ▶use Declare::Constraints::Simple-Library;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 SYNOPSIS
16  
17 # test for number-conformity
18 my $looks_like_number = IsNumber;
19  
20 # only integers
21 my $is_int = IsInt;
22  
23 =head1 DESCRIPTIONS
24  
25 This library contains the constraints needed to validate numerical values.
26  
27 =head1 CONSTRAINTS
28  
29 =head2 IsNumber()
30  
31 True if the value is a number according to L<Scalar::Util>s
32 C<looks_like_number>.
33  
34 =cut
35  
36 constraint 'IsNumber',
37 6 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 6 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
39 6 ▶ return _false('Undefined Value') unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 1 5 6
40 5 return _result(Scalar::Util::looks_like_number($_[0]),
41 'Does not look like Number');
42 6 };
43 13 };
44  
45 =head2 IsInt()
46  
47 True if the value is an integer.
48  
49 =cut
50  
51 constraint 'IsInt',
52 81 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 120 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
54 120 ▶ return _false('Undefined Value') unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 6 114 120
55 114 return _result(scalar($_[0] =~ /^-?\d+$/), 'Not an Integer');
56 81 };
57 13 };
58  
59 =head1 SEE ALSO
60  
61 L<Declare::Constraints::Simple>, L<Declare::Constraints::Simple::Library>
62  
63 =head1 AUTHOR
64  
65 Robert 'phaylon' Sedlacek C<E<lt>phaylon@dunkelheit.atE<gt>>
66  
67 =head1 LICENSE AND COPYRIGHT
68  
69 This module is free software, you can redistribute it and/or modify it
70 under the same terms as perl itself.
71  
72 =cut
73  
74 13 1;
« Simple/Library/Base.pm ↑ Summary Simple/Result.pm »