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