104 |
|
|
105 |
=head2 as_collection_of |
=head2 as_collection_of |
106 |
|
|
107 |
my $connection = $ldap->collection('Organization', $limit); |
my $connection = $ldap->collection( |
108 |
|
# name of model to use |
109 |
|
'Organization', |
110 |
|
# optional params |
111 |
|
limit => $limit, |
112 |
|
); |
113 |
|
|
114 |
=cut |
=cut |
115 |
|
|
119 |
}; |
}; |
120 |
|
|
121 |
sub collection { |
sub collection { |
122 |
my ( $self, $model, $limit ) = @_; |
my $self = shift; |
123 |
|
my $model = shift or die "no model?"; |
124 |
|
my $args = {@_}; |
125 |
|
|
126 |
$limit ||= 0; # unlimited by default |
$args->{limit} ||= 0; # unlimited by default |
127 |
|
|
128 |
my $filter = $collection2filter->{$model}; |
my $filter = $collection2filter->{$model}; |
129 |
die "unknown model $model" unless $filter; |
die "unknown model $model" unless $filter; |
131 |
$self->search( |
$self->search( |
132 |
base => $self->base, |
base => $self->base, |
133 |
filter => $filter, |
filter => $filter, |
134 |
sizelimit => $limit, |
sizelimit => $args->{limit}, |
135 |
); |
); |
136 |
|
|
137 |
Jifty->log->info("searching LDAP for $model with $filter limit $limit returned ", $self->count, " results"); |
Jifty->log->info( |
138 |
|
"searching LDAP for $model with $filter ", |
139 |
|
$args->{limit} ? 'limit ' . $args->{limit} : '', |
140 |
|
'returned ', $self->count, ' results' |
141 |
|
); |
142 |
|
|
143 |
my $class = Jifty->app_class('Model', $model . 'Collection' ) or die "can't create ${model}Collection"; |
my $class = Jifty->app_class('Model', $model . 'Collection' ) or die "can't create ${model}Collection"; |
144 |
my $collection = $class->new() or die "can't $class->new"; |
my $collection = $class->new() or die "can't $class->new"; |