Teach Cat to pass a _component_name into COMPONENT method, which is what ends up...
Tomas Doran [Fri, 17 Jul 2009 22:57:47 +0000 (22:57 +0000)]
lib/Catalyst.pm
lib/Catalyst/Component.pm
lib/Catalyst/Controller.pm

index eae0325..cae8936 100644 (file)
@@ -2216,7 +2216,10 @@ sub setup_component {
 
     my $suffix = Catalyst::Utils::class2classsuffix( $component );
     my $config = $class->config->{ $suffix } || {};
-
+    $config->{_component_name} = $component; # Put this in args here, rather
+                                             # than in COMPONENT as there
+                                             # are lots of custom COMPONENT
+                                             # methods..
     my $instance = eval { $component->COMPONENT( $class, $config ); };
 
     if ( my $error = $@ ) {
index 2decf10..0fbca47 100644 (file)
@@ -60,6 +60,8 @@ component loader with config() support and a process() method placeholder.
 __PACKAGE__->mk_classdata('_plugins');
 __PACKAGE__->mk_classdata('_config');
 
+has _component_name => ( is => 'ro' );
+
 sub BUILDARGS {
     my $class = shift;
     my $args = {};
@@ -85,19 +87,18 @@ sub BUILDARGS {
 }
 
 sub COMPONENT {
-    my ( $self, $c ) = @_;
+    my ( $class, $c ) = @_;
 
     # Temporary fix, some components does not pass context to constructor
     my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {};
-    if( my $next = $self->next::can ){
-      my $class = blessed $self || $self;
+    if ( my $next = $class->next::can ) {
       my ($next_package) = Class::MOP::get_code_info($next);
       warn "There is a COMPONENT method resolving after Catalyst::Component in ${next_package}.\n";
       warn "This behavior can no longer be supported, and so your application is probably broken.\n";
       warn "Your linearized isa hierarchy is: " . join(', ', @{ mro::get_linear_isa($class) }) . "\n";
       warn "Please see perldoc Catalyst::Upgrading for more information about this issue.\n";
     }
-    return $self->new($c, $arguments);
+    return $class->new($c, $arguments);
 }
 
 sub config {
index aca0b1c..37e36e1 100644 (file)
@@ -156,7 +156,7 @@ around action_namespace => sub {
         }
     }
 
-    my $namespace = Catalyst::Utils::class2prefix(ref($self) || $self, $case_s) || '';
+    my $namespace = Catalyst::Utils::class2prefix(ref($self) ? $self->_component_name : $self, $case_s) || '';
     $self->$orig($namespace) if ref($self);
     return $namespace;
 };
@@ -190,7 +190,7 @@ sub get_action_methods {
         @methods,
         map {
             $meta->find_method_by_name($_)
-              || confess( 'Action "' 
+              || confess( 'Action "'
                   . $_
                   . '" is not available from controller '
                   . ( ref $self ) )
@@ -207,7 +207,7 @@ sub register_actions {
 
 sub register_action_methods {
     my ( $self, $c, @methods ) = @_;
-    my $class = ref $self || $self;
+    my $class = blessed($self) ? $self->_component_name : $self;
     #this is still not correct for some reason.
     my $namespace = $self->action_namespace($c);