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', |
8697f116 |
10 | builder => '_build_default_component', |
11 | lazy => 1, |
a2c0d071 |
12 | ); |
13 | |
8697f116 |
14 | sub _build_default_componentt { |
15 | my ( $self ) = @_; |
16 | |
17 | my @complist = $self->get_service_list; |
18 | |
19 | scalar @complist == 1 ? $complist[0] : undef; |
20 | } |
21 | |
22 | |
59aacfa7 |
23 | sub get_component { |
77e27f6e |
24 | my ( $self, $name, @args ) = @_; |
4f38bf4b |
25 | |
26 | return $self->resolve( |
27 | service => $name, |
77e27f6e |
28 | parameters => { accept_context_args => \@args }, |
4f38bf4b |
29 | ); |
59aacfa7 |
30 | } |
31 | |
1f90ca59 |
32 | sub get_component_regexp { |
5a53ef3d |
33 | my ( $self, $query, $c, @args ) = @_; |
1f90ca59 |
34 | |
1f90ca59 |
35 | my @result = map { |
77e27f6e |
36 | $self->get_component( $_, $c, @args ) |
ff974a7c |
37 | } grep { m/$query/ } $self->get_service_list; |
1f90ca59 |
38 | |
1f90ca59 |
39 | return @result; |
40 | } |
41 | |
59aacfa7 |
42 | 1; |
4f38bf4b |
43 | |
44 | __END__ |
45 | |
46 | =pod |
47 | |
48 | =head1 NAME |
49 | |
a6c13ff4 |
50 | Catalyst::IOC::SubContainer - Container for models, controllers and views |
4f38bf4b |
51 | |
2c2ed473 |
52 | =head1 SYNOPSIS |
53 | |
54 | =head1 DESCRIPTION |
55 | |
4f38bf4b |
56 | =head1 METHODS |
57 | |
58 | =head2 get_component |
59 | |
797ba652 |
60 | Gets the service of the container for the searched component. Also executes |
61 | the ACCEPT_CONTEXT sub in the component, if it exists. |
eea0c6e2 |
62 | |
4f38bf4b |
63 | =head2 get_component_regexp |
64 | |
eea0c6e2 |
65 | Gets all components from container that match a given regexp. |
66 | |
b79f858d |
67 | =head2 make_single_default |
68 | |
797ba652 |
69 | If the container has only one component, and no default has been defined, |
70 | this method makes that one existing service the default. |
eea0c6e2 |
71 | |
4f38bf4b |
72 | =head1 AUTHORS |
73 | |
74 | Catalyst Contributors, see Catalyst.pm |
75 | |
76 | =head1 COPYRIGHT |
77 | |
78 | This library is free software. You can redistribute it and/or modify it under |
79 | the same terms as Perl itself. |
80 | |
81 | =cut |