line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2003-2022 by [Mark Overmeer ]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.03. |
5
|
|
|
|
|
|
|
# This code is part of distribution User-Identity. Meta-POD processed with |
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package User::Identity::Collection; |
10
|
1
|
|
|
1
|
|
8
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
89
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.01'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
9
|
use base 'User::Identity::Item'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
441
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
16
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
482
|
use User::Identity; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
19
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
114
|
|
20
|
1
|
|
|
1
|
|
6
|
use List::Util qw/first/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
175
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use overload '""' => sub { |
24
|
29
|
|
|
29
|
|
265
|
my $self = shift; |
25
|
29
|
|
|
|
|
55
|
$self->name . ": " . join(", ", sort map {$_->name} $self->roles); |
|
29
|
|
|
|
|
50
|
|
26
|
1
|
|
|
1
|
|
6
|
}; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
97
|
use overload '@{}' => sub { [ shift->roles ] }; |
|
1
|
|
|
5
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
15
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#----------------------------------------- |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
1
|
0
|
sub type { "people" } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub init($) |
38
|
2
|
|
|
2
|
0
|
8
|
{ my ($self, $args) = @_; |
39
|
|
|
|
|
|
|
|
40
|
2
|
50
|
|
|
|
12
|
defined($self->SUPER::init($args)) or return; |
41
|
|
|
|
|
|
|
|
42
|
2
|
50
|
|
|
|
13
|
$self->{UIC_itype} = delete $args->{item_type} or die; |
43
|
2
|
|
|
|
|
7
|
$self->{UIC_roles} = { }; |
44
|
2
|
|
|
|
|
4
|
my $roles = $args->{roles}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my @roles |
47
|
2
|
0
|
|
|
|
11
|
= ! defined $roles ? () |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
: ref $roles eq 'ARRAY' ? @$roles |
49
|
|
|
|
|
|
|
: $roles; |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
7
|
$self->addRole($_) foreach @roles; |
52
|
2
|
|
|
|
|
5
|
$self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#----------------------------------------- |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
37
|
|
|
37
|
1
|
1100
|
sub roles() { values %{shift->{UIC_roles}} } |
|
37
|
|
|
|
|
140
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
3
|
1
|
9
|
sub itemType { shift->{UIC_itype} } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#----------------------------------------- |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub addRole(@) |
67
|
3
|
|
|
3
|
1
|
8
|
{ my $self = shift; |
68
|
3
|
|
|
|
|
15
|
my $maintains = $self->itemType; |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
6
|
my $role; |
71
|
3
|
100
|
66
|
|
|
24
|
if(ref $_[0] && ref $_[0] ne 'ARRAY') |
72
|
1
|
|
|
|
|
3
|
{ $role = shift; |
73
|
1
|
50
|
|
|
|
8
|
croak "ERROR: Wrong type of role for ".ref($self) |
74
|
|
|
|
|
|
|
. ": requires a $maintains but got a ". ref($role) |
75
|
|
|
|
|
|
|
unless $role->isa($maintains); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else |
78
|
2
|
50
|
|
|
|
7
|
{ $role = $maintains->new(ref $_[0] ? @{$_[0]} : @_); |
|
2
|
|
|
|
|
14
|
|
79
|
2
|
50
|
|
|
|
7
|
croak "ERROR: Cannot create a $maintains to add this to my collection." |
80
|
|
|
|
|
|
|
unless defined $role; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
33
|
$role->parent($self); |
84
|
3
|
|
|
|
|
17
|
$self->{UIC_roles}{$role->name} = $role; |
85
|
3
|
|
|
|
|
24
|
$role; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub removeRole($) |
90
|
0
|
|
|
0
|
1
|
0
|
{ my ($self, $which) = @_; |
91
|
0
|
0
|
|
|
|
0
|
my $name = ref $which ? $which->name : $which; |
92
|
0
|
0
|
|
|
|
0
|
my $role = delete $self->{UIC_roles}{$name} or return (); |
93
|
0
|
|
|
|
|
0
|
$role->parent(undef); |
94
|
0
|
|
|
|
|
0
|
$role; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub renameRole($$$) |
99
|
0
|
|
|
0
|
1
|
0
|
{ my ($self, $which, $newname) = @_; |
100
|
0
|
0
|
|
|
|
0
|
my $name = ref $which ? $which->name : $which; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
0
|
if(exists $self->{UIC_roles}{$newname}) |
103
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR=>"Cannot rename $name into $newname: already exists"); |
104
|
0
|
|
|
|
|
0
|
return (); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
my $role = delete $self->{UIC_roles}{$name}; |
108
|
0
|
0
|
|
|
|
0
|
unless(defined $role) |
109
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot rename $name into $newname: doesn't exist"); |
110
|
0
|
|
|
|
|
0
|
return (); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
$role->name($newname); # may imply change other attributes. |
114
|
0
|
|
|
|
|
0
|
$self->{UIC_roles}{$newname} = $role; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
0
|
1
|
0
|
sub sorted() { sort {$a->name cmp $b->name} shift->roles} |
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
#----------------------------------------- |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub find($) |
124
|
3
|
|
|
3
|
1
|
19
|
{ my ($self, $select) = @_; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
!defined $select ? ($self->roles)[0] |
127
|
|
|
|
|
|
|
: !ref $select ? $self->{UIC_roles}{$select} |
128
|
0
|
|
|
|
|
|
: wantarray ? grep ({ $select->($_, $self) } $self->roles) |
129
|
3
|
0
|
|
0
|
|
26
|
: first { $select->($_, $self) } $self->roles; |
|
0
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|