[Catalyst-commits] r10460 - in Catalyst-Runtime/5.80/branches/namespace_handling_refactor: . lib lib/Catalyst

mo at dev.catalyst.perl.org mo at dev.catalyst.perl.org
Sat Jun 6 13:33:53 GMT 2009


Author: mo
Date: 2009-06-06 13:33:53 +0000 (Sat, 06 Jun 2009)
New Revision: 10460

Modified:
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/Makefile.PL
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/TODO
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst.pm
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Controller.pm
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Dispatcher.pm
   Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Utils.pm
Log:
refactor of namespace handling

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/Makefile.PL	2009-06-06 12:56:50 UTC (rev 10459)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/Makefile.PL	2009-06-06 13:33:53 UTC (rev 10460)
@@ -34,6 +34,7 @@
 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';
 

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/TODO
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/TODO	2009-06-06 12:56:50 UTC (rev 10459)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/TODO	2009-06-06 13:33:53 UTC (rev 10460)
@@ -1,25 +1,10 @@
-Known Bugs:
+TODO for brach namespace_handling_refactor:
 
-   - Bug ->go or ->visit causes actions which have Args or CaptureArgs called
-     twice when called via ->go or ->visit.
+- refactor code in 
+  * Catalyst::Dispatcher::get_containers           # No Idea
+  * Catalyst::Dispatcher::get_containers           # No Idea
 
-     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
-
-
+  * 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

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Controller.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Controller.pm	2009-06-06 12:56:50 UTC (rev 10459)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Controller.pm	2009-06-06 13:33:53 UTC (rev 10460)
@@ -376,9 +376,7 @@
 
 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 );
 }
 

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Dispatcher.pm	2009-06-06 12:56:50 UTC (rev 10459)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Dispatcher.pm	2009-06-06 13:33:53 UTC (rev 10460)
@@ -643,9 +643,8 @@
 
     # 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 @@
 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;

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Utils.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Utils.pm	2009-06-06 12:56:50 UTC (rev 10459)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst/Utils.pm	2009-06-06 13:33:53 UTC (rev 10460)
@@ -9,6 +9,8 @@
 use Carp qw/croak/;
 use Cwd;
 
+use String::RewritePrefix;
+
 use namespace::clean;
 
 =head1 NAME
@@ -377,6 +379,27 @@
     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

Modified: Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst.pm	2009-06-06 12:56:50 UTC (rev 10459)
+++ Catalyst-Runtime/5.80/branches/namespace_handling_refactor/lib/Catalyst.pm	2009-06-06 13:33:53 UTC (rev 10460)
@@ -2502,9 +2502,9 @@
 
         $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);
             my $meta = find_meta($plugin);




More information about the Catalyst-commits mailing list