Added support for ~ prefix to plugins and action classes
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Utils.pm
index 4d5f0ed..e791b4a 100644 (file)
@@ -9,6 +9,8 @@ use URI;
 use Carp qw/croak/;
 use Cwd;
 
+use String::RewritePrefix;
+
 use namespace::clean;
 
 =head1 NAME
@@ -377,6 +379,28 @@ sub term_width {
     return $_term_width = $width;
 }
 
+
+=head2 resolve_namespace
+
+Method which adds the namespace for plugins and actions.
+
+  __PACKAGE__->setup(qw(MyPlugin));
+  
+  # will load Catalyst::Plugin::MyPlugin
+
+=cut
+
+
+sub resolve_namespace {
+    my $appnamespace = shift;
+    my $namespace = shift;
+    my @classes = @_;
+    return String::RewritePrefix->rewrite(
+        { '' => $namespace.'::', '+' => '', '~' => $appnamespace . '::' }, @classes,
+      );
+}
+
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm