same for SubContainer.pm
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / SubContainer.pm
index 2751268..4870bf0 100644 (file)
@@ -1,14 +1,14 @@
 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',
+    isa      => 'Str|Undef',
+    is       => 'ro',
     required => 0,
+    writer   => '_set_default_component',
 );
 
 sub get_component {
@@ -30,6 +30,17 @@ 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__
@@ -40,12 +51,26 @@ __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.
+
 =head2 get_component_regexp
 
+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.
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm