simplified a bit
[catagits/Catalyst-Runtime.git] / lib / Catalyst / SubContainer.pm
CommitLineData
59aacfa7 1package Catalyst::SubContainer;
2use Bread::Board;
3use Moose;
4use Catalyst::BlockInjection;
5
6extends 'Bread::Board::Container';
7
8sub get_component {
9 my ( $self, $name, $args ) = @_;
10 return $self->resolve( service => $name, parameters => { context => $args } );
11}
12
1f90ca59 13sub get_component_regexp {
14 my ( $self, $c, $name, $args ) = @_;
15
16 return
17 if $c->config->{disable_component_resolution_regex_fallback} && !ref $name;
18
19 my $appclass = ref $c || $c;
20 my $prefix = ucfirst $self->name;
21 my $p = substr $prefix, 0, 1;
22
23 my $query = ref $name ? $name : qr{$name}i;
24 $query =~ s/^${appclass}::($p|$prefix):://i;
25
1f90ca59 26 my @result = map {
ff974a7c 27 $self->get_component( $_, $args )
28 } grep { m/$query/ } $self->get_service_list;
1f90ca59 29
30 if (!ref $name && $result[0]) {
31 $c->log->warn( Carp::shortmess(qq(Found results for "${name}" using regexp fallback)) );
32 $c->log->warn( 'Relying on the regexp fallback behavior for component resolution' );
33 $c->log->warn( 'is unreliable and unsafe. You have been warned' );
34 return $result[0];
35 }
36
37 return @result;
38}
39
59aacfa7 401;