package Person; use Moo; has name => (is => 'rw'); has age => ( is => 'rw', isa => sub { die "'$_[0]' is not an integer!" if $_[0] !~ /^\d+$/; }, ); 1; #### use strict; use warnings; use 5.010; use Person; my $student = Person->new( name => 'Foo', age => 22 ); say $student->name; say $student->age; $student->age('young'); say $student->age;