Catalyst::ActionRole::MatchRequestAccepts

Dispatch actions based on HTTP Accept Header
Download

Catalyst::ActionRole::MatchRequestAccepts Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • John Napiorkowski
  • Publisher web site:
  • http://search.cpan.org/~jjnapiork/

Catalyst::ActionRole::MatchRequestAccepts Tags


Catalyst::ActionRole::MatchRequestAccepts Description

Dispatch actions based on HTTP Accept Header Catalyst::ActionRole::MatchRequestAccepts is a Perl module that lets you specify a match for the HTTP Accept Header, which is provided by the Catalyst $ctx->request->headers object. You might wish to instead look at Catalyst::Action::REST if you are doing complex applications that match different incoming request types, but if you are very fussy about how your actions match, or if you are doing some simple ajaxy bits you might like to use this instead of a full on package (like Catalyst::Action::REST is.)Currently the match performed is a pure equalty, no attempt to guess or infer matches based on similarity are done. If you need to match several variations you can specify all the variations with multiple attribute declarations. Right now we don't support expression based matching, such as text/*, although adding such would probably not be very hard (although I don't want to make the logic here slow down our dispatch matching too much).Please note that if you specify multiple Accept attributes on a single action, those will be matched via an OR condition and not an AND condition. In other words we short circuit match the first action with at least one of the Accept values appearing in the requested HTTP headers. I think this is correct since I imagine the purpose of multiple Accept attributes would be to match several acceptable variations of a given type, not to match any of several unrelated types. However if you have a use case for this please let me know.If an action consumes this role, but no Accept attributes are found, the action will simple accept all types.For debugging purposes, if the Catalyst debug flag is enabled, you can override the HTTP Accept header with the http-accept query parameter. This makes it easy to force detect in testing or in your browser. This feature is NOT available when the debug flag is off.Also, as usual you can specify attributes and information in th configuration of your Catalyst::Controller subclass: __PACKAGE__->config( action_roles => , action => { our_action_json => { Path => 'json', Accept => 'JSON' }, });SYNOPSIS package MyApp::Controller::Foo; use Moose; use namespace::autoclean; BEGIN { extends 'Catalyst::Controller::ActionRole'; } __PACKAGE__->config( action_roles => , ); sub for_html : Path Accept('plain/html') { ... } sub for_json : Path Method('application/json') { ... } Requirements: · Perl


Catalyst::ActionRole::MatchRequestAccepts Related Software