POD and sensible name for ACCEPT_CONTEXT args
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / SubContainer.pm
1 package Catalyst::IOC::SubContainer;
2 use Bread::Board;
3 use Moose;
4 use Catalyst::IOC::BlockInjection;
5
6 extends 'Bread::Board::Container';
7
8 sub get_component {
9     my ( $self, $name, $args ) = @_;
10
11     return $self->resolve(
12         service    => $name,
13         parameters => { accept_context_args => $args },
14     );
15 }
16
17 sub 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
30     my @result = map {
31         $self->get_component( $_, $args )
32     } grep { m/$query/ } $self->get_service_list;
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
44 1;
45
46 __END__
47
48 =pod
49
50 =head1 NAME
51
52 Catalyst::IOC::SubContainer - Container for models, controllers and views
53
54 =head1 METHODS
55
56 =head2 get_component
57
58 =head2 get_component_regexp
59
60 =head1 AUTHORS
61
62 Catalyst Contributors, see Catalyst.pm
63
64 =head1 COPYRIGHT
65
66 This library is free software. You can redistribute it and/or modify it under
67 the same terms as Perl itself.
68
69 =cut