| 1 | package Plack::Middleware::Auth::QueryString; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | our $VERSION = '0.02'; | |||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use parent qw/Plack::Middleware/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use Plack::Util::Accessor qw/key password/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Plack::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | sub prepare_app { | ||||||||
|
Subroutine
prepare_app: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 13 | 2 | my $self = shift; | |||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | $self->key('key') unless $self->key; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 2 | ▶ | die 'requires password' unless $self->password; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 7 | ▶ | sub call { | ||||||||
|
Subroutine
call: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 20 | 7 | my ($self, $env) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 7 | ▶ | return $self->validate($env) ? $self->app->($env) : $self->unauthorized; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 7 | ▶ | sub validate { | ||||||||
|
Subroutine
validate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 26 | 7 | my ($self, $env) = @_; | |||||||||
| 27 | |||||||||||
| 28 | 7 | my $req = Plack::Request->new($env); | |||||||||
| 29 | 7 | $req->query_parameters->get($self->key) ~~ $self->password; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 4 | ▶ | sub unauthorized { | ||||||||
|
Subroutine
unauthorized: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 33 | 4 | my $self = shift; | |||||||||
| 34 | |||||||||||
| 35 | 4 | my $body = 'Authorization required'; | |||||||||
| 36 | return [ | ||||||||||
| 37 | 4 | 401, | |||||||||
| 38 | [ | ||||||||||
| 39 | 'Content-Type' => 'text/plain', | ||||||||||
| 40 | 'Content-Lentgth' => length $body, | ||||||||||
| 41 | ], | ||||||||||
| 42 | [$body], | ||||||||||
| 43 | ]; | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 2 | 1; | |||||||||
| 47 | __END__ | ||||||||||