| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# This code is part of Perl distribution User-Identity version 4.00. |
|
2
|
|
|
|
|
|
|
# The POD got stripped from this file by OODoc version 3.05. |
|
3
|
|
|
|
|
|
|
# For contributors see file ChangeLog. |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# This software is copyright (c) 2003-2025 by Mark Overmeer. |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
|
9
|
|
|
|
|
|
|
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package User::Identity::Collection;{ |
|
13
|
|
|
|
|
|
|
our $VERSION = '4.00'; |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
688
|
use parent 'User::Identity::Item'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
17
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
73
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
28
|
|
|
19
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
94
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
7
|
use Log::Report 'user-identity'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
1280
|
use User::Identity (); |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
21
|
|
|
24
|
1
|
|
|
1
|
|
710
|
use Hash::Ordered (); |
|
|
1
|
|
|
|
|
2541
|
|
|
|
1
|
|
|
|
|
22
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
5
|
use List::Util qw/first/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
96
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#-------------------- |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use overload '""' => sub { |
|
31
|
25
|
|
|
25
|
|
1759
|
my $self = shift; |
|
32
|
25
|
|
|
|
|
62
|
$self->name . ": " . join(", ", sort map $_->name, $self->roles); |
|
33
|
1
|
|
|
1
|
|
4
|
}; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
57
|
use overload '@{}' => sub { [ $_[0]->roles ] }; |
|
|
1
|
|
|
5
|
|
1
|
|
|
|
1
|
|
|
|
|
18
|
|
|
|
5
|
|
|
|
|
2126
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#-------------------- |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
0
|
1
|
0
|
sub type { 'people' } |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub init($) |
|
44
|
2
|
|
|
2
|
0
|
4
|
{ my ($self, $args) = @_; |
|
45
|
2
|
50
|
|
|
|
7
|
defined($self->SUPER::init($args)) or return; |
|
46
|
|
|
|
|
|
|
|
|
47
|
2
|
50
|
|
|
|
7
|
$self->{UIC_itype} = delete $args->{item_type} or panic; |
|
48
|
2
|
|
|
|
|
4
|
tie %{$self->{UIC_roles}}, 'Hash::Ordered'; |
|
|
2
|
|
|
|
|
16
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
24
|
my $roles = $args->{roles}; |
|
51
|
2
|
0
|
|
|
|
5
|
my @roles = ! defined $roles ? () : ref $roles eq 'ARRAY' ? @$roles : $roles; |
|
|
|
50
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
5
|
$self->addRole($_) for @roles; |
|
53
|
2
|
|
|
|
|
4
|
$self; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#-------------------- |
|
57
|
|
|
|
|
|
|
|
|
58
|
33
|
|
|
33
|
1
|
1051
|
sub roles() { values %{ $_[0]->{UIC_roles}} } |
|
|
33
|
|
|
|
|
168
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
3
|
|
|
3
|
1
|
5
|
sub itemType { $_[0]->{UIC_itype} } |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#-------------------- |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub addRole(@) |
|
66
|
3
|
|
|
3
|
1
|
4
|
{ my $self = shift; |
|
67
|
3
|
|
|
|
|
10
|
my $maintains = $self->itemType; |
|
68
|
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
5
|
my $role; |
|
70
|
3
|
100
|
66
|
|
|
14
|
if(ref $_[0] && ref $_[0] ne 'ARRAY') |
|
71
|
1
|
|
|
|
|
2
|
{ $role = shift; |
|
72
|
1
|
50
|
|
|
|
7
|
$role->isa($maintains) |
|
73
|
|
|
|
|
|
|
or error __x"wrong type of role for {collection}: requires a {expect} but got a {type}.", |
|
74
|
|
|
|
|
|
|
collection => ref $self, expect => $maintains, type => ref $role; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
else |
|
77
|
2
|
50
|
|
|
|
5
|
{ $role = $maintains->new(ref $_[0] ? @{$_[0]} : @_) |
|
|
2
|
50
|
|
|
|
10
|
|
|
78
|
|
|
|
|
|
|
or error __x"cannot create a {type} to add this to my collection.", type => $maintains; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
11
|
$role->parent($self); |
|
82
|
3
|
|
|
|
|
10
|
$self->{UIC_roles}{$role->name} = $role; |
|
83
|
3
|
|
|
|
|
50
|
$role; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub removeRole($) |
|
88
|
0
|
|
|
0
|
1
|
0
|
{ my ($self, $which) = @_; |
|
89
|
0
|
0
|
|
|
|
0
|
my $name = ref $which ? $which->name : $which; |
|
90
|
0
|
0
|
|
|
|
0
|
my $role = delete $self->{UIC_roles}{$name} or return (); |
|
91
|
0
|
|
|
|
|
0
|
$role->parent(undef); |
|
92
|
0
|
|
|
|
|
0
|
$role; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub renameRole($$$) |
|
97
|
0
|
|
|
0
|
1
|
0
|
{ my ($self, $which, $newname) = @_; |
|
98
|
0
|
0
|
|
|
|
0
|
my $name = ref $which ? $which->name : $which; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
0
|
! exists $self->{UIC_roles}{$newname} |
|
101
|
|
|
|
|
|
|
or error __x"cannot rename {from} into {to}: already exists", from => $name, to => $newname; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
0
|
my $role = delete $self->{UIC_roles}{$name} |
|
104
|
|
|
|
|
|
|
or error __x"cannot rename {from} into {to}: doesn't exist", from => $name, to => $newname; |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
$role->name($newname); # may imply change other attributes. |
|
107
|
0
|
|
|
|
|
0
|
$self->{UIC_roles}{$newname} = $role; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
0
|
|
|
0
|
1
|
0
|
sub sorted() { sort {$a->name cmp $b->name} shift->roles} |
|
|
0
|
|
|
|
|
0
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
#-------------------- |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub find($) |
|
116
|
3
|
|
|
3
|
1
|
9
|
{ my ($self, $select) = @_; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
!defined $select ? ($self->roles)[0] |
|
119
|
|
|
|
|
|
|
: !ref $select ? $self->{UIC_roles}{$select} |
|
120
|
|
|
|
|
|
|
: wantarray ? (grep $select->($_, $self), $self->roles) |
|
121
|
3
|
0
|
|
0
|
|
34
|
: first { $select->($_, $self) } $self->roles; |
|
|
0
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |