1MooseX::Params::ValidatUes(e3r)Contributed Perl DocumentMaotoisoenX::Params::Validate(3)
2
3
4

NAME

6       MooseX::Params::Validate - an extension of Params::Validate for using
7       Moose's types
8

SYNOPSIS

10         package Foo;
11         use Moose;
12         use MooseX::Params::Validate;
13
14         sub foo {
15             my ($self, %params) = validate(\@_,
16                 bar => { isa => 'Str', default => 'Moose' },
17             );
18             return "Horray for $params{bar}!";
19         }
20
21         sub bar {
22             my $self = shift;
23             my ($foo, $baz) = validatep(\@_,
24                 foo => { isa => 'Foo' },
25                 baz => { isa => 'ArrayRef ⎪ HashRef', optional => 1 }
26             );
27             [ $foo, $baz ];
28         }
29

DESCRIPTION

31       This module fills a gap in Moose by adding method parameter validation
32       to Moose. This is just one of many developing options, it should not be
33       considered the "official" one by any means though.
34
35       This is an early release of this module, and many things will likely
36       change and get added, so watch out :)
37

CAVEATS

39       It is not possible to introspect the method parameter specs, they are
40       created as needed when the method is called and tossed aside after‐
41       wards.
42
43       This is probably not the most efficient way to do this, but it works
44       for what it is.
45

EXPORTS

47       validate (\@_, %parameter_spec)
48           This behaves similar to the standard Params::Validate "validate"
49           function and returns the captured values in a HASH. The one excep‐
50           tion being that if it spots an instance in the @_, then it will
51           handle it appropriately (unlike Params::Validate which forces you
52           to shift you $self first).
53
54           The %parameter_spec accepts the following options:
55
56           isa The "isa" option can be either; class name, Moose type con‐
57               straint name or an anon Moose type constraint.
58
59           does
60               The "does" option can be either; role name or an anon Moose
61               type constraint.
62
63           default
64               This is the default value to be used if the value is not sup‐
65               plied.
66
67           optional
68               As with Params::Validate, all options are considered required
69               unless otherwise specified. This option is passed directly to
70               Params::Validate.
71
72           The plan is to support more options in the future as well.
73
74       validatep (\@_, %parameter_spec)
75           The %parameter_spec accepts the same options as above, but returns
76           the parameters as positional values instead of a HASH. This is best
77           explained by example:
78
79             sub foo {
80                 my ($self, $foo, $bar) = validatep(\@_,
81                     foo => { isa => 'Foo' },
82                     bar => { isa => 'Bar' },
83                 );
84                 $foo->baz($bar);
85             }
86
87           We capture the order in which you defined the parameters and then
88           return them as positionals in the same order. If a param is marked
89           optional and not included, then it will be set to "undef".
90

METHODS

92       import
93
94       Introspection
95
96       meta
97

BUGS

99       All complex software has bugs lurking in it, and this module is no
100       exception. If you find a bug please either email me, or add the bug to
101       cpan-RT.
102

AUTHOR

104       Stevan Little <stevan.little@iinteractive.com>
105
107       Copyright 2007 by Infinity Interactive, Inc.
108
109       <http://www.iinteractive.com>
110
111       This library is free software; you can redistribute it and/or modify it
112       under the same terms as Perl itself.
113
114
115
116perl v5.8.8                       2007-10-23       MooseX::Params::Validate(3)
Impressum