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