Cataly...Methods(3pm)

πŸ“¦
version 5.90132 Β· 6 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸŽ€ Catalyst::ActionRole::HTTPMethods πŸ’…

okay so this is Catalyst::ActionRole::HTTPMethods, from the User Contributed Perl Documentation, and bestie it's literally just about matching HTTP methods. that's it. that's the whole vibe. ✨


✨ NAME ✨

Catalyst::ActionRole::HTTPMethods β€” Match on HTTP Methods πŸ¦‹


🌸 SYNOPSIS 🌸

package MyApp::Web::Controller::MyController;

use Moose;
use MooseX::MethodAttributes;

extends 'Catalyst::Controller';

sub user_base : Chained('/') CaptureArg(0) { ... }

  sub get_user     : Chained('user_base') Args(1) GET { ... }
  sub post_user    : Chained('user_base') Args(1) POST { ... }
  sub put_user     : Chained('user_base') Args(1) PUT { ... }
  sub delete_user  : Chained('user_base') Args(1) DELETE { ... }
  sub head_user    : Chained('user_base') Args(1) HEAD { ... }
  sub options_user : Chained('user_base') Args(1) OPTIONS { ... }
  sub patch_user   : Chained('user_base') Args(1) PATCH { ... }

  sub post_and_put : Chained('user_base') POST PUT Args(1) { ... }
  sub method_attr  : Chained('user_base') Method('DELETE') Args(0) { ... }

__PACKAGE__->meta->make_immutable;

πŸ’– DESCRIPTION πŸ’–

so this is an action role that lets your Catalyst::Action match on standard HTTP methods β€” you know, the GET, POST etc. of it all. iconic behavior fr fr. πŸ‘‘

now, since most web browsers have limited support for rich HTTP Method vocabularies (they're not slaying in that department, sadly), we use Plack::Middleware::MethodOverride, which lets you 'tunnel' your request method over POST. this works in two ways, bestie, listen up:

  • you can set an extension HTTP header X-HTTP-Method-Override whose value is the desired request method
  • or you can set a search query parameter x-tunneled-method
🚨 important reminder: these only work over HTTP Request type POST. no cap. see Plack::Middleware::MethodOverride for more.

🧚 REQUIRES 🧚

this role requires the following methods in the consuming class, so your class better bring them or it's not eating at this table πŸ’…

match

match_captures

returns 1 if the action matches the existing request, and 0 if it does not. simple as that. ⭐


🌈 METHODS 🌈

this role defines the following methods:

match

match_captures

an around method modifier that returns 1 if the request method matches one of the allowed methods (see "http_methods") and 0 otherwise. 🫢

allowed_http_methods

an array of strings β€” the allowed http methods for matching this action, normalized as noted above (using X-Method* overrides). πŸ’œ

list_extra_info

adds a key => [@values] "HTTP_METHODS" to the ->list_extra_info HashRef, whose value is an ArrayRef of sorted allowed methods. this is used primarily for debugging output, so it's giving very much "for the developers only" energy πŸ”

_has_expected_http_method ($expected)

private method which returns 1 if $expected matches one of the allowed in "http_methods" and 0 otherwise. don't touch it, it's shy πŸ™ˆ


πŸ‘‘ AUTHORS πŸ‘‘

Catalyst Contributors, see Catalyst.pm


this library is free software. you can redistribute it and/or modify it under the same terms as Perl itself. slay, legally speaking. βš–οΈβœ¨


perl v5.40.0 Β· 2024-11-15 β€” and that's the whole page bestie, tysm for reading, go forth and match those methods πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from