Thanks for the advertisement. :)
I'll also point out that /^\d+$/ isn't a great integer check. \d allows more characters than the digits 0 to 9. It also allows a whole bunch of other Unicode digit characters, which 99% of the time, you probably didn't really intend to allow. So use /^[0-9]+$/ which is barely any more typing.
I'll also just give a quick demo of:
package Person; use Moo; use Types::Standard 'Int'; has name => (is => 'rw'); has age => (is => 'rw', isa => Int->where(q{ $_ > 0 })); 1;
... as a simple way to prohibit negative integers. Or even:
package Person; use Moo; use Types::Common::Numeric 'PositiveInt'; has name => (is => 'rw'); has age => (is => 'rw', isa => PositiveInt); 1;
Or:
package Person; use Moo; use Types::Common::Numeric 'IntRange'; has name => (is => 'rw'); has age => (is => 'rw', isa => IntRange[0,200]); # 200 is a realisti +c age limit 1;
In reply to Re^2: Moo-Type checking example from Perl Maven: What should be the expected result?
by tobyink
in thread Moo-Type checking example from Perl Maven: What should be the expected result?
by Perl300
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |