remove make_single_default
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Container.pm
1 package Catalyst::IOC::Container;
2 use Bread::Board;
3 use Moose;
4 use Config::Any;
5 use Data::Visitor::Callback;
6 use Catalyst::Utils ();
7 use Devel::InnerPackage ();
8 use Hash::Util qw/lock_hash/;
9 use MooseX::Types::LoadableClass qw/ LoadableClass /;
10 use Moose::Util;
11 use Catalyst::IOC::BlockInjection;
12 use Catalyst::IOC::ConstructorInjection;
13 use Module::Pluggable::Object ();
14 use namespace::autoclean;
15
16 extends 'Bread::Board::Container';
17
18 has config_local_suffix => (
19     is      => 'ro',
20     isa     => 'Str',
21     default => 'local',
22 );
23
24 has driver => (
25     is      => 'ro',
26     isa     => 'HashRef',
27     default => sub { +{} },
28 );
29
30 has file => (
31     is      => 'ro',
32     isa     => 'Str',
33     default => '',
34 );
35
36 has substitutions => (
37     is      => 'ro',
38     isa     => 'HashRef',
39     default => sub { +{} },
40 );
41
42 has application_name => (
43     is       => 'ro',
44     isa      => 'Str',
45     required => 1,
46 );
47
48 has sub_container_class => (
49     isa     => LoadableClass,
50     is      => 'ro',
51     coerce  => 1,
52     default => 'Catalyst::IOC::SubContainer',
53     handles => {
54         new_sub_container => 'new',
55     }
56 );
57
58 sub BUILD {
59     my ( $self, $params ) = @_;
60
61     $self->add_service(
62         $self->${\"build_${_}_service"}
63     ) for qw/
64         substitutions
65         file
66         driver
67         application_name
68         prefix
69         extensions
70         path
71         config
72         raw_config
73         global_files
74         local_files
75         global_config
76         local_config
77         class_config
78         config_local_suffix
79         config_path
80         locate_components
81     /;
82
83     my $config = $self->resolve( service => 'config' );
84
85     $self->add_sub_container(
86         $self->build_component_subcontainer
87     );
88
89     $self->add_sub_container(
90         $self->build_controller_subcontainer
91     );
92
93     $self->add_sub_container(
94         $self->build_view_subcontainer(
95             default_component => $config->{default_view},
96         )
97     );
98
99     $self->add_sub_container(
100         $self->build_model_subcontainer(
101             default_component => $config->{default_model},
102         )
103     );
104 }
105
106 sub build_model_subcontainer {
107     my $self = shift;
108
109     return $self->new_sub_container( @_,
110         name => 'model',
111     );
112 }
113
114 sub build_view_subcontainer {
115     my $self = shift;
116
117     return $self->new_sub_container( @_,
118         name => 'view',
119     );
120 }
121
122 sub build_controller_subcontainer {
123     my $self = shift;
124
125     return $self->new_sub_container(
126         name => 'controller',
127     );
128 }
129
130 sub build_component_subcontainer {
131     my $self = shift;
132
133     return Bread::Board::Container->new(
134         name => 'component',
135     );
136 }
137
138 sub build_application_name_service {
139     my $self = shift;
140
141     return Bread::Board::Literal->new( name => 'application_name', value => $self->application_name );
142 }
143
144 sub build_driver_service {
145     my $self = shift;
146
147     return Bread::Board::Literal->new( name => 'driver', value => $self->driver );
148 }
149
150 sub build_file_service {
151     my $self = shift;
152
153     return Bread::Board::Literal->new( name => 'file', value => $self->file );
154 }
155
156 sub build_substitutions_service {
157     my $self = shift;
158
159     return Bread::Board::Literal->new( name => 'substitutions', value => $self->substitutions );
160 }
161
162 sub build_extensions_service {
163     my $self = shift;
164
165     return Bread::Board::BlockInjection->new(
166         lifecycle => 'Singleton',
167         name => 'extensions',
168         block => sub {
169             return \@{Config::Any->extensions};
170         },
171     );
172 }
173
174 sub build_prefix_service {
175     my $self = shift;
176
177     return Bread::Board::BlockInjection->new(
178         lifecycle => 'Singleton',
179         name => 'prefix',
180         block => sub {
181             return Catalyst::Utils::appprefix( shift->param('application_name') );
182         },
183         dependencies => [ depends_on('application_name') ],
184     );
185 }
186
187 sub build_path_service {
188     my $self = shift;
189
190     return Bread::Board::BlockInjection->new(
191         lifecycle => 'Singleton',
192         name => 'path',
193         block => sub {
194             my $s = shift;
195
196             return Catalyst::Utils::env_value( $s->param('application_name'), 'CONFIG' )
197             || $s->param('file')
198             || $s->param('application_name')->path_to( $s->param('prefix') );
199         },
200         dependencies => [ depends_on('file'), depends_on('application_name'), depends_on('prefix') ],
201     );
202 }
203
204 sub build_config_service {
205     my $self = shift;
206
207     return Bread::Board::BlockInjection->new(
208         lifecycle => 'Singleton',
209         name => 'config',
210         block => sub {
211             my $s = shift;
212
213             my $v = Data::Visitor::Callback->new(
214                 plain_value => sub {
215                     return unless defined $_;
216                     return $self->_config_substitutions( $s->param('application_name'), $s->param('substitutions'), $_ );
217                 }
218
219             );
220             $v->visit( $s->param('raw_config') );
221         },
222         dependencies => [ depends_on('application_name'), depends_on('raw_config'), depends_on('substitutions') ],
223     );
224 }
225
226 sub build_raw_config_service {
227     my $self = shift;
228
229     return Bread::Board::BlockInjection->new(
230         lifecycle => 'Singleton',
231         name => 'raw_config',
232         block => sub {
233             my $s = shift;
234
235             my @global = @{$s->param('global_config')};
236             my @locals = @{$s->param('local_config')};
237
238             my $config = $s->param('class_config');
239
240             for my $cfg (@global, @locals) {
241                 for (keys %$cfg) {
242                     $config = Catalyst::Utils::merge_hashes( $config, $cfg->{$_} );
243                 }
244             }
245
246             return $config;
247         },
248         dependencies => [ depends_on('global_config'), depends_on('local_config'), depends_on('class_config') ],
249     );
250 }
251
252 sub build_global_files_service {
253     my $self = shift;
254
255     return Bread::Board::BlockInjection->new(
256         lifecycle => 'Singleton',
257         name => 'global_files',
258         block => sub {
259             my $s = shift;
260
261             my ( $path, $extension ) = @{$s->param('config_path')};
262
263             my @extensions = @{$s->param('extensions')};
264
265             my @files;
266             if ( $extension ) {
267                 die "Unable to handle files with the extension '${extension}'" unless grep { $_ eq $extension } @extensions;
268                 push @files, $path;
269             } else {
270                 @files = map { "$path.$_" } @extensions;
271             }
272             return \@files;
273         },
274         dependencies => [ depends_on('extensions'), depends_on('config_path') ],
275     );
276 }
277
278 sub build_local_files_service {
279     my $self = shift;
280
281     return Bread::Board::BlockInjection->new(
282         lifecycle => 'Singleton',
283         name => 'local_files',
284         block => sub {
285             my $s = shift;
286
287             my ( $path, $extension ) = @{$s->param('config_path')};
288             my $suffix = $s->param('config_local_suffix');
289
290             my @extensions = @{$s->param('extensions')};
291
292             my @files;
293             if ( $extension ) {
294                 die "Unable to handle files with the extension '${extension}'" unless grep { $_ eq $extension } @extensions;
295                 $path =~ s{\.$extension}{_$suffix.$extension};
296                 push @files, $path;
297             } else {
298                 @files = map { "${path}_${suffix}.$_" } @extensions;
299             }
300             return \@files;
301         },
302         dependencies => [ depends_on('extensions'), depends_on('config_path'), depends_on('config_local_suffix') ],
303     );
304 }
305
306 sub build_class_config_service {
307     my $self = shift;
308
309     return Bread::Board::BlockInjection->new(
310         lifecycle => 'Singleton',
311         name => 'class_config',
312         block => sub {
313             my $s   = shift;
314             my $app = $s->param('application_name');
315
316             # Container might be called outside Catalyst context
317             return {} unless Class::MOP::is_class_loaded($app);
318
319             # config might not have been defined
320             return $app->config || {};
321         },
322         dependencies => [ depends_on('application_name') ],
323     );
324 }
325
326 sub build_global_config_service {
327     my $self = shift;
328
329     return Bread::Board::BlockInjection->new(
330         lifecycle => 'Singleton',
331         name => 'global_config',
332         block => sub {
333             my $s = shift;
334
335             return Config::Any->load_files({
336                 files       => $s->param('global_files'),
337                 filter      => \&_fix_syntax,
338                 use_ext     => 1,
339                 driver_args => $s->param('driver'),
340             });
341         },
342         dependencies => [ depends_on('global_files') ],
343     );
344 }
345
346 sub build_local_config_service {
347     my $self = shift;
348
349     return Bread::Board::BlockInjection->new(
350         lifecycle => 'Singleton',
351         name => 'local_config',
352         block => sub {
353             my $s = shift;
354
355             return Config::Any->load_files({
356                 files       => $s->param('local_files'),
357                 filter      => \&_fix_syntax,
358                 use_ext     => 1,
359                 driver_args => $s->param('driver'),
360             });
361         },
362         dependencies => [ depends_on('local_files') ],
363     );
364 }
365
366 sub build_config_path_service {
367     my $self = shift;
368
369     return Bread::Board::BlockInjection->new(
370         lifecycle => 'Singleton',
371         name => 'config_path',
372         block => sub {
373             my $s = shift;
374
375             my $path = $s->param('path');
376             my $prefix = $s->param('prefix');
377
378             my ( $extension ) = ( $path =~ m{\.(.{1,4})$} );
379
380             if ( -d $path ) {
381                 $path =~ s{[\/\\]$}{};
382                 $path .= "/$prefix";
383             }
384
385             return [ $path, $extension ];
386         },
387         dependencies => [ depends_on('prefix'), depends_on('path') ],
388     );
389 }
390
391 sub build_config_local_suffix_service {
392     my $self = shift;
393
394     return Bread::Board::BlockInjection->new(
395         lifecycle => 'Singleton',
396         name => 'config_local_suffix',
397         block => sub {
398             my $s = shift;
399             my $suffix = Catalyst::Utils::env_value( $s->param('application_name'), 'CONFIG_LOCAL_SUFFIX' ) || $self->config_local_suffix;
400
401             return $suffix;
402         },
403         dependencies => [ depends_on('application_name') ],
404     );
405 }
406
407 sub build_locate_components_service {
408     my $self = shift;
409
410     return Bread::Board::BlockInjection->new(
411         lifecycle => 'Singleton',
412         name      => 'locate_components',
413         block     => sub {
414             my $s      = shift;
415             my $class  = $s->param('application_name');
416             my $config = $s->param('config')->{ setup_components };
417
418             Catalyst::Exception->throw(
419                 qq{You are using search_extra config option. That option is\n} .
420                 qq{deprecated, please refer to the documentation for\n} .
421                 qq{other ways of achieving the same results.\n}
422             ) if delete $config->{ search_extra };
423
424             my @paths = qw( ::Controller ::C ::Model ::M ::View ::V );
425
426             my $locator = Module::Pluggable::Object->new(
427                 search_path => [ map { s/^(?=::)/$class/; $_; } @paths ],
428                 %$config
429             );
430
431             return [ $locator->plugins ];
432         },
433         dependencies => [ depends_on('application_name'), depends_on('config') ],
434     );
435 }
436
437 sub setup_components {
438     my $self = shift;
439     my $class = $self->resolve( service => 'application_name' );
440     my @comps = @{ $self->resolve( service => 'locate_components' ) };
441     my %comps = map { $_ => 1 } @comps;
442     my $deprecatedcatalyst_component_names = 0;
443
444     for my $component ( @comps ) {
445
446         # We pass ignore_loaded here so that overlay files for (e.g.)
447         # Model::DBI::Schema sub-classes are loaded - if it's in @comps
448         # we know M::P::O found a file on disk so this is safe
449
450         Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } );
451     }
452
453     for my $component (@comps) {
454         $self->add_component( $component );
455         # FIXME - $instance->expand_modules() is broken
456         my @expanded_components = $self->expand_component_module( $component );
457
458         if (
459             !$deprecatedcatalyst_component_names &&
460             ($deprecatedcatalyst_component_names = $component =~ m/::[CMV]::/) ||
461             ($deprecatedcatalyst_component_names = grep { /::[CMV]::/ } @expanded_components)
462         ) {
463             # FIXME - should I be calling warn here?
464             # Maybe it's time to remove it, or become fatal
465             $class->log->warn(qq{Your application is using the deprecated ::[MVC]:: type naming scheme.\n}.
466                 qq{Please switch your class names to ::Model::, ::View:: and ::Controller: as appropriate.\n}
467             );
468         }
469
470         for my $component (@expanded_components) {
471             $self->add_component( $component )
472                 unless $comps{$component};
473         }
474     }
475 }
476
477 sub _fix_syntax {
478     my $config     = shift;
479     my @components = (
480         map +{
481             prefix => $_ eq 'Component' ? '' : $_ . '::',
482             values => delete $config->{ lc $_ } || delete $config->{ $_ }
483         },
484         grep { ref $config->{ lc $_ } || ref $config->{ $_ } }
485             qw( Component Model M View V Controller C Plugin )
486     );
487
488     foreach my $comp ( @components ) {
489         my $prefix = $comp->{ prefix };
490         foreach my $element ( keys %{ $comp->{ values } } ) {
491             $config->{ "$prefix$element" } = $comp->{ values }->{ $element };
492         }
493     }
494 }
495
496 sub _config_substitutions {
497     my ( $self, $name, $subs, $arg ) = @_;
498
499     $subs->{ HOME } ||= sub { shift->path_to( '' ); };
500     $subs->{ ENV } ||=
501         sub {
502             my ( $c, $v ) = @_;
503             if (! defined($ENV{$v})) {
504                 Catalyst::Exception->throw( message =>
505                     "Missing environment variable: $v" );
506                 return "";
507             } else {
508                 return $ENV{ $v };
509             }
510         };
511     $subs->{ path_to } ||= sub { shift->path_to( @_ ); };
512     $subs->{ literal } ||= sub { return $_[ 1 ]; };
513     my $subsre = join( '|', keys %$subs );
514
515     $arg =~ s{__($subsre)(?:\((.+?)\))?__}{ $subs->{ $1 }->( $name, $2 ? split( /,/, $2 ) : () ) }eg;
516     return $arg;
517 }
518
519 sub get_component_from_sub_container {
520     my ( $self, $sub_container_name, $name, $c, @args ) = @_;
521
522     my $sub_container = $self->get_sub_container( $sub_container_name );
523
524     if (!$name) {
525         my $default = $sub_container->default_component;
526
527         return $sub_container->get_component( $default, $c, @args )
528             if $default && $sub_container->has_service( $default );
529
530         # FIXME - should I be calling $c->log->warn here?
531         # this is never a controller, so this is safe
532         $c->log->warn( "Calling \$c->$sub_container_name() is not supported unless you specify one of:" );
533         $c->log->warn( "* \$c->config(default_$sub_container_name => 'the name of the default $sub_container_name to use')" );
534         $c->log->warn( "* \$c->stash->{current_$sub_container_name} # the name of the view to use for this request" );
535         $c->log->warn( "* \$c->stash->{current_${sub_container_name}_instance} # the instance of the $sub_container_name to use for this request" );
536
537         return;
538     }
539
540     return $sub_container->get_component_regexp( $name, $c, @args )
541         if ref $name;
542
543     return $sub_container->get_component( $name, $c, @args )
544         if $sub_container->has_service( $name );
545
546     $c->log->warn(
547         "Attempted to use $sub_container_name '$name', " .
548         "but it does not exist"
549     );
550
551     return;
552 }
553
554 sub find_component {
555     my ( $self, $component, @args ) = @_;
556     my ( $type, $name ) = _get_component_type_name($component);
557     my @result;
558
559     return $self->get_component_from_sub_container(
560         $type, $name, @args
561     ) if $type;
562
563     my $query = ref $component
564               ? $component
565               : qr{^$component$}
566               ;
567
568     for my $subcontainer_name (qw/model view controller/) {
569         my $subcontainer = $self->get_sub_container( $subcontainer_name );
570         my @components   = $subcontainer->get_service_list;
571         @result          = grep { m{$component} } @components;
572
573         return map { $subcontainer->get_component( $_, @args ) } @result
574             if @result;
575     }
576
577     # one last search for things like $c->comp(qr/::M::/)
578     @result = $self->find_component_regexp(
579         $component, @args
580     ) if !@result and ref $component;
581
582     # it expects an empty list on failed searches
583     return @result;
584 }
585
586 sub find_component_regexp {
587     my ( $self, $component, @args ) = @_;
588     my @result;
589
590     my @components = grep { m{$component} } keys %{ $self->get_all_components };
591
592     for (@components) {
593         my ($type, $name) = _get_component_type_name($_);
594
595         push @result, $self->get_component_from_sub_container(
596             $type, $name, @args
597         ) if $type;
598     }
599
600     return @result;
601 }
602
603 sub get_all_components {
604     my $self = shift;
605     my %components;
606
607     my $container = $self->get_sub_container('component');
608
609     for my $component ($container->get_service_list) {
610         my $comp = $container->resolve(
611             service => $component
612         );
613         my $comp_name = ref $comp || $comp;
614         $components{$comp_name} = $comp;
615     }
616
617     return lock_hash %components;
618 }
619
620 sub add_component {
621     my ( $self, $component ) = @_;
622     my ( $type, $name ) = _get_component_type_name($component);
623
624     return unless $type;
625
626     my $component_service_name = "${type}_${name}";
627
628     # The 'component' sub-container will create the object, and store it's
629     # instance, which, by default, will live throughout the application.
630     # The model/view/controller sub-containers only reference the instance
631     # held in the aforementioned sub-container, and execute the ACCEPT_CONTEXT
632     # sub every time they are called, when it exists.
633     my $instance_container       = $self->get_sub_container('component');
634     my $accept_context_container = $self->get_sub_container($type);
635
636     $instance_container->add_service(
637         Catalyst::IOC::ConstructorInjection->new(
638             name      => $component_service_name,
639             class     => $component,
640             lifecycle => 'Singleton',
641             dependencies => [
642                 depends_on( '/application_name' ),
643                 depends_on( '/config' ),
644             ],
645         )
646     ) unless $instance_container->has_service( $component_service_name );
647     # ^ custom containers might have added the service already.
648     # we don't want to override that.
649
650     $accept_context_container->add_service(
651         Catalyst::IOC::BlockInjection->new(
652             name         => $name,
653             dependencies => [
654                 depends_on( "/component/$component_service_name" ),
655             ],
656             block => sub { shift->param($component_service_name) },
657         )
658     ) unless $accept_context_container->has_service( $name );
659     # ^ same as above
660 }
661
662 # FIXME: should this sub exist?
663 # should it be moved to Catalyst::Utils,
664 # or replaced by something already existing there?
665 sub _get_component_type_name {
666     my ( $component ) = @_;
667
668     my @parts = split /::/, $component;
669
670     while (my $type = shift @parts) {
671         return ('controller', join '::', @parts)
672             if $type =~ /^(c|controller)$/i;
673
674         return ('model', join '::', @parts)
675             if $type =~ /^(m|model)$/i;
676
677         return ('view', join '::', @parts)
678             if $type =~ /^(v|view)$/i;
679     }
680
681     return (undef, $component);
682 }
683
684 sub expand_component_module {
685     my ( $class, $module ) = @_;
686     return Devel::InnerPackage::list_packages( $module );
687 }
688
689 1;
690
691 __END__
692
693 =pod
694
695 =head1 NAME
696
697 Catalyst::Container - IOC for Catalyst components
698
699 =head1 SYNOPSIS
700
701 =head1 DESCRIPTION
702
703 =head1 METHODS
704
705 =head1 Building Containers
706
707 =head2 build_component_subcontainer
708
709 Container that stores all components, i.e. all models, views and controllers
710 together. Each service is an instance of the actual component, and by default
711 it lives while the application is running. Retrieving components from this
712 subcontainer will instantiate the component, if it hasn't been instantiated
713 already, but will not execute ACCEPT_CONTEXT.
714
715 =head2 build_model_subcontainer
716
717 Container that stores references for all models that are inside the components
718 subcontainer. Retrieving a model triggers ACCEPT_CONTEXT, if it exists.
719
720 =head2 build_view_subcontainer
721
722 Same as L<build_model_subcontainer>, but for views.
723
724 =head2 build_controller_subcontainer
725
726 Same as L<build_model_subcontainer>, but for controllers.
727
728 =head1 Building Services
729
730 =head2 build_application_name_service
731
732 Name of the application (such as MyApp).
733
734 =head2 build_driver_service
735
736 Config options passed directly to the driver being used.
737
738 =head2 build_file_service
739
740 ?
741
742 =head2 build_substitutions_service
743
744 This method substitutes macros found with calls to a function. There are a
745 number of default macros:
746
747 =over
748
749 =item * C<__HOME__> - replaced with C<$c-E<gt>path_to('')>
750
751 =item * C<__ENV(foo)__> - replaced with the value of C<$ENV{foo}>
752
753 =item * C<__path_to(foo/bar)__> - replaced with C<$c-E<gt>path_to('foo/bar')>
754
755 =item * C<__literal(__FOO__)__> - leaves __FOO__ alone (allows you to use
756 C<__DATA__> as a config value, for example)
757
758 =back
759
760 The parameter list is split on comma (C<,>). You can override this method to
761 do your own string munging, or you can define your own macros in
762 C<< <MyApp->config( 'Plugin::ConfigLoader' => { substitutions => { ... } } ) >>.
763 Example:
764
765     MyApp->config( 'Plugin::ConfigLoader' => {
766         substitutions => {
767             baz => sub { my $c = shift; qux( @_ ); },
768         },
769     });
770
771 The above will respond to C<__baz(x,y)__> in config strings.
772
773 =head2 build_extensions_service
774
775 Config::Any's available config file extensions (e.g. xml, json, pl, etc).
776
777 =head2 build_prefix_service
778
779 The prefix, based on the application name, that will be used to lookup the
780 config files (which will be in the format $prefix.$extension). If the app is
781 MyApp::Foo, the prefix will be myapp_foo.
782
783 =head2 build_path_service
784
785 The path to the config file (or environment variable, if defined).
786
787 =head2 build_config_service
788
789 The resulting configuration for the application, after it has successfully
790 been loaded, and all substitutions have been made.
791
792 =head2 build_raw_config_service
793
794 The merge of local_config and global_config hashes, before substitutions.
795
796 =head2 build_global_files_service
797
798 Gets all files for config that don't have the local_suffix, such as myapp.conf.
799
800 =head2 build_local_files_service
801
802 Gets all files for config that have the local_suffix, such as myapp_local.conf.
803
804 =head2 build_global_config_service
805
806 Reads config from global_files.
807
808 =head2 build_local_config_service
809
810 Reads config from local_files.
811
812 =head2 build_class_config_service
813
814 Reads config set from the application's class attribute config,
815 i.e. MyApp->config( name => 'MyApp', ... )
816
817 =head2 build_config_path_service
818
819 Splits the path to the config file, and returns on array ref containing
820 the path to the config file minus the extension in the first position,
821 and the extension in the second.
822
823 =head2 build_config_local_suffix_service
824
825 Determines the suffix of files used to override the main config. By default
826 this value is C<local>, which will load C<myapp_local.conf>.  The suffix can
827 be specified in the following order of preference:
828
829 =over
830
831 =item * C<$ENV{ MYAPP_CONFIG_LOCAL_SUFFIX }>
832
833 =item * C<$ENV{ CATALYST_CONFIG_LOCAL_SUFFIX }>
834
835 =back
836
837 The first one of these values found replaces the default of C<local> in the
838 name of the local config file to be loaded.
839
840 For example, if C< $ENV{ MYAPP_CONFIG_LOCAL_SUFFIX }> is set to C<testing>,
841 ConfigLoader will try and load C<myapp_testing.conf> instead of
842 C<myapp_local.conf>.
843
844 =head2 build_locate_components_service
845
846 This method is meant to provide a list of component modules that should be
847 setup for the application.  By default, it will use L<Module::Pluggable>.
848
849 Specify a C<setup_components> config option to pass additional options directly
850 to L<Module::Pluggable>.
851
852 =head1 Other methods
853
854 =head2 get_component_from_sub_container($sub_container, $name, $c, @args)
855
856 Looks for components in a given subcontainer (such as controller, model or
857 view), and returns the searched component. If $name is undef, it returns the
858 default component (such as default_view, if $sub_container is 'view'). If
859 $name is a regexp, it returns an array of matching components. Otherwise, it
860 looks for the component with name $name.
861
862 =head2 get_components_names_types
863
864 Gets all components from all containers and returns them as an array of
865 arrayrefs containing the component name and the component type (i.e., whether
866 it's an instance or a class).
867
868 =head2 get_all_components
869
870 Fetches all the components, in each of the sub_containers model, view and
871 controller, and returns a readonly hash. The keys are the class names, and
872 the values are the blessed objects. This is what is returned by $c->components.
873
874 =head2 add_component
875
876 Adds a component to the appropriate subcontainer. The subcontainer is guessed
877 by the component name given.
878
879 =head2 find_component
880
881 Searches for components in all containers. If $component is the full class
882 name, the subcontainer is guessed, and it gets the searched component in there.
883 Otherwise, it looks for a component with that name in all subcontainers. If
884 $component is a regexp, it calls the method below, find_component_regexp,
885 and matches all components against that regexp.
886
887 =head2 find_component_regexp
888
889 Finds components that match a given regexp. Used internally, by find_component.
890
891 =head2 expand_component_module
892
893 Components found by C<locate_components> will be passed to this method, which
894 is expected to return a list of component (package) names to be set up.
895
896 =head2 setup_components
897
898 =head1 AUTHORS
899
900 Catalyst Contributors, see Catalyst.pm
901
902 =head1 COPYRIGHT
903
904 This library is free software. You can redistribute it and/or modify it under
905 the same terms as Perl itself.
906
907 =cut