| 1 | package Catalyst::ActionRole::Scheme; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 2 | requires 'match', 'match_captures', 'list_extra_info'; | |||||||||||
| 6 | |||||||||||||
| 7 | 11 | ▶ | around ['match','match_captures'] => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||
| 8 | 11 | my ($orig, $self, $ctx, @args) = @_; | |||||||||||
| 9 | 11 | my $request_scheme = lc($ctx->req->env->{'psgi.url_scheme'}); | |||||||||||
| 10 | 11 | ▶ | my $match_scheme = lc($self->scheme||''); | ||||||||||
|
Condition50%1/2
$self->scheme || ''
MC/DC0%0/1
$self->scheme || ''
$self->scheme
Truth table50%1/2
A
A= $self->scheme
| |||||||||||||
| 11 | |||||||||||||
| 12 | 11 | ▶ | return $request_scheme eq $match_scheme ? $self->$orig($ctx, @args) : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 13 | 2 | }; | |||||||||||
| 14 | |||||||||||||
| 15 | 0 | ▶ | around 'list_extra_info' => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 16 | 0 | my ($orig, $self, @args) = @_; | |||||||||||
| 17 | return { | ||||||||||||
| 18 | 0 | ▶ | %{ $self->$orig(@args) }, | ||||||||||
|
Condition0%0/2
$self->attributes->{'Scheme'}[0] || ''
MC/DC0%0/1
$self->attributes->{'Scheme'}[0] || ''
$self->attributes->{'Scheme'}[0]
Truth table0%0/2
A
A= $self->attributes->{'Scheme'}[0]
| |||||||||||||
| 19 | 0 | Scheme => $self->attributes->{Scheme}[0]||'', | |||||||||||
| 20 | }; | ||||||||||||
| 21 | 2 | }; | |||||||||||
| 22 | |||||||||||||
| 23 | 2 | 1; | |||||||||||
| 24 | |||||||||||||
| 25 | =head1 NAME | ||||||||||||
| 26 | |||||||||||||
| 27 | Catalyst::ActionRole::Scheme - Match on HTTP Request Scheme | ||||||||||||
| 28 | |||||||||||||
| 29 | =head1 SYNOPSIS | ||||||||||||
| 30 | |||||||||||||
| 31 | package MyApp::Web::Controller::MyController; | ||||||||||||
| 32 | |||||||||||||
| 33 | use base 'Catalyst::Controller'; | ||||||||||||
| 34 | |||||||||||||
| 35 | sub is_http :Path(scheme) Scheme(http) Args(0) { | ||||||||||||
| 36 | my ($self, $c) = @_; | ||||||||||||
| 37 | Test::More::is $c->action->scheme, 'http'; | ||||||||||||
| 38 | $c->response->body("is_http"); | ||||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | sub is_https :Path(scheme) Scheme(https) Args(0) { | ||||||||||||
| 42 | my ($self, $c) = @_; | ||||||||||||
| 43 | Test::More::is $c->action->scheme, 'https'; | ||||||||||||
| 44 | $c->response->body("is_https"); | ||||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 1; | ||||||||||||
| 48 | |||||||||||||
| 49 | =head1 DESCRIPTION | ||||||||||||
| 50 | |||||||||||||
| 51 | This is an action role that lets your L<Catalyst::Action> match on the scheme | ||||||||||||
| 52 | type of the request. Typically this is C<http> or C<https> but other common | ||||||||||||
| 53 | schemes that L<Catalyst> can handle include C<ws> and C<wss> (web socket and web | ||||||||||||
| 54 | socket secure). | ||||||||||||
| 55 | |||||||||||||
| 56 | This also ensures that if you use C<uri_for> on an action that specifies a | ||||||||||||
| 57 | match scheme, that the generated L<URI> object sets its scheme to that automatically | ||||||||||||
| 58 | (rather than the scheme of the current request object, which is and remains the | ||||||||||||
| 59 | default behavior.) | ||||||||||||
| 60 | |||||||||||||
| 61 | For matching purposes, we match strings but the casing is insensitive. | ||||||||||||
| 62 | |||||||||||||
| 63 | =head1 REQUIRES | ||||||||||||
| 64 | |||||||||||||
| 65 | This role requires the following methods in the consuming class. | ||||||||||||
| 66 | |||||||||||||
| 67 | =head2 match | ||||||||||||
| 68 | |||||||||||||
| 69 | =head2 match_captures | ||||||||||||
| 70 | |||||||||||||
| 71 | Returns 1 if the action matches the existing request and zero if not. | ||||||||||||
| 72 | |||||||||||||
| 73 | =head1 METHODS | ||||||||||||
| 74 | |||||||||||||
| 75 | This role defines the following methods | ||||||||||||
| 76 | |||||||||||||
| 77 | =head2 match | ||||||||||||
| 78 | |||||||||||||
| 79 | =head2 match_captures | ||||||||||||
| 80 | |||||||||||||
| 81 | Around method modifier that return 1 if the scheme matches | ||||||||||||
| 82 | |||||||||||||
| 83 | =head2 list_extra_info | ||||||||||||
| 84 | |||||||||||||
| 85 | Add the scheme declaration if present to the debug screen. | ||||||||||||
| 86 | |||||||||||||
| 87 | =head1 AUTHORS | ||||||||||||
| 88 | |||||||||||||
| 89 | Catalyst Contributors, see L<Catalyst> | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 COPYRIGHT | ||||||||||||
| 92 | |||||||||||||
| 93 | See L<Catalyst> | ||||||||||||
| 94 | |||||||||||||
| 95 | =cut | ||||||||||||