use Tree::Simple qw/use_weak_refs/;
use Tree::Simple::Visitor::FindByUID;
use Class::C3::Adopt::NEXT;
-use List::Util qw/first/;
+use Hash::Util qw/lock_hash/;
use List::MoreUtils qw/uniq/;
use attributes;
use utf8;
#I imagine that very few of these really need to be class variables. if any.
#maybe we should just make them attributes with a default?
-__PACKAGE__->mk_classdata($_) # XXX FIXME - components remove from here
- for qw/container components arguments dispatcher engine log dispatcher_class
+__PACKAGE__->mk_classdata($_)
+ for qw/container arguments dispatcher engine log dispatcher_class
engine_class context_class request_class response_class stats_class
setup_finished/;
$class->setup unless $Catalyst::__AM_RESTARTING;
}
- # Initialize our data structure
- $class->components( {} ); # XXX - Remove!
-
$class->setup_components;
if ( $class->debug ) { # XXX - Fixme to be a method on the container? (Or at least get a) data structure back from the container!!
if ( keys %{ $class->components } );
}
- # Add our self to components, since we are also a component
- if( $class->isa('Catalyst::Controller') ){
- $class->components->{$class} = $class;
- }
-
$class->setup_actions;
if ( $class->debug ) {
=cut
-# FIXME - We deal with ->components({'Foo' => 'Bar'})
-# however we DO NOT deal with ->components->{Foo} = 'Bar'
-# We should return a locked hash back to the user? So that if they try the latter, they
-# get breakage, rather than their addition being silently ignored?
-around components => sub {
- my $orig = shift;
- my $class = shift;
- my $comps = shift;
-
- return $class->$orig if ( !$comps );
+sub components {
+ my ( $class, $comps ) = @_;
-# FIXME: should this ugly kludge exist?
+ # FIXME: should this ugly kludge exist?
$class->setup_config unless defined $class->container;
-# FIXME: should there be a warning here, not to use this accessor to create the components?
- my $components = {};
-
my $containers;
$containers->{$_} = $class->container->get_sub_container($_) for qw(model view controller);
- for my $component ( keys %$comps ) {
- $components->{ $component } = $comps->{$component};
+ if ( $comps ) {
+ for my $component ( keys %$comps ) {
+ my ($type, $name) = _get_component_type_name($component);
- my ($type, $name) = _get_component_type_name($component);
+ $containers->{$type}->add_service(Catalyst::IOC::BlockInjection->new( name => $name, block => sub { return $class->setup_component($component) } ));
+ }
+ }
- $containers->{$type}->add_service(Catalyst::IOC::BlockInjection->new( name => $name, block => sub { return $class->setup_component($component) } ));
+ my %components;
+ for my $container (keys %$containers) {
+ my @service_list = $containers->{$container}->get_service_list;
+ for my $component (@service_list) {
+ $components{$component} =
+ $containers->{$container}->resolve(service => $component);
+ }
}
- return $class->$orig($components);
+ return lock_hash %components;
};
=head2 $c->context_class
$containers->{$_} = $class->container->get_sub_container($_) for qw(model view controller);
for my $component (@comps) {
- my $instance = $class->components->{ $component } = $class->setup_component($component);
+ my $instance = $class->setup_component($component);
if ( my ($type, $name) = _get_component_type_name($component, $search_extra) ) {
$containers->{$type}->add_service(Catalyst::IOC::BlockInjection->new( name => $name, block => sub { return $instance } ));
}
if (my ($type, $name) = _get_component_type_name($component, $search_extra)) {
$containers->{$type}->add_service(Catalyst::IOC::BlockInjection->new( name => $name, block => sub { return $class->setup_component($component) } ));
}
-
- # FIXME - Remove this!!
- $class->components->{ $component } = $class->setup_component($component);
}
}