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