blib/lib/Plack/Middleware/Auth/QueryString.pm

filter: Statementstmt 100% 31 / 31 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 50.0% 2 / 4 totaltotal 94.1% 48 / 51 CC 4 SCAR 4.8
CC
4
Cov
97%
prepare_app
3.0
call
2.0
BEGIN
1.0
CRAP 1.6
↑ Summary
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
BranchTrueFalseTotal
unless $self->key 1 1 2
16 2 ▶ die 'requires password' unless $self->password;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->password 0 2 2
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
BranchTrueFalseTotal
$self->validate($env) ? : 3 4 7
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__
↑ Summary