X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FIOC%2FSubContainer.pm;h=28c59ffa7aa00c6b63086dd248b5f53d149b043d;hb=1a5e7517716258d7ecfaf65a7b3a35234577b121;hp=3c2c434b7dc448c3f7d119a74d8cd71f963a73cd;hpb=eea0c6e27ff029024bd7352064eb033e9758cd81;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/IOC/SubContainer.pm b/lib/Catalyst/IOC/SubContainer.pm index 3c2c434..28c59ff 100644 --- a/lib/Catalyst/IOC/SubContainer.pm +++ b/lib/Catalyst/IOC/SubContainer.pm @@ -1,23 +1,34 @@ package Catalyst::IOC::SubContainer; use Bread::Board; use Moose; -use Catalyst::IOC::BlockInjection; extends 'Bread::Board::Container'; has default_component => ( isa => 'Str|Undef', is => 'ro', - required => 0, - writer => '_set_default_component', + builder => '_build_default_component', + lazy => 1, ); +sub _build_default_component { + my ( $self ) = @_; + + my @complist = $self->get_service_list; + + scalar @complist == 1 ? $complist[0] : undef; +} + + sub get_component { - my ( $self, $name, @args ) = @_; + my ( $self, $name, $ctx, @args ) = @_; return $self->resolve( service => $name, - parameters => { accept_context_args => \@args }, + parameters => { + accept_context_args => [ $ctx, @args ], + ctx => $ctx, + }, ); } @@ -31,17 +42,6 @@ sub get_component_regexp { return @result; } -# FIXME - is this sub ok? -# is the name ok too? -sub make_single_default { - my ( $self ) = @_; - - my @complist = $self->get_service_list; - - $self->_set_default_component( shift @complist ) - if !$self->default_component && scalar @complist == 1; -} - 1; __END__ @@ -52,11 +52,16 @@ __END__ Catalyst::IOC::SubContainer - Container for models, controllers and views +=head1 SYNOPSIS + +=head1 DESCRIPTION + =head1 METHODS =head2 get_component -Gets the service of the container for the searched component. Also executes the ACCEPT_CONTEXT sub in the component, if it exists. +Gets the service of the container for the searched component. Also executes +the ACCEPT_CONTEXT sub in the component, if it exists. =head2 get_component_regexp @@ -64,7 +69,8 @@ Gets all components from container that match a given regexp. =head2 make_single_default -If the container has only one component, and no default has been defined, this method makes that one existing service the default. +If the container has only one component, and no default has been defined, +this method makes that one existing service the default. =head1 AUTHORS