refactor of namespace handling
Moritz Onken [Sat, 6 Jun 2009 13:33:53 +0000 (13:33 +0000)]
Makefile.PL
TODO
lib/Catalyst.pm
lib/Catalyst/Controller.pm
lib/Catalyst/Dispatcher.pm
lib/Catalyst/Utils.pm

index a15ed5d..cd3dd33 100644 (file)
@@ -34,6 +34,7 @@ requires 'Tree::Simple::Visitor::FindByPath';
 requires 'URI' => '1.35';
 requires 'Text::Balanced'; # core in 5.8.x but mentioned for completeness
 requires 'MRO::Compat';
+requires 'String::RewritePrefix' => '0.004'; # Catalyst::Utils::resolve_namespace
 
 recommends 'B::Hooks::OP::Check::StashChange';
 
diff --git a/TODO b/TODO
index 8c5bc68..4862bfe 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,25 +1,10 @@
-Known Bugs:
-
-   - Bug ->go or ->visit causes actions which have Args or CaptureArgs called
-     twice when called via ->go or ->visit.
-
-     Test app: http://github.com/bobtfish/catalyst-app-bug-go_chain/tree/master
-
-Compatibility warnings to add:
-
-   - $self->config should warn as config should only ever be called as a
-     class method.
-
-Proposed functionality / feature additions:
-
-    - Log setup needs to be less lame, so Catalyst::Plugin::Log::* can die
-      in a fire. Having $c->log_class would be a good start. kane volunteered
-      to do some of this.
-
-      Simple example: Catalyst::Plugin::Log::Colorful should just be a
-      subclass of Catalyst::Log, no ::Plugin:: needed.
-
-      See also: Catalyst::Plugin::Log::Dispatch and
-      http://github.com/willert/catalyst-plugin-log4perl-simple/tree
+TODO for brach namespace_handling_refactor:
 
+- refactor code in 
+  * Catalyst::Dispatcher::get_containers           # No Idea
+  * Catalyst::Dispatcher::get_containers           # No Idea
 
+  * Catalyst::Controller::_parse_ActionClass_attr  # DONE
+  * Catalyst::Dispatcher::_load_dispatch_types     # DONE
+  * Catalyst::setup_plugins                        # DONE
+  to use the same namespacing method
\ No newline at end of file
index b38be49..426cbb3 100644 (file)
@@ -2502,8 +2502,8 @@ the plugin name does not begin with C<Catalyst::Plugin::>.
 
         $class->_plugins( {} ) unless $class->_plugins;
         $plugins ||= [];
-
-        my @plugins = map { s/\A\+// ? $_ : "Catalyst::Plugin::$_" } @$plugins;
+        
+        my @plugins = Catalyst::Utils::resolve_namespace('Catalyst::Plugin', @$plugins);
         
         for my $plugin ( reverse @plugins ) {
             Class::MOP::load_class($plugin);
index 8b391df..d1c6274 100644 (file)
@@ -376,9 +376,7 @@ sub _parse_PathPrefix_attr {
 
 sub _parse_ActionClass_attr {
     my ( $self, $c, $name, $value ) = @_;
-    unless ( $value =~ s/^\+// ) {
-      $value = join('::', $self->_action_class, $value );
-    }
+    $value = Catalyst::Utils::resolve_namespace($self->_action_class, $value);
     return ( 'ActionClass', $value );
 }
 
index 214d031..5df4526 100644 (file)
@@ -643,9 +643,8 @@ sub _load_dispatch_types {
 
     # Preload action types
     for my $type (@types) {
-        my $class =
-          ( $type =~ /^\+(.*)$/ ) ? $1 : "Catalyst::DispatchType::${type}";
-
+        my $class = Catalyst::Utils::resolve_namespace('Catalyst::DispatchType', $type);
+        
         eval { Class::MOP::load_class($class) };
         Catalyst::Exception->throw( message => qq/Couldn't load "$class"/ )
           if $@;
@@ -668,9 +667,7 @@ of course it's being used.)
 sub dispatch_type {
     my ($self, $name) = @_;
 
-    unless ($name =~ s/^\+//) {
-        $name = "Catalyst::DispatchType::" . $name;
-    }
+    $name = Catalyst::Utils::resolve_namespace('Catalyst::DispatchType', $name);
 
     for (@{ $self->_dispatch_types }) {
         return $_ if ref($_) eq $name;
index 4d5f0ed..76f0733 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,27 @@ 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 $namespace = shift;
+    my @classes = @_;
+    return String::RewritePrefix->rewrite(
+        { '' => $namespace.'::', '+' => '' }, @classes,
+      );
+}
+
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm