NAME
Catalyst::Plugin::StrongParameters - Plug to add tge strong parameter request trait plus proxy methods
SYNOPSIS
package MyApp;
use Catalyst 'StrongParameters';
MyApp->setup;
package MyApp::Controller::Root;
sub body :Local {
my ($self, $c) = @_;
my %clean = $c->strong_body
->permitted(['person'], +{'email' => []})
->namespace(['person'])
->permitted(
'name',
'age',
'address' => ['street' => ['number', 'zip'],
+{'credit_cards' => [
'number',
'exp' => [qw/year month day/],
]},
)->to_hash;
## Do something with the sanitized body parameters
}
## Don't forget to add code to handle any exceptions
sub end :Action {
my ($self, $c) = @_;
if(my $error = $c->last_error) {
$c->clear_errors; ## Clear the error stack unless you want the default Catalyst error
if($c->isa_strong_parameter_exception($error)) {
## Something here like return a Bad Request 4xx view or similar.
}
}
}
You should review Catalyst::TraitFor::Request::StrongParameters for a more detailed SYNOPSIS and explanation of how all this works.
DESCRIPTION
This plugin will add in the Catalyst::TraitFor::Request::StrongParameters request class trait and proxy some of its methods to the context. You might find this a bit less typing.
All the main documentation is in Catalyst::TraitFor::Request::StrongParameters.
NOTE: This plugin only works with For Catalyst v5.90090 or greater. If you must use an older version of Catalyst you'll need to use the workaround described in the SYNOPSIS of Catalyst::TraitFor::Request::StrongParameters.
METHODS
This role defines the following methods:
strong_body
strong_data
strong_query
These just proxy to the same methods under the Catalyst::Request object.
isa_strong_parameter_exception
This is just a convenience method that returns true if a possible exception is both a blessed object and ISA Catalyst::Exception::StrongParameter. Since you need to add checking for this everytime I added this method to save a bit of trouble.
AUTHOR
See Catalyst::TraitFor::Request::StrongParameters
SEE ALSO
Catalyst, Catalyst::TraitFor::Request::StrongParameters