changing get_component and get_component_args
[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
b06ded69 8has disable_regex_fallback => (
9 is => 'ro',
10 isa => 'Bool',
11 default => 1,
12);
13
59aacfa7 14sub get_component {
77e27f6e 15 my ( $self, $name, @args ) = @_;
4f38bf4b 16
17 return $self->resolve(
18 service => $name,
77e27f6e 19 parameters => { accept_context_args => \@args },
4f38bf4b 20 );
59aacfa7 21}
22
1f90ca59 23sub get_component_regexp {
77e27f6e 24 my ( $self, $name, $c, @args ) = @_;
1f90ca59 25
26 return
b06ded69 27 if $self->disable_regex_fallback && !ref $name;
1f90ca59 28
77e27f6e 29 my $query = ref $name ? $name : qr{$name}i;
30 my $appname = $self->parent->name;
31 $query =~ s/^${appname}:://i;
32 $query =~ s/[MVC]|(Model|View|Controller):://i;
1f90ca59 33
1f90ca59 34 my @result = map {
77e27f6e 35 $self->get_component( $_, $c, @args )
ff974a7c 36 } grep { m/$query/ } $self->get_service_list;
1f90ca59 37
38 if (!ref $name && $result[0]) {
39 $c->log->warn( Carp::shortmess(qq(Found results for "${name}" using regexp fallback)) );
40 $c->log->warn( 'Relying on the regexp fallback behavior for component resolution' );
41 $c->log->warn( 'is unreliable and unsafe. You have been warned' );
42 return $result[0];
43 }
44
45 return @result;
46}
47
59aacfa7 481;
4f38bf4b 49
50__END__
51
52=pod
53
54=head1 NAME
55
a6c13ff4 56Catalyst::IOC::SubContainer - Container for models, controllers and views
4f38bf4b 57
58=head1 METHODS
59
60=head2 get_component
61
62=head2 get_component_regexp
63
64=head1 AUTHORS
65
66Catalyst Contributors, see Catalyst.pm
67
68=head1 COPYRIGHT
69
70This library is free software. You can redistribute it and/or modify it under
71the same terms as Perl itself.
72
73=cut