| 1 | package Articulate::Credentials; | ||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 10 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 10 | ▶ | use overload bool => sub { shift->accepted }, '0+' => sub { shift->rejected }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
Subroutine
__ANON__: not called CC=1 SCAR=0.6
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Articulate::Credentials - represent an authentication request/response | ||||||||||
| 11 | |||||||||||
| 12 | =cut | ||||||||||
| 13 | |||||||||||
| 14 | =head1 FUNCTIONS | ||||||||||
| 15 | |||||||||||
| 16 | =head3 credentials | ||||||||||
| 17 | |||||||||||
| 18 | my $credentials = credentials $user_id, $password; | ||||||||||
| 19 | my $credentials = credentials { email => $email, api_key => $key }; | ||||||||||
| 20 | |||||||||||
| 21 | Creates a new request, using the user_id and password supplied as the respective arguments; or other fields if they are supplied instead. | ||||||||||
| 22 | |||||||||||
| 23 | =cut | ||||||||||
| 24 | |||||||||||
| 25 | 10 | ▶ | use Exporter::Declare; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 10 | default_exports qw(credentials); | |||||||||
| 27 | |||||||||||
| 28 | sub credentials { | ||||||||||
| 29 | 0 | ▶ | return shift if ref $_[0] eq __PACKAGE__; | ||||||||
|
Subroutine
credentials: not called CC=3 SCAR=24.8
Pod
documented
Branch: 1 branch
| |||||||||||
| 30 | 0 | ▶ | __PACKAGE__->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | { | ||||||||||
| 32 | fields => ( | ||||||||||
| 33 | ( ref $_[0] eq ref {} ) | ||||||||||
| 34 | ? $_[0] | ||||||||||
| 35 | : { | ||||||||||
| 36 | user_id => shift, | ||||||||||
| 37 | password => shift, | ||||||||||
| 38 | } | ||||||||||
| 39 | ), | ||||||||||
| 40 | } | ||||||||||
| 41 | ); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | =head1 METHODS | ||||||||||
| 45 | |||||||||||
| 46 | =head3 new | ||||||||||
| 47 | |||||||||||
| 48 | An unremarkable Moo constructor. | ||||||||||
| 49 | |||||||||||
| 50 | =cut | ||||||||||
| 51 | |||||||||||
| 52 | =head3 accept | ||||||||||
| 53 | |||||||||||
| 54 | $credentials->accept('Password matched'); | ||||||||||
| 55 | |||||||||||
| 56 | Declares that the credentials are valid, for the reason given; sets C<accpeted> and C<rejected> and populates the stack trace. | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | |||||||||||
| 60 | sub accept { | ||||||||||
| 61 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
accept: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 62 | 0 | my $reason = shift; | |||||||||
| 63 | |||||||||||
| 64 | # die if granted or denied are already set? | ||||||||||
| 65 | 0 | $self->accepted(1); | |||||||||
| 66 | 0 | $self->reason($reason); | |||||||||
| 67 | 0 | $self->stack_trace( Devel::StackTrace->new ); | |||||||||
| 68 | 0 | return $self; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =head3 reject | ||||||||||
| 72 | |||||||||||
| 73 | $credentials->reject('User not found'); | ||||||||||
| 74 | |||||||||||
| 75 | Declares that the credentials are invalid, for the reason given; sets C<accpeted> and C<rejected> and populates the stack trace. | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | sub reject { | ||||||||||
| 80 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
reject: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 81 | 0 | my $reason = shift; | |||||||||
| 82 | |||||||||||
| 83 | # die if granted or denied are already set? | ||||||||||
| 84 | 0 | $self->accepted(0); | |||||||||
| 85 | 0 | $self->rejected(1); | |||||||||
| 86 | 0 | $self->reason($reason); | |||||||||
| 87 | 0 | $self->stack_trace( Devel::StackTrace->new ); | |||||||||
| 88 | 0 | return $self; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | =head1 ATTRIBUTES | ||||||||||
| 92 | |||||||||||
| 93 | =head3 fields | ||||||||||
| 94 | |||||||||||
| 95 | The credentials provided, typically user_id and password. | ||||||||||
| 96 | |||||||||||
| 97 | =cut | ||||||||||
| 98 | |||||||||||
| 99 | has fields => ( | ||||||||||
| 100 | is => 'rw', | ||||||||||
| 101 | 0 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 102 | 10 | ); | |||||||||
| 103 | |||||||||||
| 104 | =head3 accepted | ||||||||||
| 105 | |||||||||||
| 106 | Whether or not the credentials have been explicitly accepted. The value of this is used for overload behaviour. | ||||||||||
| 107 | |||||||||||
| 108 | Please do not explicitly set this. Use C<accept> instead. | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||
| 111 | |||||||||||
| 112 | has accepted => ( | ||||||||||
| 113 | is => 'rw', | ||||||||||
| 114 | 0 | ▶ | default => sub { 0 }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 115 | 10 | ); | |||||||||
| 116 | |||||||||||
| 117 | =head3 rejected | ||||||||||
| 118 | |||||||||||
| 119 | Whether the credentials have been explicitly rejected. | ||||||||||
| 120 | |||||||||||
| 121 | Please do not explicitly set this. Use C<reject> instead. | ||||||||||
| 122 | |||||||||||
| 123 | =cut | ||||||||||
| 124 | |||||||||||
| 125 | has rejected => ( | ||||||||||
| 126 | is => 'rw', | ||||||||||
| 127 | 0 | ▶ | default => sub { 0 }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 128 | 10 | ); | |||||||||
| 129 | |||||||||||
| 130 | =head3 reason | ||||||||||
| 131 | |||||||||||
| 132 | The reason for the acceptance or rejection of credentials. | ||||||||||
| 133 | |||||||||||
| 134 | Please do not explicitly set this. Use C<accept> or C<reject> instead. | ||||||||||
| 135 | |||||||||||
| 136 | =cut | ||||||||||
| 137 | |||||||||||
| 138 | has reason => ( | ||||||||||
| 139 | is => 'rw', | ||||||||||
| 140 | 0 | ▶ | default => sub { '' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 141 | 10 | ); | |||||||||
| 142 | |||||||||||
| 143 | =head3 stack_trace | ||||||||||
| 144 | |||||||||||
| 145 | The stack trace at the point of acceptance or rejection of credentials. | ||||||||||
| 146 | |||||||||||
| 147 | Please do not explicitly set this. Use C<accept> or C<reject> instead. | ||||||||||
| 148 | |||||||||||
| 149 | =cut | ||||||||||
| 150 | |||||||||||
| 151 | has stack_trace => ( | ||||||||||
| 152 | is => 'rw', | ||||||||||
| 153 | 0 | ▶ | default => sub { '' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 154 | 10 | ); | |||||||||
| 155 | |||||||||||
| 156 | =head1 SEE ALSO | ||||||||||
| 157 | |||||||||||
| 158 | =over | ||||||||||
| 159 | |||||||||||
| 160 | =item * L<Articulate::Authentication> | ||||||||||
| 161 | |||||||||||
| 162 | =item * L<Articulate::Permission> (which performs a similar function for L<Articulate::Authorisation>) | ||||||||||
| 163 | |||||||||||
| 164 | =back | ||||||||||
| 165 | |||||||||||
| 166 | =cut | ||||||||||
| 167 | |||||||||||
| 168 | 10 | 1; | |||||||||