Cataly...Scheme(3pm)

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

πŸ’– Cataly...Scheme(3pm) β€” aka Catalyst::ActionRole::Scheme πŸ’–

okay so bestie, welcome to the Catalyst::ActionRole::Scheme page from the User Contributed Perl Documentation, and no I will not be normal about it. This is a Perl manpage, it's a whole vibe, and by the end of this you're gonna know exactly how to make your Catalyst actions picky about http vs https and honestly? iconic. πŸŽ€


✨ NAME ✨

Catalyst::ActionRole::Scheme β€” Match on HTTP Request Scheme πŸ¦‹


🌸 SYNOPSIS 🌸

here's the whole thing, verbatim, because it's giving art:

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

use base 'Catalyst::Controller';

sub is_http :Path(scheme) Scheme(http) Args(0) {
  my ($self, $c) = @_;
  Test::More::is $c->action->scheme, 'http';
  $c->response->body("is_http");
}

sub is_https :Path(scheme) Scheme(https) Args(0)  {
  my ($self, $c) = @_;
  Test::More::is $c->action->scheme, 'https';
  $c->response->body("is_https");
}

1;

like look at that. two subs. one for each scheme. the attribute does all the heavy lifting. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So this is an action role that lets your Catalyst::Action match on the scheme type of the request. Lowkey the whole point.

Typically that's "http" or "https", but other common schemes Catalyst can handle include "ws" and "wss" β€” that's web socket and web socket secure, for the record. slay. 🌈

It also does this extra cute thing: if you use uri_for on an action that specifies a match scheme, the generated URI object sets its scheme to that automatically. Like, automatically automatically. Instead of doing what it would normally do and using the scheme of the current request object. Which, for the record, is and remains the default behavior. So don't come for me, I'm just telling you what the docs say. πŸ™ˆ

And for matching purposes? We match strings, but the casing is insensitive. So HTTP and http are the same girl. periodt. πŸ‘‘


πŸŽ€ REQUIRES πŸŽ€

This role needs the following methods to exist in the consuming class. (Translation: your class gotta bring these to the party, bestie.) πŸ’–

πŸ“ match

πŸ“ match_captures

Returns 1 if the action matches the existing request and zero if not. that's it. that's the whole job. 🫢


πŸ’œ METHODS πŸ’œ

This role defines the following methods. Buckle up, there's three. ⭐

🌟 match

🌟 match_captures

An around method modifier that returns 1 if the scheme matches. πŸ’…

🌟 list_extra_info

Adds the scheme declaration β€” if there is one β€” to the debug screen. cute little debug moment, honestly. πŸ”₯


πŸ‘‘ AUTHORS πŸ‘‘

Catalyst Contributors, see Catalyst. 🫢


See Catalyst. πŸ’œ


and that's the whole page, bestie!! this bad boy came from perl v5.40.0 and is dated 2024-11-15, and yes it's still out here living its best life as Cataly...Scheme(3pm). no cap. go forth and scheme-match. 🧚✨🌸

πŸ“¦ where this page comes from