From: André Walker Date: Mon, 11 Jul 2011 23:19:56 +0000 (-0300) Subject: make_single_default sub X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=b79f858d1c7bc042ba8dc8b33e66a71902266754 make_single_default sub --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 134f5b6..ad387c0 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1462,7 +1462,6 @@ around components => sub { my ($type, $name) = _get_component_type_name($component); -# FIXME: shouldn't the service name be $name? $containers->{$type}->add_service(Catalyst::IOC::BlockInjection->new( name => $name, block => sub { return $class->setup_component($component) } )); } @@ -2382,6 +2381,9 @@ sub setup_components { $class->components->{ $component } = $class->setup_component($component); } } + + $containers->{model}->make_single_default; + $containers->{view}->make_single_default; } sub _get_component_type_name { diff --git a/lib/Catalyst/IOC/SubContainer.pm b/lib/Catalyst/IOC/SubContainer.pm index 2751268..8ebbceb 100644 --- a/lib/Catalyst/IOC/SubContainer.pm +++ b/lib/Catalyst/IOC/SubContainer.pm @@ -30,6 +30,16 @@ sub get_component_regexp { return @result; } +# FIXME: not the best name for a sub +sub make_single_default { + my ( $self ) = @_; + + my @complist = $self->get_service_list; + + $self->default_component( shift @complist ) + if !$self->default_component && scalar @complist == 1; +} + 1; __END__ @@ -46,6 +56,8 @@ Catalyst::IOC::SubContainer - Container for models, controllers and views =head2 get_component_regexp +=head2 make_single_default + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm