Changing module naming from Catalyst::Plugin::Authentication to
Jay Kuri [Thu, 22 Nov 2007 00:14:33 +0000 (00:14 +0000)]
Catalyst::Authentication.

lib/Catalyst/Plugin/Authentication/Realm.pm

index c88d5e5..b328c66 100644 (file)
@@ -21,7 +21,7 @@ sub new {
 
     # use the Null store as a default
     if( ! exists $config->{store}{class} ) {
-        $config->{store}{class} = '+Catalyst::Plugin::Authentication::Store::Null';
+        $config->{store}{class} = '+Catalyst::Authentication::Store::Null';
         $app->log->debug( qq(No Store specified for realm "$realmname", using the Null store.) );
     } 
     my $storeclass = $config->{'store'}{'class'};
@@ -29,28 +29,50 @@ sub new {
     ## follow catalyst class naming - a + prefix means a fully qualified class, otherwise it's
     ## taken to mean C::P::A::Store::(specifiedclass)
     if ($storeclass !~ /^\+(.*)$/ ) {
-        $storeclass = "Catalyst::Plugin::Authentication::Store::${storeclass}";
+        $storeclass = "Catalyst::Authentication::Store::${storeclass}";
     } else {
         $storeclass = $1;
     }
 
     # a little niceness - since most systems seem to use the password credential class, 
     # if no credential class is specified we use password.
-    $config->{credential}{class} ||= '+Catalyst::Plugin::Authentication::Credential::Password';
+    $config->{credential}{class} ||= '+Catalyst::Authentication::Credential::Password';
 
     my $credentialclass = $config->{'credential'}{'class'};
     
     ## follow catalyst class naming - a + prefix means a fully qualified class, otherwise it's
-    ## taken to mean C::P::A::Credential::(specifiedclass)
+    ## taken to mean C::A::Credential::(specifiedclass)
     if ($credentialclass !~ /^\+(.*)$/ ) {
-        $credentialclass = "Catalyst::Plugin::Authentication::Credential::${credentialclass}";
+        $credentialclass = "Catalyst::Authentication::Credential::${credentialclass}";
     } else {
         $credentialclass = $1;
     }
     
-    # if we made it here - we have what we need to load the classes;
-    Catalyst::Utils::ensure_class_loaded( $credentialclass );
-    Catalyst::Utils::ensure_class_loaded( $storeclass );
+    # if we made it here - we have what we need to load the classes
+    
+    ### BACKWARDS COMPATIBILITY - DEPRECATION WARNING:  
+    ###  we must eval the ensure_class_loaded - because we might need to try the old-style
+    ###  ::Plugin:: module naming if the standard method fails. 
+    
+    eval {
+        Catalyst::Utils::ensure_class_loaded( $credentialclass );
+    };
+    
+    if ($@) {
+        $app->log->warn( qq(Credential class "$credentialclass" not found, trying deprecated ::Plugin:: style naming. ) );
+        $credentialclass =~ s/Catalyst::Authentication/Catalyst::Plugin::Authentication/;
+        Catalyst::Utils::ensure_class_loaded( $credentialclass );
+    }
+    
+    eval {
+        Catalyst::Utils::ensure_class_loaded( $storeclass );
+    };
+    
+    if ($@) {
+        $app->log->warn( qq(Store class "$storeclass" not found, trying deprecated ::Plugin:: style naming. ) );
+        $storeclass =~ s/Catalyst::Authentication/Catalyst::Plugin::Authentication/;
+        Catalyst::Utils::ensure_class_loaded( $storeclass );
+    }
     
     # BACKWARDS COMPATIBILITY - if the store class does not define find_user, we define it in terms 
     # of get_user and add it to the class.  this is because the auth routines use find_user,