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