get_all_components is getting until we know what to do
André Walker [Thu, 11 Aug 2011 21:48:53 +0000 (18:48 -0300)]
lib/Catalyst.pm
lib/Catalyst/IOC/BlockInjection.pm
lib/Catalyst/IOC/Container.pm
lib/Catalyst/IOC/Service/WithAcceptContext.pm
lib/Catalyst/IOC/Service/WithParameters.pm

index 7e4e229..c87bff2 100644 (file)
@@ -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
index 5528537..bdc5981 100644 (file)
@@ -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;
index 921854c..07d7fc5 100644 (file)
@@ -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" ),
             ],
index eb0ff39..99b45e0 100644 (file)
@@ -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 );
     }
 
index b9f513e..14cbbf5 100644 (file)
@@ -12,7 +12,7 @@ sub _build_parameters {
         },
         accept_context_args => {
             isa      => 'ArrayRef',
-            required => 1,
+            default  => sub { [] },
         }
     };
 }