sub setup_components {
my $self = shift;
+ warn("Setting up default components");
my $class = $self->resolve( service => 'application_name' );
my @comps = @{ $self->resolve( service => 'locate_components' ) };
my %comps = map { $_ => 1 } @comps;
}
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;
}
}
sub get_all_components {
- my $self = shift;
+ my ($self, $class) = @_;
my %components;
- my $container = $self->get_sub_container('component');
+ # FIXME - if we're getting from these containers, we need to either:
+ # - pass 'ctx' and 'accept_context_args' OR
+ # - make these params optional
+ foreach my $type (qw/model view controller /) {
+ my $container = $self->get_sub_container($type);
+
+ for my $component ($container->get_service_list) {
+ my $comp_service = $container->get_service($component);
- for my $component ($container->get_service_list) {
- my $comp = $container->resolve(
- service => $component
- );
- my $comp_name = ref $comp || $comp;
- $components{$comp_name} = $comp;
+ $components{$comp_service->catalyst_component_name} = $comp_service->get(ctx => $class);
+ }
}
return lock_hash %components;
return unless $type;
- my $component_service_name = "${type}_${name}";
-
# The 'component' sub-container will create the object, and store it's
# instance, which, by default, will live throughout the application.
# The model/view/controller sub-containers only reference the instance
my $instance_container = $self->get_sub_container('component');
my $accept_context_container = $self->get_sub_container($type);
+ # Custom containers might have added the service already
+ # We don't want to override that
+ return if $accept_context_container->has_service( $name );
+
+ my $component_service_name = "${type}_${name}";
+
$instance_container->add_service(
Catalyst::IOC::ConstructorInjection->new(
name => $component_service_name,
+ catalyst_component_name => $component,
class => $component,
lifecycle => 'Singleton',
dependencies => [
depends_on( '/application_name' ),
- depends_on( '/config' ),
],
)
- ) unless $instance_container->has_service( $component_service_name );
- # ^ custom containers might have added the service already.
- # we don't want to override that.
+ );
$accept_context_container->add_service(
Catalyst::IOC::BlockInjection->new(
name => $name,
+ catalyst_component_name => $component,
dependencies => [
depends_on( "/component/$component_service_name" ),
],
block => sub { shift->param($component_service_name) },
)
- ) unless $accept_context_container->has_service( $name );
- # ^ same as above
+ );
}
# FIXME: should this sub exist?