line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::LDAP::Class::Group; |
2
|
8
|
|
|
8
|
|
34
|
use strict; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
170
|
|
3
|
8
|
|
|
8
|
|
22
|
use warnings; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
130
|
|
4
|
8
|
|
|
8
|
|
22
|
use Carp; |
|
8
|
|
|
|
|
6
|
|
|
8
|
|
|
|
|
338
|
|
5
|
8
|
|
|
8
|
|
24
|
use base qw( Net::LDAP::Class ); |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
532
|
|
6
|
|
|
|
|
|
|
use Net::LDAP::Class::MethodMaker ( |
7
|
8
|
|
|
|
|
48
|
'scalar --get_set_init' => [qw( user_class )], |
8
|
|
|
|
|
|
|
'related_objects' => [qw( primary_users secondary_users )], |
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
32
|
); |
|
8
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.27'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Net::LDAP::Class::Group - base class for LDAP group objects |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package MyGroup; |
21
|
|
|
|
|
|
|
use strict; |
22
|
|
|
|
|
|
|
use base qw( Net::LDAP::Class::Group ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# define action_for_* methods for your LDAP schema |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
1; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Net::LDAP::Class::Group is a simple base class intended to be |
31
|
|
|
|
|
|
|
subclassed by schema-specific Net::LDAP::Class::Group::* classes. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 init |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Checks that user_class() is defined. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub init { |
42
|
80
|
|
|
80
|
1
|
21213
|
my $self = shift; |
43
|
80
|
|
|
|
|
409
|
$self->SUPER::init(@_); |
44
|
80
|
50
|
|
|
|
281
|
unless ( defined $self->user_class ) { |
45
|
0
|
|
|
|
|
0
|
croak "must define user_class()"; |
46
|
|
|
|
|
|
|
} |
47
|
80
|
|
|
|
|
859
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 users_iterator([I]) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Returns a Net::LDAP::Class::MultiIterator object |
53
|
|
|
|
|
|
|
for all primary and secondary users. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This is the same data as users() returns, but is more |
56
|
|
|
|
|
|
|
efficient since it pages the results and only fetches |
57
|
|
|
|
|
|
|
one at a time. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub users_iterator { |
62
|
6
|
|
|
6
|
1
|
1133
|
my $self = shift; |
63
|
6
|
|
|
|
|
39
|
return Net::LDAP::Class::MultiIterator->new( |
64
|
|
|
|
|
|
|
iterators => [ |
65
|
|
|
|
|
|
|
$self->primary_users_iterator(@_), |
66
|
|
|
|
|
|
|
$self->secondary_users_iterator(@_), |
67
|
|
|
|
|
|
|
] |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 users |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns array or array ref (based on context) of primary_users() |
74
|
|
|
|
|
|
|
and secondary_users(). |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
B Consider using users_iterator() instead, especially if you |
77
|
|
|
|
|
|
|
have large groups. See L for an explanation. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub users { |
82
|
37
|
|
|
37
|
1
|
52
|
my $self = shift; |
83
|
37
|
50
|
|
|
|
97
|
if (@_) { |
84
|
0
|
|
|
|
|
0
|
croak "users() is an accessor (getter) only"; |
85
|
|
|
|
|
|
|
} |
86
|
37
|
|
|
|
|
39
|
my @users = ( @{ $self->primary_users }, @{ $self->secondary_users } ); |
|
37
|
|
|
|
|
173
|
|
|
37
|
|
|
|
|
141
|
|
87
|
37
|
100
|
|
|
|
230
|
return wantarray ? @users : \@users; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 has_user( I ) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Returns true if I is amongst users(), false otherwise. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
B This looks at the currently loaded users() and does |
95
|
|
|
|
|
|
|
not do a read of the LDAP server. It is mostly useful |
96
|
|
|
|
|
|
|
for checking whether you've already queued I for addition |
97
|
|
|
|
|
|
|
with add_to_group(). |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub has_user { |
102
|
35
|
|
|
35
|
1
|
64
|
my $self = shift; |
103
|
35
|
50
|
|
|
|
102
|
my $user = shift or croak "User required"; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# don't use the iterator, because we want to look |
106
|
|
|
|
|
|
|
# at what might be queued for addition. |
107
|
35
|
|
|
|
|
128
|
for my $u ( $self->users ) { |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#warn "member $u <> user $user"; |
110
|
207
|
100
|
|
|
|
359
|
if ( "$u" eq "$user" ) { |
111
|
8
|
|
|
|
|
42
|
return 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
27
|
|
|
|
|
1247
|
return 0; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 init_user_class |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Override this method in your subclass to set the default User class |
120
|
|
|
|
|
|
|
for your Group class. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub init_user_class { |
125
|
0
|
|
|
0
|
1
|
0
|
croak "Must override init_user_class() or set user_class in metadata. " |
126
|
|
|
|
|
|
|
. "Have you created a user subclass yet?"; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 name |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Same as calling cn(). A Group object stringifies to this method. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
41
|
|
|
41
|
1
|
143
|
sub name { shift->cn(@_) } |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 stringify |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Aliased to name(). |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
31
|
|
|
31
|
1
|
109
|
sub stringify { shift->name } |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |