ditto
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / SubContainer.pm
index 11c6657..3c2c434 100644 (file)
@@ -5,10 +5,11 @@ use Catalyst::IOC::BlockInjection;
 
 extends 'Bread::Board::Container';
 
-has disable_regex_fallback => (
-    is      => 'ro',
-    isa     => 'Bool',
-    default => 1,
+has default_component => (
+    isa      => 'Str|Undef',
+    is       => 'ro',
+    required => 0,
+    writer   => '_set_default_component',
 );
 
 sub get_component {
@@ -21,30 +22,26 @@ sub get_component {
 }
 
 sub get_component_regexp {
-    my ( $self, $name, $c, @args ) = @_;
-
-    return
-        if $self->disable_regex_fallback && !ref $name;
-
-    my $query   = ref $name ? $name : qr{$name}i;
-    my $appname = $self->parent->name;
-    $query      =~ s/^${appname}:://i;
-    $query      =~ s/[MVC]|(Model|View|Controller):://i;
+    my ( $self, $query, $c, @args ) = @_;
 
     my @result = map {
         $self->get_component( $_, $c, @args )
     } grep { m/$query/ } $self->get_service_list;
 
-    if (!ref $name && $result[0]) {
-        $c->log->warn( Carp::shortmess(qq(Found results for "${name}" using regexp fallback)) );
-        $c->log->warn( 'Relying on the regexp fallback behavior for component resolution' );
-        $c->log->warn( 'is unreliable and unsafe. You have been warned' );
-        return $result[0];
-    }
-
     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__
@@ -59,8 +56,16 @@ Catalyst::IOC::SubContainer - Container for models, controllers and views
 
 =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