Commit | Line | Data |
a6c13ff4 |
1 | package Catalyst::IOC::SubContainer; |
59aacfa7 |
2 | use Bread::Board; |
3 | use Moose; |
a6c13ff4 |
4 | use Catalyst::IOC::BlockInjection; |
59aacfa7 |
5 | |
6 | extends 'Bread::Board::Container'; |
7 | |
a2c0d071 |
8 | has default_component => ( |
eea0c6e2 |
9 | isa => 'Str|Undef', |
10 | is => 'ro', |
a2c0d071 |
11 | required => 0, |
5be6c1d8 |
12 | writer => '_set_default_component', |
a2c0d071 |
13 | ); |
14 | |
59aacfa7 |
15 | sub 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 |
24 | sub 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 |
36 | sub 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 |
45 | 1; |
4f38bf4b |
46 | |
47 | __END__ |
48 | |
49 | =pod |
50 | |
51 | =head1 NAME |
52 | |
a6c13ff4 |
53 | Catalyst::IOC::SubContainer - Container for models, controllers and views |
4f38bf4b |
54 | |
55 | =head1 METHODS |
56 | |
57 | =head2 get_component |
58 | |
eea0c6e2 |
59 | Gets the service of the container for the searched component. Also executes the ACCEPT_CONTEXT sub in the component, if it exists. |
60 | |
4f38bf4b |
61 | =head2 get_component_regexp |
62 | |
eea0c6e2 |
63 | Gets all components from container that match a given regexp. |
64 | |
b79f858d |
65 | =head2 make_single_default |
66 | |
eea0c6e2 |
67 | If the container has only one component, and no default has been defined, this method makes that one existing service the default. |
68 | |
4f38bf4b |
69 | =head1 AUTHORS |
70 | |
71 | Catalyst Contributors, see Catalyst.pm |
72 | |
73 | =head1 COPYRIGHT |
74 | |
75 | This library is free software. You can redistribute it and/or modify it under |
76 | the same terms as Perl itself. |
77 | |
78 | =cut |