v_melnik has asked for the wisdom of the Perl Monks concerning the following question:

Dear colleagues,

If you have a couple of minutes, please, tell what way do you prefer to validate method's parameters? There are a few nice modules (Params::Validate, MooseX::Params::Validate, Method::Signatures, MooseX::Method::Signatrues), which of them do you prefer? Maybe you would suggest anything else?

As for me, I use my own subroutine for it, but for me it's quite obvious that there are much more flexible tools that already have been developed by other contributors.

Would you be so kind as to share your experience?

Thank you!

V.Melnik

(Added on the same day) P.S. As the MooseX::Method::Signatrues module is marked as deprecated, the Method::Signatures one seems to be the most convenient, as for me.

  • Comment on Params::Validate, MooseX::Params::Validate, Method::Signatures, MooseX::Method::Signatrues or your own solutions

Replies are listed 'Best First'.
Re: Params::Validate, MooseX::Params::Validate, Method::Signatures, MooseX::Method::Signatrues or your own solutions
by 1nickt (Canon) on Dec 23, 2015 at 14:22 UTC

    Toby Inks' Type::Tiny suite, starting with Types::Standard.

    #!/usr/bin/perl use strict; use warnings; use Moo; # Or Moose, or Mouse use Types::Standard qw/ :all /; has foo => ( is => 'ro', isa => Str, required => 1 ); has bar => ( is => 'ro', isa => HashRef, required => 1 ); has flintstone => ( is => 'ro', isa => Enum[qw( Fred Wilma Pebbles Bam +Bam )] ); # etc. . .
    Also see Type::Tiny and Type::Tiny::Manual to define your own constraints, and/or Type::Library to create a type library.

    Hope this helps!

    The way forward always starts with a minimal test.
Re: Params::Validate, MooseX::Params::Validate, Method::Signatures, MooseX::Method::Signatrues or your own solutions
by davies (Monsignor) on Dec 23, 2015 at 13:22 UTC

    As I said in Re^2: Function Prototypes, I've rather fallen in love with Method::Signatures, but I haven't tried the others (the little OO programming I've done in Perl has used Moo rather than Moose).

    Regards,

    John Davies