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

dwc at dev.catalyst.perl.org dwc at dev.catalyst.perl.org
Sat Jul 28 01:53:52 GMT 2007


Author: dwc
Date: 2007-07-28 01:53:51 +0100 (Sat, 28 Jul 2007)
New Revision: 6599

Added:
   trunk/Catalyst-Model-LDAP/t/unit_Connection.t
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:
Move exception on connection failure from ACCEPT_CONTEXT to Catalyst::Model::LDAP::Connection->new

Modified: trunk/Catalyst-Model-LDAP/Changes
===================================================================
--- trunk/Catalyst-Model-LDAP/Changes	2007-07-28 00:27:43 UTC (rev 6598)
+++ trunk/Catalyst-Model-LDAP/Changes	2007-07-28 00:53:51 UTC (rev 6599)
@@ -3,6 +3,8 @@
 0.16
         - Fix Catalyst::Model::LDAP::Entry's constructor
         - Reorganize tests a little
+        - Move exception on connection failure from ACCEPT_CONTEXT to
+          Catalyst::Model::LDAP::Connection->new
 
 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-07-28 00:27:43 UTC (rev 6598)
+++ trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP/Connection.pm	2007-07-28 00:53:51 UTC (rev 6599)
@@ -64,6 +64,8 @@
         base => 'ou=People,dc=ufl,dc=edu',
     );
 
+On connection failure, an error is thrown using L<Carp/croak>.
+
 =cut
 
 sub new {
@@ -73,7 +75,9 @@
     my %options = %{ ref $args{options} eq 'HASH' ? delete $args{options} : {} };
     my $entry_class = delete $args{entry_class} || 'Catalyst::Model::LDAP::Entry';
 
-    my $self = $class->next::method(delete $args{host}, %args);
+    my $host = delete $args{host};
+    my $self = $class->next::method($host, %args);
+    croak "Error connecting to $host: $@" unless $self;
 
     $self->{_base} = $base;
     $self->{_options} = { %options };

Modified: trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP.pm
===================================================================
--- trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP.pm	2007-07-28 00:27:43 UTC (rev 6598)
+++ trunk/Catalyst-Model-LDAP/lib/Catalyst/Model/LDAP.pm	2007-07-28 00:53:51 UTC (rev 6599)
@@ -132,7 +132,7 @@
     eval "require $class";
     die $@ if $@;
 
-    my $conn = $class->new(%args) or croak $@;
+    my $conn = $class->new(%args);
     my $mesg = $conn->bind(%args);
     croak 'LDAP error: ' . $mesg->error if $mesg->is_error;
 

Added: trunk/Catalyst-Model-LDAP/t/unit_Connection.t
===================================================================
--- trunk/Catalyst-Model-LDAP/t/unit_Connection.t	                        (rev 0)
+++ trunk/Catalyst-Model-LDAP/t/unit_Connection.t	2007-07-28 00:53:51 UTC (rev 6599)
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+use Catalyst::Model::LDAP::Connection;
+use Test::More;
+
+plan skip_all => 'set LDAP_TEST_LIVE to enable this test' unless $ENV{LDAP_TEST_LIVE};
+plan tests    => 3;
+
+{
+    eval {
+        my $ldap = Catalyst::Model::LDAP::Connection->new(
+            host    => 'example.com',
+            base    => 'ou=People,dc=ufl,dc=edu',
+            timeout => 2,
+        );
+    };
+
+    diag($@);
+    ok($@, 'failed to connect to invalid host');
+}
+
+{
+    my $ldap = Catalyst::Model::LDAP::Connection->new(
+        host    => 'ldap.ufl.edu',
+        base    => 'ou=People,dc=ufl,dc=edu',
+        timeout => 2,
+    );
+
+    ok(!$@, 'connected to valid host');
+    isa_ok($ldap, 'Catalyst::Model::LDAP::Connection');
+}




More information about the Catalyst-commits mailing list