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