1Attribute::Params::ValiUdsaetre(C3o)ntributed Perl DocumAetnttraitbiuotne::Params::Validate(3)
2
3
4

SYNOPSIS

6         use Attribute::Params::Validate qw(:all);
7
8         # takes named params (hash or hashref)
9         # foo is mandatory, bar is optional
10         sub foo : Validate( foo => 1, bar => 0 )
11         {
12             ...
13         }
14
15         # takes positional params
16         # first two are mandatory, third is optional
17         sub bar : ValidatePos( 1, 1, 0 )
18         {
19             ...
20         }
21
22         # for some reason Perl insists that the entire attribute be on one line
23         sub foo2 : Validate( foo => { type => ARRAYREF }, bar => { can => [ 'print', 'flush', 'frobnicate' ] }, baz => { type => SCALAR, callbacks => { 'numbers only' => sub { shift() =~ /^\d+$/ }, 'less than 90' => sub { shift() < 90 } } } )
24         {
25             ...
26         }
27
28         # note that this is marked as a method.  This is very important!
29         sub baz : Validate( foo => { type => ARRAYREF }, bar => { isa => 'Frobnicator' } ) method
30         {
31             ...
32         }
33

DESCRIPTION

35       The Attribute::Params::Validate module allows you to validate method or
36       function call parameters just like Params::Validate does.  However,
37       this module allows you to specify your validation spec as an attribute,
38       rather than by calling the "validate" routine.
39
40       Please see Params::Validate for more information on how you can specify
41       what validation is performed.
42
43   EXPORT
44       This module exports everything that Params::Validate does except for
45       the "validate" and "validate_pos" subroutines.
46
47   ATTRIBUTES
48       ·   Validate
49
50           This attribute corresponds to the "validate" subroutine in
51           Params::Validate.
52
53       ·   ValidatePos
54
55           This attribute corresponds to the "validate_pos" subroutine in
56           Params::Validate.
57
58   OO
59       If you are using this module to mark methods for validation, as opposed
60       to subroutines, it is crucial that you mark these methods with the
61       ":method" attribute, as well as the "Validate" or "ValidatePos"
62       attribute.
63
64       If you do not do this, then the object or class used in the method call
65       will be passed to the validation routines, which is probably not what
66       you want.
67
68   CAVEATS
69       You must put all the arguments to the "Validate" or "ValidatePos"
70       attribute on a single line, or Perl will complain.
71

SEE ALSO

73       Params::Validate
74
75
76
77perl v5.12.3                      2011-05-31    Attribute::Params::Validate(3)
Impressum