moving classes/roles to Catalyst::IOC::* namespace
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / SubContainer.pm
CommitLineData
a6c13ff4 1package Catalyst::IOC::SubContainer;
59aacfa7 2use Bread::Board;
3use Moose;
a6c13ff4 4use Catalyst::IOC::BlockInjection;
59aacfa7 5
6extends 'Bread::Board::Container';
7
8sub get_component {
9 my ( $self, $name, $args ) = @_;
4f38bf4b 10
11 return $self->resolve(
12 service => $name,
13 parameters => { accept_context_args => $args },
14 );
59aacfa7 15}
16
1f90ca59 17sub get_component_regexp {
18 my ( $self, $c, $name, $args ) = @_;
19
20 return
21 if $c->config->{disable_component_resolution_regex_fallback} && !ref $name;
22
23 my $appclass = ref $c || $c;
24 my $prefix = ucfirst $self->name;
25 my $p = substr $prefix, 0, 1;
26
27 my $query = ref $name ? $name : qr{$name}i;
28 $query =~ s/^${appclass}::($p|$prefix):://i;
29
1f90ca59 30 my @result = map {
ff974a7c 31 $self->get_component( $_, $args )
32 } grep { m/$query/ } $self->get_service_list;
1f90ca59 33
34 if (!ref $name && $result[0]) {
35 $c->log->warn( Carp::shortmess(qq(Found results for "${name}" using regexp fallback)) );
36 $c->log->warn( 'Relying on the regexp fallback behavior for component resolution' );
37 $c->log->warn( 'is unreliable and unsafe. You have been warned' );
38 return $result[0];
39 }
40
41 return @result;
42}
43
59aacfa7 441;
4f38bf4b 45
46__END__
47
48=pod
49
50=head1 NAME
51
a6c13ff4 52Catalyst::IOC::SubContainer - Container for models, controllers and views
4f38bf4b 53
54=head1 METHODS
55
56=head2 get_component
57
58=head2 get_component_regexp
59
60=head1 AUTHORS
61
62Catalyst Contributors, see Catalyst.pm
63
64=head1 COPYRIGHT
65
66This library is free software. You can redistribute it and/or modify it under
67the same terms as Perl itself.
68
69=cut