X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FIOC%2FContainer.pm;h=b89fd9669ee1e25b15191f6881eec2514239adb6;hb=8c199f8627c2d972d06aa0a98337ff7ba922d9af;hp=cb82f697f33ec7e45bfae1e95c63726cc00adefc;hpb=1a5adaee236dda2152a9d0fb1ca27d08f3f92777;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/IOC/Container.pm b/lib/Catalyst/IOC/Container.pm index cb82f69..b89fd96 100644 --- a/lib/Catalyst/IOC/Container.pm +++ b/lib/Catalyst/IOC/Container.pm @@ -669,16 +669,86 @@ sub _find_component_regexp { return @result; } +# FIXME +# what exactly should this method return? +# By default, for back-compatibility, we have two services for each component: +# - one in the model|view|controller sub-container +# - and another in the component sub-container +# the latter is a Singleton, it executes the COMPONENT method, and the first +# is executed at every call, executing ACCEPT_CONTEXT. It's just a layer. +# +# So the one in $type sub-container is pretty useless by default. But when the +# user overrides the container (which is what we want), the sub-container they +# will use is precisely $type, not 'component'. So for now, I'm returning both +# services, to decide later what to do. +# TODO +# add pod, remove code repetition +sub get_all_component_services { + my $self = shift; + + my %components; + my $components_container = $self->get_sub_container('component'); + + 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); + + my $key = $comp_service->catalyst_component_name; + my %values = ( + type => $type, + service => $comp_service, + ); + + my $comp_name = "${type}_${component}"; + if ($components_container->has_service($comp_name)) { + $values{backcompat_service} = $components_container->get_service($comp_name); + } + + $components{$key} = \%values; + } + } + + return lock_hash %components; +} + +# TODO +# add pod, remove code repetition +sub get_all_singleton_lifecycle_components { + my $self = shift; + + my %components; + my $components_container = $self->get_sub_container('component'); + + 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); + + my $key = $comp_service->catalyst_component_name; + my $lifecycle = $comp_service->lifecycle; + my $comp_name = "${type}_${component}"; + + if (defined $lifecycle && $lifecycle eq 'Singleton') { + $components{$key} = $comp_service->get; + } + elsif ($components_container->has_service($comp_name)) { + $components{$key} = $components_container->get_service($comp_name)->get; + } + } + } + + return lock_hash %components; +} + +# TODO +# remove code repetition sub get_all_components { my ($self, $class) = @_; my %components; - # FIXME - if we're getting from these containers, we need to either: - # - pass 'ctx' and 'accept_context_args' OR - # - make these params optional - # big problem when setting up the dispatcher - this method is called - # as $container->get_all_components('MyApp'). What to do with Request - # life cycles? foreach my $type (qw/model view controller /) { my $container = $self->get_sub_container($type);