remove make_single_default
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / SubContainer.pm
1 package Catalyst::IOC::SubContainer;
2 use Bread::Board;
3 use Moose;
4
5 extends 'Bread::Board::Container';
6
7 has default_component => (
8     isa      => 'Str|Undef',
9     is       => 'ro',
10     builder  => '_build_default_component',
11     lazy     => 1,
12 );
13
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
23 sub get_component {
24     my ( $self, $name, @args ) = @_;
25
26     return $self->resolve(
27         service    => $name,
28         parameters => { accept_context_args => \@args },
29     );
30 }
31
32 sub get_component_regexp {
33     my ( $self, $query, $c, @args ) = @_;
34
35     my @result = map {
36         $self->get_component( $_, $c, @args )
37     } grep { m/$query/ } $self->get_service_list;
38
39     return @result;
40 }
41
42 1;
43
44 __END__
45
46 =pod
47
48 =head1 NAME
49
50 Catalyst::IOC::SubContainer - Container for models, controllers and views
51
52 =head1 SYNOPSIS
53
54 =head1 DESCRIPTION
55
56 =head1 METHODS
57
58 =head2 get_component
59
60 Gets the service of the container for the searched component. Also executes
61 the ACCEPT_CONTEXT sub in the component, if it exists.
62
63 =head2 get_component_regexp
64
65 Gets all components from container that match a given regexp.
66
67 =head2 make_single_default
68
69 If the container has only one component, and no default has been defined,
70 this method makes that one existing service the default.
71
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