File Coverage

blib/lib/Plack/Middleware/DoormanAuthentication.pm
Criterion Covered Total %
statement 26 26 100.0
branch 6 6 100.0
condition 4 6 66.6
subroutine 7 7 100.0
pod 2 2 100.0
total 45 47 95.7


line stmt bran cond sub pod time code
1             package Plack::Middleware::DoormanAuthentication;
2 2     2   4081 use 5.010;
  2         6  
3 2     2   10 use strict;
  2         3  
  2         95  
4              
5             our $VERSION = "0.06";
6             our $AUTHORITY = "http://gugod.org";
7              
8 2     2   739 use parent 'Doorman::PlackMiddleware';
  2         290  
  2         10  
9              
10 2     2   87 use Plack::Util::Accessor qw(authenticator);
  2         3  
  2         9  
11 2     2   72 use Plack::Session;
  2         5  
  2         404  
12              
13             sub is_sign_in {
14 6     6 1 75 $_[0]->session_get("authenticated");
15             }
16              
17             sub call {
18 6     6 1 110006 my ($self, $env) = @_;
19              
20 6         26 $self->prepare_call($env);
21              
22 6         25 $env->{ $self->fq } = $self;
23              
24 6         61 my $request = Plack::Request->new($env);
25              
26 6 100 66     52 if ($request->method eq 'POST' and $request->path eq $self->sign_in_path) {
    100 66        
27 2         152 my ($success, $error_message) = $self->authenticator->($self, $self->{env});
28 2 100       1259 if ($success) {
29 1         8 $self->session_set("authenticated" => $success);
30             }
31             else {
32 1         13 $self->env_set("error" => $error_message);
33             }
34             }
35             elsif ($request->method eq 'GET' and $request->path eq $self->sign_out_path) {
36 1         80 $self->session_remove("authenticated");
37             }
38              
39 6         302 return $self->app->($env);
40             }
41              
42             1;
43              
44             __END__