View on
Mohammad S Anwar > MouseX-Params-Validate-0.04 > MouseX::Params::Validate



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.04   Source   Latest Release: MouseX-Params-Validate-0.10


MouseX::Params::Validate - Extension of Params::Validate using Mouse's types.


Version 0.04


Method parameter validation extension to Mouse.

Borrowed code entirely from MooseX::Params::Validate and stripped Moose footprints.


By default, this module exports the following:


It isn't possible to introspect the method parameter specs they are created as needed when the method is called and cached for subsequent calls.


When a validation subroutine is called the first time, the parameter spec is prepared & cached to avoid unnecessary regeneration. It uses the fully qualified name of the subroutine (package +subname) as the cache key. In 99.999% of the use cases for this module that will be the right thing to do. You can do a couple things to better control the caching behavior.


validated_hash(\@_, %parameter_spec)

This behaves similarly to the standard Params::Validate validate function and returns the captured values in a HASH. The one exception is where if it spots an instance in the @_ , then it will handle it appropriately.

The values in @_ can either be a set of name-value pairs or a single hash reference.

The %parameter_spec accepts the following options:


The isa option can be either; class name, Mouse type constraint name or an anon Mouse type constraint.


The does option can be either; role name or an anon Mouse type constraint.


This is the default value to be used if the value is not supplied.


As with Params::Validate, all options are considered required unless otherwise specified. This option is passed directly to Params::Validate.


If this is true and the parameter has a type constraint which has coercions, then the coercion will be called for this parameter. If the type does have coercions, then this parameter is ignored.

    use Mouse;
    use MouseX::Params::Validate;
    sub foo 
        my ($self, %params) = validated_hash(
            bar => {isa => 'Str', default => 'Mouse'},

validated_list(\@_, %parameter_spec)

The %parameter_spec accepts the same options as above but returns the params as positional values instead of a HASH.

We capture the order in which you defined the parameters and then return them as a list in the same order. If a param is marked optional and not included, then it will be set to undef.

The values in @_ can either be a set of name-value pairs or a single hash reference.

Like validated_hash, if it spots an object instance as the first parameter of @_ it will handle it appropriately, returning it as the first argument.

    use Mouse;
    use MouseX::Params::Validate;

    sub foo 
        my ($self, $foo, $bar) = validated_list(
            foo => {isa => 'Foo'},
            bar => {isa => 'Bar'},

pos_validated_list(\@_, $spec, $spec, ...)

This function validates a list of positional parameters. Each $spec should validate one of the parameters in the list.

Unlike the other functions, this function cannot find $self in the argument list. Make sure to shift it off yourself before doing validation.

The values in @_ must be a list of values.You cannot pass the values as an array reference, because this cannot be distinguished from passing one value which itself an array reference.

If a parameter is marked as optional and is not present, it will simply not be returned.

If you want to pass in any of the cache control parameters described below, simply pass them after the list of parameter validation specs.

    use Mouse;
    use MouseX::Params::Validate;

    sub foo 
        my $self = shift;
        my ($foo, $bar) = pos_validated_list(
            {isa => 'Foo'},
            {isa => 'Bar'},


Mohammad S Anwar, <mohammad.anwar at>


Please report any bugs or feature requests to bug-mousex-params-validate at, or through the web interface at I will be notified and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc MouseX::Params::Validate

You can also look for information at:



Copyright 2011 Mohammad S Anwar.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.


This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

syntax highlighting: