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