make_single_default sub
[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
a2c0d071 8has default_component => (
9 isa => 'Str|Undef',
10 is => 'ro',
11 required => 0,
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 {
5a53ef3d 24 my ( $self, $query, $c, @args ) = @_;
1f90ca59 25
1f90ca59 26 my @result = map {
77e27f6e 27 $self->get_component( $_, $c, @args )
ff974a7c 28 } grep { m/$query/ } $self->get_service_list;
1f90ca59 29
1f90ca59 30 return @result;
31}
32
b79f858d 33# FIXME: not the best name for a sub
34sub make_single_default {
35 my ( $self ) = @_;
36
37 my @complist = $self->get_service_list;
38
39 $self->default_component( shift @complist )
40 if !$self->default_component && scalar @complist == 1;
41}
42
59aacfa7 431;
4f38bf4b 44
45__END__
46
47=pod
48
49=head1 NAME
50
a6c13ff4 51Catalyst::IOC::SubContainer - Container for models, controllers and views
4f38bf4b 52
53=head1 METHODS
54
55=head2 get_component
56
57=head2 get_component_regexp
58
b79f858d 59=head2 make_single_default
60
4f38bf4b 61=head1 AUTHORS
62
63Catalyst Contributors, see Catalyst.pm
64
65=head1 COPYRIGHT
66
67This library is free software. You can redistribute it and/or modify it under
68the same terms as Perl itself.
69
70=cut