From: Tomas Doran Date: Sat, 1 Aug 2009 00:39:39 +0000 (+0000) Subject: Merge branch pass_component_names: X-Git-Tag: 5.80008~43 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=829b22f766b0b1d1a09a6ce152abe48ad9bde5ec Merge branch pass_component_names: svn merge -r 10899:10927 http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Runtime/5.80/branches/pass_component_names --- 829b22f766b0b1d1a09a6ce152abe48ad9bde5ec diff --cc lib/Catalyst.pm index fbfb3bf,b238376..b601962 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@@ -2215,7 -2216,11 +2215,10 @@@ sub setup_component my $suffix = Catalyst::Utils::class2classsuffix( $component ); my $config = $class->config->{ $suffix } || {}; - - # Stash _component_name in the config here, so that custom COMPONENT - # methods also pass it. local to avoid pointlessly shitting in config - # for the debug screen, as $component is already the key name. - local $config->{_component_name} = $component; - ++ $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 = $@ ) { diff --cc lib/Catalyst/Component.pm index 2decf10,ee1f99a..c065664 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@@ -60,6 -60,15 +60,8 @@@ component loader with config() support __PACKAGE__->mk_classdata('_plugins'); __PACKAGE__->mk_classdata('_config'); -has _component_name => ( is => 'ro' ); # Cannot be required => 1 as context - # class @ISA component - HATE -# Make accessor callable as a class method, as we need to call setup_actions -# on the application class, which we don't have an instance of, ewwwww -around _component_name => sub { - my ($orig, $self) = (shift, shift); - blessed($self) ? $self->$orig(@_) : $self; -}; ++has _component_name => ( is => 'ro' ); + sub BUILDARGS { my $class = shift; my $args = {}; @@@ -171,6 -179,6 +172,15 @@@ something like this return $class->new($app, $args); } ++=head2 _component_name ++ ++The name of the component within an application. This is used to ++pass the component's name to actions generated (becoming ++C<< $action->class >>). This is needed so that the L method can ++return an instance of a different class (e.g. a L anonymous class), ++(as finding the component name by C<< ref($self) >> will not work correctly in ++such cases). ++ =head2 $c->config =head2 $c->config($hashref) diff --cc lib/Catalyst/Controller.pm index aca0b1c,c8db2e7..37e36e1 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@@ -156,7 -156,7 +156,7 @@@ around action_namespace => sub } } - my $namespace = Catalyst::Utils::class2prefix(ref($self) || $self, $case_s) || ''; - my $namespace = Catalyst::Utils::class2prefix($self->_component_name, $case_s) || ''; ++ my $namespace = Catalyst::Utils::class2prefix(ref($self) ? $self->_component_name : $self, $case_s) || ''; $self->$orig($namespace) if ref($self); return $namespace; }; @@@ -207,7 -207,7 +207,7 @@@ sub register_actions sub register_action_methods { my ( $self, $c, @methods ) = @_; - my $class = ref $self || $self; - my $class = $self->_component_name; ++ my $class = blessed($self) ? $self->_component_name : $self; #this is still not correct for some reason. my $namespace = $self->action_namespace($c);