/
Numeric.pm
123 lines (98 loc) · 2.79 KB
/
Numeric.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use strictures 1;
package MooX::Types::MooseLike::Numeric;
use MooX::Types::MooseLike::Base;
use Exporter 5.57 'import';
our @EXPORT_OK = ();
my $type_definitions = [
{
name => 'PositiveNum',
subtype_of => 'Num',
from => 'MooX::Types::MooseLike::Base',
test => sub { $_[0] > 0 },
message => sub { "$_[0] is not a positive number!" },
},
{
name => 'NonNegativeNum',
subtype_of => 'Num',
from => 'MooX::Types::MooseLike::Base',
test => sub { $_[0] >= 0 },
message => sub { "$_[0] is not a non-negative number!" },
},
{
name => 'PositiveInt',
subtype_of => 'Int',
from => 'MooX::Types::MooseLike::Base',
test => sub { $_[0] > 0 },
message => sub { "$_[0] is not a positive integer!" },
},
{
name => 'NonNegativeInt',
subtype_of => 'Int',
from => 'MooX::Types::MooseLike::Base',
test => sub { $_[0] >= 0 },
message => sub { "$_[0] is not a non-negative integer!" },
},
{
name => 'NegativeNum',
subtype_of => 'Num',
from => 'MooX::Types::MooseLike::Base',
test => sub { $_[0] < 0 },
message => sub { "$_[0] is not a negative number!" },
},
{
name => 'NonPositiveNum',
subtype_of => 'Num',
from => 'MooX::Types::MooseLike::Base',
test => sub { $_[0] <= 0 },
message => sub { "$_[0] is not a non-positive number!" },
},
{
name => 'NegativeInt',
subtype_of => 'Int',
from => 'MooX::Types::MooseLike::Base',
test => sub { $_[0] < 0 },
message => sub { "$_[0] is not a negative integer!" },
},
{
name => 'NonPositiveInt',
subtype_of => 'Int',
from => 'MooX::Types::MooseLike::Base',
test => sub { $_[0] <= 0 },
message => sub { "$_[0] is not a non-positive integer!" },
},
{
name => 'SingleDigit',
subtype_of => 'NonNegativeInt',
from => 'MooX::Types::MooseLike::Numeric',
test => sub { $_[0] < 10 },
message => sub { "$_[0] is not a single digit!" },
},
];
MooX::Types::MooseLike::register_types($type_definitions, __PACKAGE__);
our %EXPORT_TAGS = ('all' => \@EXPORT_OK);
1
__END__
=head1 NAME
MooX::Types::MooseLike::Numeric - Moo types for numbers
=head1 SYNOPSIS
package MyPackage;
use Moo;
use MooX::Types::MooseLike::Numeric qw(PositiveInt);
has "daily_breathes" => (
isa => PositiveInt
);
=head1 DESCRIPTION
adpated from MooseX::Types::Common::Numeric
=head1 TYPES (subroutines)
Available types are listed below.
=over
=item PositiveNum
=item NonNegativeNum
=item PositiveInt
=item NonNegativeInt
=item NegativeNum
=item NonPositiveNum
=item NegativeInt
=item NonPositiveInt
=item SingleDigit
=back