There have been a few attempts to hack (design by) contracts into Perl. Here are some which can be found on CPAN:
* Class::Agreement - https://metacpan.org/module/Class::Agreement
* Class::Contract - https://metacpan.org/module/Class::Contract
* Sub::Contract - https://metacpan.org/module/Sub::Contract
Sub::Contract is my favourite because it's lightweight, pragmatic & with a more Perlish implementation.