Merge branch 'master' into gsoc_breadboard
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / SubContainer.pm
CommitLineData
a6c13ff4 1package Catalyst::IOC::SubContainer;
59aacfa7 2use Bread::Board;
3use Moose;
59aacfa7 4
5extends 'Bread::Board::Container';
6
a2c0d071 7has default_component => (
eea0c6e2 8 isa => 'Str|Undef',
9 is => 'ro',
8697f116 10 builder => '_build_default_component',
11 lazy => 1,
a2c0d071 12);
13
cd20de09 14sub _build_default_component {
8697f116 15 my ( $self ) = @_;
16
17 my @complist = $self->get_service_list;
18
19 scalar @complist == 1 ? $complist[0] : undef;
20}
21
22
59aacfa7 23sub get_component {
3f1b0032 24 my ( $self, $name, $ctx, @args ) = @_;
4f38bf4b 25
26 return $self->resolve(
27 service => $name,
3f1b0032 28 parameters => {
29 accept_context_args => [ $ctx, @args ],
30 ctx => $ctx,
31 },
4f38bf4b 32 );
59aacfa7 33}
34
1f90ca59 35sub get_component_regexp {
5a53ef3d 36 my ( $self, $query, $c, @args ) = @_;
1f90ca59 37
1f90ca59 38 my @result = map {
77e27f6e 39 $self->get_component( $_, $c, @args )
ff974a7c 40 } grep { m/$query/ } $self->get_service_list;
1f90ca59 41
1f90ca59 42 return @result;
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
797ba652 63Gets the service of the container for the searched component. Also executes
64the ACCEPT_CONTEXT sub in the component, if it exists.
eea0c6e2 65
4f38bf4b 66=head2 get_component_regexp
67
eea0c6e2 68Gets all components from container that match a given regexp.
69
b79f858d 70=head2 make_single_default
71
797ba652 72If the container has only one component, and no default has been defined,
73this method makes that one existing service the default.
eea0c6e2 74
4f38bf4b 75=head1 AUTHORS
76
77Catalyst Contributors, see Catalyst.pm
78
79=head1 COPYRIGHT
80
81This library is free software. You can redistribute it and/or modify it under
82the same terms as Perl itself.
83
84=cut