line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Credentials; |
2
|
11
|
|
|
11
|
|
47
|
use strict; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
362
|
|
3
|
11
|
|
|
11
|
|
48
|
use warnings; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
230
|
|
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
39
|
use Moo; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
85
|
|
6
|
11
|
|
|
11
|
|
3352
|
use overload bool => sub { shift->accepted }, '0+' => sub { shift->rejected }; |
|
11
|
|
|
0
|
|
19
|
|
|
11
|
|
|
|
|
131
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
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
|
|
|
11
|
|
739
|
use Exporter::Declare; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
66
|
|
27
|
|
|
|
|
|
|
default_exports qw(new_credentials); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new_credentials { |
30
|
0
|
0
|
|
0
|
1
|
|
return shift if ref $_[0] eq __PACKAGE__; |
31
|
0
|
0
|
|
|
|
|
__PACKAGE__->new( |
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 and C and populates the stack trace. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub accept { |
63
|
0
|
|
|
0
|
1
|
|
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 and C and populates the stack trace. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub reject { |
83
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
default => sub { {} }, |
105
|
|
|
|
|
|
|
); |
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 instead. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
has accepted => ( |
117
|
|
|
|
|
|
|
is => 'rw', |
118
|
|
|
|
|
|
|
default => sub { 0 }, |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head3 rejected |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Whether the credentials have been explicitly rejected. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Please do not explicitly set this. Use C instead. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
has rejected => ( |
130
|
|
|
|
|
|
|
is => 'rw', |
131
|
|
|
|
|
|
|
default => sub { 0 }, |
132
|
|
|
|
|
|
|
); |
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 or C instead. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
has reason => ( |
143
|
|
|
|
|
|
|
is => 'rw', |
144
|
|
|
|
|
|
|
default => sub { '' }, |
145
|
|
|
|
|
|
|
); |
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 or C instead. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
has stack_trace => ( |
156
|
|
|
|
|
|
|
is => 'rw', |
157
|
|
|
|
|
|
|
default => sub { '' }, |
158
|
|
|
|
|
|
|
); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=over |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * L |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * L (which performs a similar function for L) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=back |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |