X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FIOC%2FSubContainer.pm;h=4870bf097a4f0f9382b43a012a380cb8a7a2a5a6;hb=9e6091e2f24701da88b4592f4192e6731faa4813;hp=95bb8d3a104723f8b6c0b77c938667c5189b1913;hpb=a6c13ff4f57e0e616547e468e970f03d3ee54ef9;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/IOC/SubContainer.pm b/lib/Catalyst/IOC/SubContainer.pm index 95bb8d3..4870bf0 100644 --- a/lib/Catalyst/IOC/SubContainer.pm +++ b/lib/Catalyst/IOC/SubContainer.pm @@ -1,46 +1,46 @@ 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', +); + sub get_component { - my ( $self, $name, $args ) = @_; + my ( $self, $name, @args ) = @_; return $self->resolve( service => $name, - parameters => { accept_context_args => $args }, + parameters => { accept_context_args => \@args }, ); } sub get_component_regexp { - my ( $self, $c, $name, $args ) = @_; - - return - if $c->config->{disable_component_resolution_regex_fallback} && !ref $name; - - my $appclass = ref $c || $c; - my $prefix = ucfirst $self->name; - my $p = substr $prefix, 0, 1; - - my $query = ref $name ? $name : qr{$name}i; - $query =~ s/^${appclass}::($p|$prefix):://i; + my ( $self, $query, $c, @args ) = @_; my @result = map { - $self->get_component( $_, $args ) + $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__ @@ -51,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