fixing pod again
[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 => (
eea0c6e2 9 isa => 'Str|Undef',
10 is => 'ro',
a2c0d071 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
eea0c6e2 34# FIXME - is this sub ok?
35# is the name ok too?
b79f858d 36sub make_single_default {
37 my ( $self ) = @_;
38
39 my @complist = $self->get_service_list;
40
5be6c1d8 41 $self->_set_default_component( shift @complist )
b79f858d 42 if !$self->default_component && scalar @complist == 1;
43}
44
59aacfa7 451;
4f38bf4b 46
47__END__
48
49=pod
50
51=head1 NAME
52
a6c13ff4 53Catalyst::IOC::SubContainer - Container for models, controllers and views
4f38bf4b 54
2c2ed473 55=head1 SYNOPSIS
56
57=head1 DESCRIPTION
58
4f38bf4b 59=head1 METHODS
60
61=head2 get_component
62
eea0c6e2 63Gets the service of the container for the searched component. Also executes the ACCEPT_CONTEXT sub in the component, if it exists.
64
4f38bf4b 65=head2 get_component_regexp
66
eea0c6e2 67Gets all components from container that match a given regexp.
68
b79f858d 69=head2 make_single_default
70
eea0c6e2 71If the container has only one component, and no default has been defined, this method makes that one existing service the default.
72
4f38bf4b 73=head1 AUTHORS
74
75Catalyst Contributors, see Catalyst.pm
76
77=head1 COPYRIGHT
78
79This library is free software. You can redistribute it and/or modify it under
80the same terms as Perl itself.
81
82=cut