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 | |
cd20de09 |
14 | sub _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 |
23 | sub 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 |
35 | sub 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 |
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 | |
2c2ed473 |
55 | =head1 SYNOPSIS |
56 | |
57 | =head1 DESCRIPTION |
58 | |
4f38bf4b |
59 | =head1 METHODS |
60 | |
61 | =head2 get_component |
62 | |
797ba652 |
63 | Gets the service of the container for the searched component. Also executes |
64 | the ACCEPT_CONTEXT sub in the component, if it exists. |
eea0c6e2 |
65 | |
4f38bf4b |
66 | =head2 get_component_regexp |
67 | |
eea0c6e2 |
68 | Gets all components from container that match a given regexp. |
69 | |
b79f858d |
70 | =head2 make_single_default |
71 | |
797ba652 |
72 | If the container has only one component, and no default has been defined, |
73 | this method makes that one existing service the default. |
eea0c6e2 |
74 | |
4f38bf4b |
75 | =head1 AUTHORS |
76 | |
77 | Catalyst Contributors, see Catalyst.pm |
78 | |
79 | =head1 COPYRIGHT |
80 | |
81 | This library is free software. You can redistribute it and/or modify it under |
82 | the same terms as Perl itself. |
83 | |
84 | =cut |