File Coverage

blib/lib/OIDC/Client/User.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 7 7 100.0
pod 1 1 100.0
total 33 33 100.0


line stmt bran cond sub pod time code
1             package OIDC::Client::User;
2 3     3   393921 use utf8;
  3         307  
  3         23  
3 3     3   610 use Moose;
  3         529209  
  3         31  
4 3     3   24678 use MooseX::Params::Validate;
  3         96592  
  3         28  
5 3     3   2468 use namespace::autoclean;
  3         8620  
  3         36  
6              
7 3     3   404 use List::Util qw(any);
  3         6  
  3         1229  
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             has 'login' => (
22             is => 'ro',
23             isa => 'Str',
24             required => 1,
25             );
26              
27             has 'lastname' => (
28             is => 'ro',
29             isa => 'Maybe[Str]',
30             required => 0,
31             );
32              
33             has 'firstname' => (
34             is => 'ro',
35             isa => 'Maybe[Str]',
36             required => 0,
37             );
38              
39             has 'email' => (
40             is => 'ro',
41             isa => 'Maybe[Str]',
42             required => 0,
43             );
44              
45             has 'roles' => (
46             is => 'ro',
47             isa => 'Maybe[ArrayRef[Str]]',
48             required => 0,
49             );
50              
51             has 'role_prefix' => (
52             is => 'ro',
53             isa => 'Maybe[Str]',
54             required => 0,
55             );
56              
57             has 'uo' => (
58             is => 'ro',
59             isa => 'Maybe[Str]',
60             required => 0,
61             );
62              
63             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             sub has_role {
93 5     5 1 708 my $self = shift;
94 5         27 my ($role_to_check) = pos_validated_list(\@_, { isa => 'Str', optional => 0 });
95              
96 5   100     1148 my $role_prefix = $self->role_prefix // '';
97              
98 5 100   8   19 return any { $_ eq $role_prefix . $role_to_check } @{ $self->roles || [] };
  8         21  
  5         113  
99             }
100              
101             __PACKAGE__->meta->make_immutable;
102              
103             1;