Catalyst::Plugin::Params::Profile - Parameter checking with Params::Profile
package MyAPP; use Catalyst qw/Params::Profile/; # In a controller MyAPP->register_profile( 'method' => 'subroto', 'profile' => { testkey1 => { required => 1 }, testkey2 => { required => 1, allow => qr/^\d+$/, }, testkey3 => { allow => qr/^\w+$/, }, }, ); sub subroto : Private { my (%params) = @_; return unlesss $c->validate('params' => \%params); ### OR my %opts = $c->check_params or return; ### DO SOME STUFF HERE ... my $profile = $c->get_profile('method' => 'subroto'); } ### Multiple Profile MyAPP->register_profile( 'method' => 'subalso', 'profile' => [ 'subroto', { testkey4 => { required => 1 }, testkey5 => { required => 1, allow => qr/^\d+$/, }, testkey6 => { allow => qr/^\w+$/, }, }, ], ); sub subalso : Local { my (%params) = @_; ### Checks parameters agains profile of subroto and above registered ### profile return unlesss $c->validate('params' => \%params); ### DO SOME STUFF HERE ... }
Catalyst::Plugin::Params::Profile provides a mechanism for a centralised Params::Check or a Data::FormValidater profile. You can bind a profile to a class::subroutine, then, when you are in a subroutine you can simply call $c->check($params) of $c->validate($params) to validate against this profile.
For more information read the manual of Params::Profile , the methods below are just an interface on it.
Params::Profile
See Params::Profile for more information about the specific methods, the onse listed below are the most important.
Checks $c->req->params against the profile of the calling sub. It returns a HASHREF containing validate parameters, or undef on failure. It will also log to Catalyst::Log about what happened.
Extra options to this sub are:
Validate against params instead of $c->req->params
Validate against profile instead of profile of calling sub
Pass the unknown parameters to the return HREF rather than filtering them out.
Instead of returning a hashref containing validated params, return the Data::FormValidator::Results object.
NOTE: Only tested with Data::FormValidator yet!!
This module also registers a method name called system.methodHelp into the Server::XMLRPC plugin when it is loaded. This method will try to explain in plaintext the arguments for the subroutine by parsing the given profile.
system.methodHelp
Example output when system.methodHelp is called with one argument containing the name of the method you'd like to be explained:
Required arguments are: * customer_id * username * product Optional arguments are: * roaming * card_type
NOTE: This currently only works for Data::FormValidator profiles.
This module by Michiel Ootjers <michiel@cpan.org>.
and
Jos Boumans <kane@cpan.org>.
Fix the profile explanation to explain profiles other than Data::FormValidator
Data::FormValidator
Please submit all bugs regarding Catalyst::Plugin::Params::Profile to bug-catalyst-plugin-params-profile@rt.cpan.org
Catalyst::Plugin::Params::Profile
bug-catalyst-plugin-params-profile@rt.cpan.org
This module is copyright (c) 2002 Michiel Ootjers <michiel@cpan.org>. All rights reserved.
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Catalyst::Plugin::Params::Profile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::Params::Profile
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::Params::Profile
For more information on module installation, please visit the detailed CPAN module installation guide.