File Coverage

blib/lib/CatalystX/SimpleLogin/TraitFor/Controller/Login/Logout.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 33 33 100.0


line stmt bran cond sub pod time code
1             package CatalystX::SimpleLogin::TraitFor::Controller::Login::Logout;
2 8     8   39174 use MooseX::MethodAttributes::Role;
  8         34  
  8         85  
3 8     8   215450 use MooseX::Types::Moose qw/Str Bool/;
  8         22  
  8         90  
4 8     8   37153 use namespace::autoclean;
  8         21  
  8         77  
5              
6             sub logout : Chained('/') PathPart('logout') Args(0) {
7 7     7 1 790452 my ($self, $c) = @_;
8 7         77 $c->logout;
9 7         30820 $c->change_session_id;
10 7 100       24037 $self->do_clear_session_on_logout($c) if $self->clear_session_on_logout;
11 7         4786 $c->res->redirect($self->redirect_after_logout_uri($c));
12 8     8   1256 }
  8         22  
  8         75  
13              
14             has clear_session_on_logout => (
15             isa => Bool,
16             is => 'ro',
17             default => 0,
18             );
19              
20             sub do_clear_session_on_logout {
21 1     1 1 4 my ($self, $c) = @_;
22 1         12 $c->delete_session;
23             }
24              
25             sub redirect_after_logout_uri {
26 7     7 1 228 my ($self, $c) = @_;
27 7         243 $c->uri_for($self->_redirect_after_logout_uri);
28             }
29             has _redirect_after_logout_uri => (
30             isa => Str,
31             default => '/',
32             init_arg => 'redirect_after_logout_uri',
33             is => 'ro',
34             );
35              
36             1;
37              
38             =head1 NAME
39              
40             CatalystX::SimpleLogin::TraitFor::Controller::Login::Logout - log users out
41              
42             =head1 DESCRIPTION
43              
44             Simple controller role for logging users out. Provides a
45             C<logout> action (at /logout by default) which redirects
46             the user to the homepage by default.
47              
48             =head1 ACTIONS
49              
50             =head2 logout : Chained('/') PathPart('logout') Args(0)
51              
52             Calls C<< $c->logout >>, then redirects to the logout uri
53             retuned by C<< $self->redirect_after_logout_uri >>.
54              
55             =head1 METHODS
56              
57             =head2 redirect_after_logout_uri
58              
59             Returns the uri to redirect to after logout.
60              
61             Defaults to C<< $c->uri_for('/'); >> you can override this
62             by setting the C<<redirect_after_logout_uri>> key in config
63             to a path to be passed to C<< $c->uri_for >>.
64              
65             Alternatively, you can write your own redirect_after_logout_uri
66             in your Login controller if you are extending CatalystX::SimpleLogin
67             and it will override the method from this role.
68              
69             =head2 do_clear_session_on_logout
70              
71             Deletes the session after a logout.
72              
73             To enable this use the following in your config:
74             __PACKAGE__->config('Controller::Login' => { clear_session_on_logout => 1 });
75              
76             =head1 SEE ALSO
77              
78             =over
79              
80             =item L<CatalystX::SimpleLogin::Controller::Login>
81              
82             =back
83              
84             =head1 AUTHORS
85              
86             See L<CatalystX::SimpleLogin> for authors.
87              
88             =head1 LICENSE
89              
90             See L<CatalystX::SimpleLogin> for license.
91              
92             =cut
93