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