From: André Walker Date: Thu, 11 Aug 2011 21:48:53 +0000 (-0300) Subject: get_all_components is getting until we know what to do X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=9084f394cf7b3a451cac0b6732b921b2dd3fad55 get_all_components is getting until we know what to do --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 7e4e229..c87bff2 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1017,7 +1017,7 @@ EOF if ( $class->debug and - my $comps = $class->container->get_all_components + my $comps = $class->container->get_all_components($class) ) { my $column_width = Catalyst::Utils::term_width() - 8 - 9; my $t = Text::SimpleTable->new( [ $column_width, 'Class' ], [ 8, 'Type' ] ); @@ -1435,7 +1435,7 @@ sub components { $container->add_component( $_ ) for keys %$comps; } - return $container->get_all_components(); + return $container->get_all_components($class); } =head2 $c->context_class diff --git a/lib/Catalyst/IOC/BlockInjection.pm b/lib/Catalyst/IOC/BlockInjection.pm index 5528537..bdc5981 100644 --- a/lib/Catalyst/IOC/BlockInjection.pm +++ b/lib/Catalyst/IOC/BlockInjection.pm @@ -6,6 +6,10 @@ with 'Catalyst::IOC::Service::WithAcceptContext', 'Catalyst::IOC::Service::WithParameters', 'Bread::Board::Service::WithDependencies'; +has catalyst_component_name => ( + is => 'ro', +); + __PACKAGE__->meta->make_immutable; no Moose; 1; diff --git a/lib/Catalyst/IOC/Container.pm b/lib/Catalyst/IOC/Container.pm index 921854c..07d7fc5 100644 --- a/lib/Catalyst/IOC/Container.pm +++ b/lib/Catalyst/IOC/Container.pm @@ -592,16 +592,16 @@ sub find_component { } sub _find_component_regexp { - my ( $self, $component, @args ) = @_; + my ( $self, $component, $ctx, @args ) = @_; my @result; - my @components = grep { m{$component} } keys %{ $self->get_all_components }; + my @components = grep { m{$component} } keys %{ $self->get_all_components($ctx) }; for (@components) { my ($type, $name) = _get_component_type_name($_); push @result, $self->get_component_from_sub_container( - $type, $name, @args + $type, $name, $ctx, @args ) if $type; } @@ -609,7 +609,7 @@ sub _find_component_regexp { } sub get_all_components { - my $self = shift; + my ($self, $class) = @_; my %components; # FIXME - if we're getting from these containers, we need to either: @@ -619,10 +619,9 @@ sub get_all_components { my $container = $self->get_sub_container($type); for my $component ($container->get_service_list) { - my $comp = $container->get_service($component); + my $comp_service = $container->get_service($component); - # is this better? - $components{$comp->catalyst_component_name} = $comp->get; + $components{$comp_service->catalyst_component_name} = $comp_service->get(ctx => $class); } } @@ -664,6 +663,7 @@ sub add_component { $accept_context_container->add_service( Catalyst::IOC::BlockInjection->new( name => $name, + catalyst_component_name => $component, dependencies => [ depends_on( "/component/$component_service_name" ), ], diff --git a/lib/Catalyst/IOC/Service/WithAcceptContext.pm b/lib/Catalyst/IOC/Service/WithAcceptContext.pm index eb0ff39..99b45e0 100644 --- a/lib/Catalyst/IOC/Service/WithAcceptContext.pm +++ b/lib/Catalyst/IOC/Service/WithAcceptContext.pm @@ -16,7 +16,7 @@ around get => sub { my $instance = $self->$orig(@_); - if ( $instance->can($ac_sub) ) { + if ( $accept_context_args && $instance->can($ac_sub) ) { return $instance->$ac_sub( @$accept_context_args ); } diff --git a/lib/Catalyst/IOC/Service/WithParameters.pm b/lib/Catalyst/IOC/Service/WithParameters.pm index b9f513e..14cbbf5 100644 --- a/lib/Catalyst/IOC/Service/WithParameters.pm +++ b/lib/Catalyst/IOC/Service/WithParameters.pm @@ -12,7 +12,7 @@ sub _build_parameters { }, accept_context_args => { isa => 'ArrayRef', - required => 1, + default => sub { [] }, } }; }