created default_component writer
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / SubContainer.pm
index 6d4f08f..afa8e3f 100644 (file)
@@ -5,6 +5,13 @@ use Catalyst::IOC::BlockInjection;
 
 extends 'Bread::Board::Container';
 
+has default_component => (
+    isa => 'Str|Undef',
+    is  => 'ro',
+    required => 0,
+    writer   => '_set_default_component',
+);
+
 sub get_component {
     my ( $self, $name, @args ) = @_;
 
@@ -17,11 +24,6 @@ sub get_component {
 sub get_component_regexp {
     my ( $self, $query, $c, @args ) = @_;
 
-    if (!ref $query) {
-        $c->log->warn("Looking for '$query', but nothing was found.");
-        return;
-    }
-
     my @result = map {
         $self->get_component( $_, $c, @args )
     } grep { m/$query/ } $self->get_service_list;
@@ -29,6 +31,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->_set_default_component( shift @complist )
+        if !$self->default_component && scalar @complist == 1;
+}
+
 1;
 
 __END__
@@ -45,6 +57,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