Use String::RewritePrefix, it's already a Cat dep
Tomas Doran [Sat, 30 Jun 2012 10:35:42 +0000 (11:35 +0100)]
Changes
Makefile.PL
lib/Catalyst/Authentication/Realm.pm

diff --git a/Changes b/Changes
index 113a5da..a8b09a0 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Perl extension Catalyst::Plugin::Authentication
 
+    - Change Catalyst::Authentication::Realm to use String::RewritePrefix
+      rather than doing namespace mangling manually.
     - Fix whitespace and tabs, add Test::EOL and Test::NoTabs
     - Document optional methods in stores needed for auto_create_user
       and auto_update_user in realms.
index d31da22..b8cd666 100644 (file)
@@ -23,7 +23,7 @@ requires 'Catalyst::Plugin::Session' => '0.10';
 requires 'Moose';
 requires 'MooseX::Emulate::Class::Accessor::Fast';
 requires 'namespace::clean';
-
+requires 'String::RewritePrefix';
 
 test_requires 'Test::More' => '0.88';
 test_requires 'Test::Exception';
index 9a61a2e..28ce7ea 100644 (file)
@@ -2,6 +2,7 @@ package Catalyst::Authentication::Realm;
 
 use strict;
 use warnings;
+use String::RewritePrefix;
 
 use base qw/Class::Accessor::Fast/;
 
@@ -41,11 +42,10 @@ 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::Authentication::Store::${storeclass}";
-    } else {
-        $storeclass = $1;
-    }
+    $storeclass = String::RewritePrefix->rewrite({
+        '' => 'Catalyst::Authentication::Store::',
+        '+' => '',
+    }, $storeclass);
 
     # a little niceness - since most systems seem to use the password credential class,
     # if no credential class is specified we use password.
@@ -55,11 +55,10 @@ sub new {
 
     ## follow catalyst class naming - a + prefix means a fully qualified class, otherwise it's
     ## taken to mean C::A::Credential::(specifiedclass)
-    if ($credentialclass !~ /^\+(.*)$/ ) {
-        $credentialclass = "Catalyst::Authentication::Credential::${credentialclass}";
-    } else {
-        $credentialclass = $1;
-    }
+    $credentialclass = String::RewritePrefix->rewrite({
+        '' => 'Catalyst::Authentication::Credential::',
+        '+' => '',
+    }, $credentialclass);
 
     # if we made it here - we have what we need to load the classes