X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=fc278fb7f20cde6d3747cb8fccf08a72e46e7318;hp=b0e0129f87433a96beb034ae6e71d72473226da6;hb=refs%2Ftags%2F5.90089_003;hpb=0d0d19ed00b7f86a716558d34a5a8d810d074d3a diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index b0e0129..fc278fb 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -715,20 +715,15 @@ sub _comp_names { # Filter a component before returning by calling ACCEPT_CONTEXT if available -#our %tracker = (); sub _filter_component { my ( $c, $comp, @args ) = @_; - # die "Circular Dependencies Detected." if $tracker{$comp}; - # $tracker{$comp}++; if(ref $comp eq 'CODE') { $comp = $comp->(); } - #$tracker{$comp}++; if ( eval { $comp->can('ACCEPT_CONTEXT'); } ) { - die "Component '${\$comp->catalyst_component_name}' does ACCEPT_CONTEXT but I am in application scope" unless blessed $c; - return $comp->ACCEPT_CONTEXT( $c, @args ); + return $comp->ACCEPT_CONTEXT( $c, @args ); } $c->log->warn("You called component '${\$comp->catalyst_component_name}' with arguments [@args], but this component does not ACCEPT_CONTEXT, so args are ignored.") if scalar(@args) && $c->debug; @@ -2855,25 +2850,49 @@ sub setup_components { # of named components in the configuration that are not actually existing (not a # real file). + my @injected_components = $class->setup_injected_components; + + # All components are registered, now we need to 'init' them. + foreach my $component_name (@comps, @injected_components) { + $class->components->{$component_name} = $class->components->{$component_name}->() if + (ref($class->components->{$component_name}) || '') eq 'CODE'; + } +} + +=head2 $app->setup_injected_components + +Called by setup_compoents to setup components that are injected. + +=cut + +sub setup_injected_components { + my ($class) = @_; my @injected_components = keys %{$class->config->{inject_components} ||+{}}; + foreach my $injected_comp_name(@injected_components) { - my $component_class = $class->config->{inject_components}->{$injected_comp_name}->{from_component} || ''; - if($component_class) { - my @roles = @{$class->config->{inject_components}->{$injected_comp_name}->{roles} ||[]}; - my %args = %{ $class->config->{$injected_comp_name} || +{} }; + $class->setup_injected_component( + $injected_comp_name, + $class->config->{inject_components}->{$injected_comp_name}); + } + + return @injected_components; +} + +=head2 $app->setup_injected_component( $injected_component_name, $config ) + +Setup a given injected component. + +=cut +sub setup_injected_component { + my ($class, $injected_comp_name, $config) = @_; + if(my $component_class = $config->{from_component}) { + my @roles = @{$config->{roles} ||[]}; Catalyst::Utils::inject_component( into => $class, component => $component_class, (scalar(@roles) ? (traits => \@roles) : ()), as => $injected_comp_name); - } - } - - # All components are registered, now we need to 'init' them. - foreach my $component_name (@comps, @injected_components) { - $class->components->{$component_name} = $class->components->{$component_name}->() if - (ref($class->components->{$component_name}) || '') eq 'CODE'; } }