| 1 | package OIDC::Client::User; | ||||||||||||
| 2 | 4 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 4 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use MooseX::Params::Validate; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 4 | ▶ | use List::Util qw(any); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | =encoding utf8 | ||||||||||||
| 10 | |||||||||||||
| 11 | =head1 NAME | ||||||||||||
| 12 | |||||||||||||
| 13 | OIDC::Client::User - User class | ||||||||||||
| 14 | |||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||
| 16 | |||||||||||||
| 17 | Class representing a user. | ||||||||||||
| 18 | |||||||||||||
| 19 | =cut | ||||||||||||
| 20 | |||||||||||||
| 21 | 4 | has 'login' => ( | |||||||||||
| 22 | is => 'ro', | ||||||||||||
| 23 | isa => 'Str', | ||||||||||||
| 24 | required => 1, | ||||||||||||
| 25 | ); | ||||||||||||
| 26 | |||||||||||||
| 27 | 4 | has 'lastname' => ( | |||||||||||
| 28 | is => 'ro', | ||||||||||||
| 29 | isa => 'Maybe[Str]', | ||||||||||||
| 30 | required => 0, | ||||||||||||
| 31 | ); | ||||||||||||
| 32 | |||||||||||||
| 33 | 4 | has 'firstname' => ( | |||||||||||
| 34 | is => 'ro', | ||||||||||||
| 35 | isa => 'Maybe[Str]', | ||||||||||||
| 36 | required => 0, | ||||||||||||
| 37 | ); | ||||||||||||
| 38 | |||||||||||||
| 39 | 4 | has 'email' => ( | |||||||||||
| 40 | is => 'ro', | ||||||||||||
| 41 | isa => 'Maybe[Str]', | ||||||||||||
| 42 | required => 0, | ||||||||||||
| 43 | ); | ||||||||||||
| 44 | |||||||||||||
| 45 | 4 | has 'roles' => ( | |||||||||||
| 46 | is => 'ro', | ||||||||||||
| 47 | isa => 'Maybe[ArrayRef[Str]]', | ||||||||||||
| 48 | required => 0, | ||||||||||||
| 49 | ); | ||||||||||||
| 50 | |||||||||||||
| 51 | 4 | has 'role_prefix' => ( | |||||||||||
| 52 | is => 'ro', | ||||||||||||
| 53 | isa => 'Maybe[Str]', | ||||||||||||
| 54 | required => 0, | ||||||||||||
| 55 | ); | ||||||||||||
| 56 | |||||||||||||
| 57 | 4 | has 'uo' => ( | |||||||||||
| 58 | is => 'ro', | ||||||||||||
| 59 | isa => 'Maybe[Str]', | ||||||||||||
| 60 | required => 0, | ||||||||||||
| 61 | ); | ||||||||||||
| 62 | |||||||||||||
| 63 | 4 | has 'title' => ( | |||||||||||
| 64 | is => 'ro', | ||||||||||||
| 65 | isa => 'Maybe[Str]', | ||||||||||||
| 66 | required => 0, | ||||||||||||
| 67 | ); | ||||||||||||
| 68 | |||||||||||||
| 69 | =head1 METHODS | ||||||||||||
| 70 | |||||||||||||
| 71 | =head2 has_role( $role_to_check ) | ||||||||||||
| 72 | |||||||||||||
| 73 | my $has_role = $user->has_role( $role ); | ||||||||||||
| 74 | |||||||||||||
| 75 | Returns whether the user has a specified role in his C<roles> attribute. | ||||||||||||
| 76 | |||||||||||||
| 77 | The C<role_prefix> attribute is used to avoid repeating a prefix common to | ||||||||||||
| 78 | the roles to check. | ||||||||||||
| 79 | |||||||||||||
| 80 | The list parameters are: | ||||||||||||
| 81 | |||||||||||||
| 82 | =over 2 | ||||||||||||
| 83 | |||||||||||||
| 84 | =item role_to_check | ||||||||||||
| 85 | |||||||||||||
| 86 | Role to check | ||||||||||||
| 87 | |||||||||||||
| 88 | =back | ||||||||||||
| 89 | |||||||||||||
| 90 | =cut | ||||||||||||
| 91 | |||||||||||||
| 92 | 7 | ▶ | sub has_role { | ||||||||||
|
Subroutine
has_role: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 93 | 7 | my $self = shift; | |||||||||||
| 94 | 7 | my ($role_to_check) = pos_validated_list(\@_, { isa => 'Str', optional => 0 }); | |||||||||||
| 95 | |||||||||||||
| 96 | 7 | ▶ | my $role_prefix = $self->role_prefix // ''; | ||||||||||
|
Condition100%2/2
$self->role_prefix // ""
MC/DC100%1/1
$self->role_prefix // ""
$self->role_prefix
Truth table100%2/2
A
A= $self->role_prefix
| |||||||||||||
| 97 | |||||||||||||
| 98 | 7 | ▶ | return any { $_ eq $role_prefix . $role_to_check } @{ $self->roles || [] }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Condition100%2/2
$self->roles || []
MC/DC100%1/1
$self->roles || []
$self->roles
Truth table100%2/2
A
A= $self->roles
| |||||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 102 | |||||||||||||
| 103 | 4 | 1; | |||||||||||