[Catalyst] source out accessors to LDAP-Model

piccard piccard at web.de
Mon Dec 13 14:24:58 GMT 2010


I'm very new to Catalyst, so at the moment I am playing around with some 
things. I think I've got a very basic question:
I'm not sure how to pull out more complicated queries from the 
controller by providing subroutines/accessors.

I created a LDAP-Model and sourced out the connection-parameters to 

     base   ou=TSM,ou=ABC,o=fffff,c=de
     password   extremlysecret
         verify   none
     port   1111
     start_tls   0
     dn   cn=readproxytsm,ou=services,o=ffff,c=de
     host   ldaps://ldapauth.ffff.de

Then I tested it by a controller query, which works very well:

     # Then, in your controller
     my $mesg = $c->model('Person')->search('(uid=lu21rue)');
     my @entries = $mesg->entries;
                template => 'books/person.tt',
                person_uri => $entries[0]->uid,
                person => $entries[0],

But I don't wanna pollute my controllers, so I wanted to source out 
complicated queries in special classes which should provide accessors. 
So I extended the Model-class to use an adaptor:

package ldap::Model::Person;

use strict;
use warnings;
use base qw/Catalyst::Model::LDAP/;
use parent 'Catalyst::Model::Adaptor';

         class => 'ldap::Model::Person::Utils',
         args => {}

package ldap::Model::Person::Utils;

use Moose;
use namespace::clean -except => 'meta';
extends 'Catalyst::Model::LDAP';

sub getPerson {
     my ($self, $person) = @_;

         my $mesg = $self->search('(uid='.$person.')');
         my @entries = $mesg->entries;

         return @entries;


But that's defnitly the wrong way, 'cause $c->model('Person') from the 
controller returns a Catalyst::Model::LDAP::Connection reference.
What's the right way to pull out these queries from the controller and 
store them in their own classes?

Thank u in advnace :-D

More information about the Catalyst mailing list