created default_component writer
[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,
5be6c1d8 12 writer => '_set_default_component',
a2c0d071 13);
14
59aacfa7 15sub get_component {
77e27f6e 16 my ( $self, $name, @args ) = @_;
4f38bf4b 17
18 return $self->resolve(
19 service => $name,
77e27f6e 20 parameters => { accept_context_args => \@args },
4f38bf4b 21 );
59aacfa7 22}
23
1f90ca59 24sub get_component_regexp {
5a53ef3d 25 my ( $self, $query, $c, @args ) = @_;
1f90ca59 26
1f90ca59 27 my @result = map {
77e27f6e 28 $self->get_component( $_, $c, @args )
ff974a7c 29 } grep { m/$query/ } $self->get_service_list;
1f90ca59 30
1f90ca59 31 return @result;
32}
33
b79f858d 34# FIXME: not the best name for a sub
35sub make_single_default {
36 my ( $self ) = @_;
37
38 my @complist = $self->get_service_list;
39
5be6c1d8 40 $self->_set_default_component( shift @complist )
b79f858d 41 if !$self->default_component && scalar @complist == 1;
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
b79f858d 60=head2 make_single_default
61
4f38bf4b 62=head1 AUTHORS
63
64Catalyst Contributors, see Catalyst.pm
65
66=head1 COPYRIGHT
67
68This library is free software. You can redistribute it and/or modify it under
69the same terms as Perl itself.
70
71=cut