line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Types::Common::Numeric; |
2
|
|
|
|
|
|
|
# ABSTRACT: Commonly used numeric types |
3
|
|
|
|
|
|
|
our $VERSION = '0.001013'; |
4
|
1
|
|
|
1
|
|
13222
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
|
|
11
|
use MooseX::Types -declare => [ |
8
|
|
|
|
|
|
|
qw(PositiveNum PositiveOrZeroNum |
9
|
|
|
|
|
|
|
PositiveInt PositiveOrZeroInt |
10
|
|
|
|
|
|
|
NegativeNum NegativeOrZeroNum |
11
|
|
|
|
|
|
|
NegativeInt NegativeOrZeroInt |
12
|
|
|
|
|
|
|
SingleDigit) |
13
|
1
|
|
|
1
|
|
425
|
]; |
|
1
|
|
|
|
|
431841
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5991
|
use MooseX::Types::Moose qw/Num Int/; |
|
1
|
|
|
|
|
11705
|
|
|
1
|
|
|
|
|
8
|
|
16
|
1
|
|
|
1
|
|
3460
|
use if MooseX::Types->VERSION >= 0.42, 'namespace::autoclean'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
subtype PositiveNum, |
19
|
|
|
|
|
|
|
as Num, |
20
|
|
|
|
|
|
|
where { $_ > 0 }, |
21
|
|
|
|
|
|
|
message { "Must be a positive number" }, |
22
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
23
|
|
|
|
|
|
|
? inline_as { |
24
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
25
|
|
|
|
|
|
|
. qq{ ($_[1] > 0) }; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
: () |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
subtype PositiveOrZeroNum, |
31
|
|
|
|
|
|
|
as Num, |
32
|
|
|
|
|
|
|
where { $_ >= 0 }, |
33
|
|
|
|
|
|
|
message { "Must be a number greater than or equal to zero" }, |
34
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
35
|
|
|
|
|
|
|
? inline_as { |
36
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
37
|
|
|
|
|
|
|
. qq{ ($_[1] >= 0) }; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
: () |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
subtype PositiveInt, |
43
|
|
|
|
|
|
|
as Int, |
44
|
|
|
|
|
|
|
where { $_ > 0 }, |
45
|
|
|
|
|
|
|
message { "Must be a positive integer" }, |
46
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
47
|
|
|
|
|
|
|
? inline_as { |
48
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
49
|
|
|
|
|
|
|
. qq{ ($_[1] > 0) }; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
: () |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
subtype PositiveOrZeroInt, |
55
|
|
|
|
|
|
|
as Int, |
56
|
|
|
|
|
|
|
where { $_ >= 0 }, |
57
|
|
|
|
|
|
|
message { "Must be an integer greater than or equal to zero" }, |
58
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
59
|
|
|
|
|
|
|
? inline_as { |
60
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
61
|
|
|
|
|
|
|
. qq{ ($_[1] >= 0) }; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
: () |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
subtype NegativeNum, |
67
|
|
|
|
|
|
|
as Num, |
68
|
|
|
|
|
|
|
where { $_ < 0 }, |
69
|
|
|
|
|
|
|
message { "Must be a negative number" }, |
70
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
71
|
|
|
|
|
|
|
? inline_as { |
72
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
73
|
|
|
|
|
|
|
. qq{ ($_[1] < 0) }; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
: () |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
subtype NegativeOrZeroNum, |
79
|
|
|
|
|
|
|
as Num, |
80
|
|
|
|
|
|
|
where { $_ <= 0 }, |
81
|
|
|
|
|
|
|
message { "Must be a number less than or equal to zero" }, |
82
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
83
|
|
|
|
|
|
|
? inline_as { |
84
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
85
|
|
|
|
|
|
|
. qq{ ($_[1] <= 0) }; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
: () |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
subtype NegativeInt, |
91
|
|
|
|
|
|
|
as Int, |
92
|
|
|
|
|
|
|
where { $_ < 0 }, |
93
|
|
|
|
|
|
|
message { "Must be a negative integer" }, |
94
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
95
|
|
|
|
|
|
|
? inline_as { |
96
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
97
|
|
|
|
|
|
|
. qq{ ($_[1] < 0) }; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
: () |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
subtype NegativeOrZeroInt, |
103
|
|
|
|
|
|
|
as Int, |
104
|
|
|
|
|
|
|
where { $_ <= 0 }, |
105
|
|
|
|
|
|
|
message { "Must be an integer less than or equal to zero" }, |
106
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
107
|
|
|
|
|
|
|
? inline_as { |
108
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
109
|
|
|
|
|
|
|
. qq{ ($_[1] <= 0) }; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
: () |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
subtype SingleDigit, |
115
|
|
|
|
|
|
|
as Int, |
116
|
|
|
|
|
|
|
where { $_ >= -9 and $_ <= 9 }, |
117
|
|
|
|
|
|
|
message { "Must be a single digit" }, |
118
|
|
|
|
|
|
|
( $Moose::VERSION >= 2.0200 |
119
|
|
|
|
|
|
|
? inline_as { |
120
|
|
|
|
|
|
|
$_[0]->parent()->_inline_check( $_[1] ) . ' && ' |
121
|
|
|
|
|
|
|
. qq{ ($_[1] >= -9 and $_[1] <= 9) }; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
: () |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=pod |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=encoding UTF-8 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 NAME |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
MooseX::Types::Common::Numeric - Commonly used numeric types |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 VERSION |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
version 0.001013 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 SYNOPSIS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
use MooseX::Types::Common::Numeric qw/PositiveInt/; |
145
|
|
|
|
|
|
|
has count => (is => 'rw', isa => PositiveInt); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
... |
148
|
|
|
|
|
|
|
#this will fail |
149
|
|
|
|
|
|
|
$object->count(-33); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 DESCRIPTION |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
A set of commonly-used numeric type constraints that do not ship with Moose by |
154
|
|
|
|
|
|
|
default. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=over |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * C<PositiveNum> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * C<PositiveOrZeroNum> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * C<PositiveInt> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * C<PositiveOrZeroInt> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * C<NegativeNum> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * C<NegativeOrZeroNum> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * C<NegativeInt> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * C<NegativeOrZeroInt> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * C<SingleDigit> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=over |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * L<MooseX::Types::Common::String> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 AUTHORS |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=over 4 |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>) |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
K. James Cheetham <jamie@shadowcatsystems.co.uk> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Guillermo Roditi <groditi@gmail.com> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=back |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>). |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
209
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |