use strict; use v5.10; use MooseX::Declare; use Moose::Util::TypeConstraints; subtype 'PositiveInt' => as 'Int' => where { $_ > 0 } => message { "Number '$_' is not positive" }; class BankAccount { use MooseX::StrictConstructor; has balance => ( isa => 'Int', is => 'rw', default => 0 ); method deposit ( PositiveInt :$amount ) { $self->balance( $self->balance + $amount ); } } my $a = BankAccount->new( balance => 100 ); $a->deposit( amount => 50 ); say $a->balance;