Removed references to BlockInjection, and created validation for parameters in accept...
[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',
a2c0d071 10 required => 0,
5be6c1d8 11 writer => '_set_default_component',
a2c0d071 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
eea0c6e2 33# FIXME - is this sub ok?
34# is the name ok too?
b79f858d 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
2c2ed473 54=head1 SYNOPSIS
55
56=head1 DESCRIPTION
57
4f38bf4b 58=head1 METHODS
59
60=head2 get_component
61
eea0c6e2 62Gets the service of the container for the searched component. Also executes the ACCEPT_CONTEXT sub in the component, if it exists.
63
4f38bf4b 64=head2 get_component_regexp
65
eea0c6e2 66Gets all components from container that match a given regexp.
67
b79f858d 68=head2 make_single_default
69
eea0c6e2 70If the container has only one component, and no default has been defined, this method makes that one existing service the default.
71
4f38bf4b 72=head1 AUTHORS
73
74Catalyst Contributors, see Catalyst.pm
75
76=head1 COPYRIGHT
77
78This library is free software. You can redistribute it and/or modify it under
79the same terms as Perl itself.
80
81=cut