[Catalyst-commits] r6646 - in trunk/Catalyst-Model-LDAP: . lib/Catalyst/Model lib/Catalyst/Model/LDAP

dwc at dev.catalyst.perl.org dwc at dev.catalyst.perl.org
Sat Aug 11 23:22:18 GMT 2007


Author: dwc
Date: 2007-08-11 23:22:18 +0100 (Sat, 11 Aug 2007)
New Revision: 6646

Modified:
   trunk/Catalyst-Model-LDAP/Changes
   trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP.pm
   trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP/Connection.pm
Log:
* Convert base, options, and entry_class in Catalyst::Model::LDAP::Connection to full accessors
* Make Catalyst::Model::LDAP::Connection->bind a little more flexible

Modified: trunk/Catalyst-Model-LDAP/Changes
===================================================================
--- trunk/Catalyst-Model-LDAP/Changes	2007-08-11 16:45:57 UTC (rev 6645)
+++ trunk/Catalyst-Model-LDAP/Changes	2007-08-11 22:22:18 UTC (rev 6646)
@@ -7,6 +7,10 @@
           Catalyst::Model::LDAP::Connection->new
         - Fix Catalyst::Model::LDAP::Connection->search to handle
           list-return from Net::LDAP::Message->control (omega)
+        - Convert base, options, and entry_class in
+          Catalyst::Model::LDAP::Connection to full accessors
+        - Make Catalyst::Model::LDAP::Connection->bind a little more
+          flexible
 
 0.15  Fri Feb 23 11:37:25 EST 2007
         - Throw runtime require errors

Modified: trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP/Connection.pm
===================================================================
--- trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP/Connection.pm	2007-08-11 16:45:57 UTC (rev 6645)
+++ trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP/Connection.pm	2007-08-11 22:22:18 UTC (rev 6646)
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use base qw/Net::LDAP/;
+use base qw/Net::LDAP Class::Accessor::Fast/;
 use Carp qw/croak/;
 use Catalyst::Model::LDAP::Search;
 use Class::C3;
@@ -11,6 +11,8 @@
 use Net::LDAP::Control::Sort;
 use Net::LDAP::Control::VLV;
 
+__PACKAGE__->mk_accessors(qw/base options entry_class/);
+
 =head1 NAME
 
 Catalyst::Model::LDAP::Connection - Convenience methods for Net::LDAP
@@ -79,9 +81,9 @@
     my $self = $class->next::method($host, %args);
     croak "Error connecting to $host: $@" unless $self;
 
-    $self->{_base} = $base;
-    $self->{_options} = { %options };
-    $self->{_entry_class} = $entry_class;
+    $self->base($base);
+    $self->options(\%options);
+    $self->entry_class($entry_class);
 
     return $self;
 }
@@ -95,28 +97,41 @@
         password => 'secret',
     );
 
+This method behaves similarly to L<Net::LDAP/bind>, except that it
+gives an explicit name to the C<dn> parameter.  For example, if you
+need to use SASL to bind to the server, you can specify that in your
+call:
+
+    $conn->bind(
+        dn   => 'uid=dwc,ou=People,dc=ufl,dc=edu',
+        sasl => Authen::SASL->new(mechanism => 'GSSAPI'),
+    );
+
+Additionally, if the C<start_tls> configuration option is present, the
+client will use L<Net::LDAP/start_tls> to make your connection secure.
+
+For more information on customizing the bind process, see
+L</OVERRIDING METHODS>.
+
 =cut
 
 sub bind {
     my ($self, %args) = @_;
 
+    delete $args{$_} for qw/host base options connection_class entry_class/;
+
     # Bind using TLS if configured
-    if ($args{start_tls}) {
+    if (delete $args{start_tls}) {
         my $mesg = $self->start_tls(
-            %{ ref $args{start_tls_options} eq 'HASH' ? $args{start_tls_options} : {} },
+            %{ delete $args{start_tls_options} || {} },
         );
         croak 'LDAP TLS error: ' . $mesg->error if $mesg->is_error;
     }
 
     # Bind via DN if configured
-    my @args;
-    if ($args{dn}) {
-        push @args, $args{dn};
-        push @args, password => $args{password}
-            if exists $args{password};
-    }
+    my $dn = delete $args{dn};
 
-    $self->next::method(@args);
+    $self->next::method($dn ? ($dn, %args) : %args);
 }
 
 =head2 search 
@@ -161,8 +176,8 @@
 
     # Use default base
     %args = (
-        base => $self->{_base},
-        %{ $self->{_options} },
+        base => $self->base,
+        %{ $self->options || {} },
         %args,
     );
 
@@ -197,7 +212,7 @@
     }
 
     bless $mesg, 'Catalyst::Model::LDAP::Search';
-    $mesg->init($self->{_entry_class});
+    $mesg->init($self->entry_class);
 
     return ($pager ? ($mesg, $pager) : $mesg);
 }

Modified: trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP.pm
===================================================================
--- trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP.pm	2007-08-11 16:45:57 UTC (rev 6645)
+++ trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP.pm	2007-08-11 22:22:18 UTC (rev 6646)
@@ -117,9 +117,8 @@
 Bind the client using the current configuration and return it.  This
 method is automatically called when you use e.g. C<< $c->model('LDAP') >>.
 
-If the C<start_tls> configuration option is present, the client will
-use the L<Net::LDAP> C<start_tls> method to make your connection
-secure.
+See L<Catalyst::Model::LDAP::Connection/bind> for information on how
+the bind operation is done.
 
 =cut
 




More information about the Catalyst-commits mailing list