NAME

Catalyst::Plugin::StructuredParameters - Plug to add the structured parameter request trait plus proxy methods

SYNOPSIS

package MyApp;
use Catalyst 'StructuredParameters';

MyApp->setup;

package MyApp::Controller::Root;

sub body :Local {
  my ($self, $c) = @_;
  my %clean = $c->structured_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.
    }
  }
}

## Alternatively handle with L<CatalystX::Errors> (don't forget to add the plugin to your 
## application class.)

sub end :Action Does(RenderErrors) { }

You should review Catalyst::TraitFor::Request::StructuredParameters for a more detailed SYNOPSIS and explanation of how all this works.

DESCRIPTION

This plugin will add in the Catalyst::TraitFor::Request::StructuredParameters 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::StructuredParameters.

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::StructuredParameters.

METHODS

This role defines the following methods:

structured_body

structured_data

structured_query

These just proxy to the same methods under the Catalyst::Request object.

isa_structured_parameter_exception

This is just a convenience method that returns true if a possible exception is both a blessed object and ISA Catalyst::Exception::StructuredParameter. Since you need to add checking for this everytime I added this method to save a bit of trouble.

AUTHOR

See Catalyst::TraitFor::Request::StructuredParameters

SEE ALSO

Catalyst, Catalyst::TraitFor::Request::StructuredParameters

COPYRIGHT & LICENSE

See Catalyst::TraitFor::Request::StructuredParameters