Articulate/Permission.pm

filter: Statementstmt 78.0% 39 / 50 Branchbran n/a Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 72.2% 13 / 18 Podpod 100% 3 / 3 totaltotal 78.3% 58 / 74 CC 2 SCAR 2.8
CC
2
Cov
79%
new_permission
2.0
deny
2.0
__ANON__
2.0
CRAP 1.3
« Articulate/FrameworkAdapter.pm ↑ Summary Articulate/Role/Component.pm »
1 package Articulate::Permission;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Devel::StackTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶use overload bool => sub { shift->granted }, '0+' => sub { shift->granted };
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine __ANON__: called CC=1 SCAR=0.1
Subroutine __ANON__: not called CC=1 SCAR=0.1
9  
10 =head1 NAME
11  
12 Articulate::Permission - represent a permission request/response
13  
14 =cut
15  
16 =head1 FUNCTIONS
17  
18 =head3 new_permission
19  
20 my $permission = new_permission $user, verb => $location;
21  
22 Creates a new permission request, using the user, verb and location
23 supplied as the respective arguments.
24  
25 =cut
26  
27 13 ▶use Exporter::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 13 default_exports qw(new_permission);
29  
30 7 ▶sub new_permission {
Subroutine new_permission: called CC=2 SCAR=6.9
Pod documented
31 7 ▶ __PACKAGE__->new(
Condition100%2/2
shift() // "[guest]"
l!l
34
MC/DC100%1/1
shift() // "[guest]"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
32 {
33 user_id => shift // '[guest]',
34 verb => shift,
35 location => shift
36 }
37 );
38 }
39  
40 =head1 METHODS
41  
42 =head3 new
43  
44 An unremarkable Moo constructor.
45  
46 =cut
47  
48 =head3 grant
49  
50 $permission->grant('Anybody can do that!');
51  
52 Declares that the user has that permission, for the reason given; sets
53 C<granted> and C<denied> and populates the stack trace.
54  
55 =cut
56  
57 6 ▶sub grant {
Subroutine grant: called CC=1 SCAR=0.0
Pod documented
58 6 my $self = shift;
59 6 my $reason = shift;
60  
61 # die if granted or denied are already set?
62 6 $self->granted(1);
63 6 $self->reason($reason);
64 6 $self->stack_trace( Devel::StackTrace->new );
65 6 return $self;
66 }
67  
68 =head3 deny
69  
70 $permission->deny('Don\t touch that!');
71  
72 Declares that the user does not have that permission, for the reason
73 given; sets C<granted> and C<denied> and populates the stack trace.
74  
75 =cut
76  
77 0 ▶sub deny {
Subroutine deny: not called CC=1 SCAR=6.9
Pod documented
78 0 my $self = shift;
79 0 my $reason = shift;
80  
81 # die if granted or denied are already set?
82 0 $self->granted(0);
83 0 $self->denied(1);
84 0 $self->reason($reason);
85 0 $self->stack_trace( Devel::StackTrace->new );
86 0 return $self;
87 }
88  
89 =head1 ATTRIBUTES
90  
91 =head3 user_id
92  
93 The user_id requesting permission to access the resource.
94  
95 =cut
96  
97 has user_id => (
98 is => 'rw',
99 0 ▶ default => sub { undef },
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 13 );
101  
102 =head3 verb
103  
104 The action being performed, e.g. C<read>, C<write>, etc. The verbs
105 available are entirely dependant on the application.
106  
107 A permission request will be granted or denied by an authorisation rule
108 (see Articulate::Authorisation), who will typically implement verbs
109 that bay be different from but are either a) broader than, or b)
110 equally broad as, the verbs used by the Articulate::Service.
111  
112 =cut
113  
114 has verb => (
115 is => 'rw',
116 0 ▶ default => sub { 'error' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 13 );
118  
119 =head3 location
120  
121 The location of the resource for which permission is requested.
122  
123 =cut
124  
125 has location => (
126 is => 'rw',
127 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
128 13 );
129  
130 =head3 granted
131  
132 Whether or not the permission has been explicitly granted. The value of
133 this is used for overload behaviour.
134  
135 Please do not explicitly set this. Use C<grant> instead.
136  
137 =cut
138  
139 has granted => (
140 is => 'rw',
141 7 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
142 13 );
143  
144 =head3 denied
145  
146 Whether the permission has been explicitly denied.
147  
148 Please do not explicitly set this. Use C<deny> instead.
149  
150 =cut
151  
152 has denied => (
153 is => 'rw',
154 7 ▶ default => sub { 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
155 13 );
156  
157 =head3 reason
158  
159 The reason for the grant or denial of permission.
160  
161 Please do not explicitly set this. Use C<grant> or C<deny> instead.
162  
163 =cut
164  
165 has reason => (
166 is => 'rw',
167 7 ▶ default => sub { '' }
Subroutine __ANON__: called CC=1 SCAR=0.0
168 13 );
169  
170 =head3 stack_trace
171  
172 The stack trace at the point of grant or denial of permission.
173  
174 Please do not explicitly set this. Use C<grant> or C<deny> instead.
175  
176 =cut
177  
178 has stack_trace => (
179 is => 'rw',
180 7 ▶ default => sub { '' }
Subroutine __ANON__: called CC=1 SCAR=0.0
181 13 );
182  
183 =head1 SEE ALSO
184  
185 =over
186  
187 =item * L<Articulate::Authorisation>
188  
189 =item * L<Articulate::Credentials> (which performs a similar function for L<Articulate::Authentication>)
190  
191 =back
192  
193 =cut
194  
195 13 1;
« Articulate/FrameworkAdapter.pm ↑ Summary Articulate/Role/Component.pm »