From: André Walker Date: Thu, 28 Jul 2011 18:49:51 +0000 (-0300) Subject: setup_components became a service X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fa6607ec462952bf12734ebf958796c88c917130;hp=dca40344fa6ddcb00a4a1261cb65330f7e08f4bd;p=catagits%2FCatalyst-Runtime.git setup_components became a service --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 6df1fd8..30e3854 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2317,10 +2317,7 @@ The C config option is passed to both of the above methods. =cut sub setup_components { - my $class = shift; - # FIXME - I believe I shouldn't be handing $class over - # Just don't know how to solve this. - return $class->container->setup_components( $class ); + shift->container->resolve( service => 'setup_components' ); } # FIXME - removed locate_components diff --git a/lib/Catalyst/IOC/Container.pm b/lib/Catalyst/IOC/Container.pm index 6a1b489..7d40bf5 100644 --- a/lib/Catalyst/IOC/Container.pm +++ b/lib/Catalyst/IOC/Container.pm @@ -76,6 +76,7 @@ sub BUILD { config_local_suffix config_path locate_components + setup_components /; $self->add_sub_container( @@ -404,6 +405,63 @@ sub build_locate_components_service { ); } +sub build_setup_components_service { + my $self = shift; + + return Bread::Board::BlockInjection->new( + lifecycle => 'Singleton', + name => 'setup_components', + block => sub { + my $s = shift; + my $class = $s->param('application_name'); + my @comps = @{ $s->param( 'locate_components' ) }; + my %comps = map { $_ => 1 } @comps; + my $deprecatedcatalyst_component_names = 0; + + for my $component ( @comps ) { + + # We pass ignore_loaded here so that overlay files for (e.g.) + # Model::DBI::Schema sub-classes are loaded - if it's in @comps + # we know M::P::O found a file on disk so this is safe + + Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } ); + } + + for my $component (@comps) { + $self->add_component( $component, $class ); + # FIXME - $instance->expand_modules() is broken + my @expanded_components = $self->expand_component_module( $component ); + + if ( + !$deprecatedcatalyst_component_names && + ($deprecatedcatalyst_component_names = $component =~ m/::[CMV]::/) || + ($deprecatedcatalyst_component_names = grep { /::[CMV]::/ } @expanded_components) + ) { + # FIXME - should I be calling warn here? + $class->log->warn(qq{Your application is using the deprecated ::[MVC]:: type naming scheme.\n}. + qq{Please switch your class names to ::Model::, ::View:: and ::Controller: as appropriate.\n} + ); + } + + for my $component (@expanded_components) { + $self->add_component( $component, $class ) + unless $comps{$component}; + } + } + + # FIXME - how can this be done? + #$s->param('/model')->make_single_default; + #$s->param('/view')->make_single_default; + }, + dependencies => [ + depends_on('application_name'), + depends_on('locate_components'), + #depends_on('/model'), + #depends_on('/view'), + ], + ); +} + sub _fix_syntax { my $config = shift; my @components = ( @@ -653,48 +711,6 @@ sub expand_component_module { return Devel::InnerPackage::list_packages( $module ); } -sub setup_components { - my ( $self, $class ) = @_; - - my @comps = @{ $self->resolve( service => 'locate_components' ) }; - my %comps = map { $_ => 1 } @comps; - my $deprecatedcatalyst_component_names = 0; - - for my $component ( @comps ) { - - # We pass ignore_loaded here so that overlay files for (e.g.) - # Model::DBI::Schema sub-classes are loaded - if it's in @comps - # we know M::P::O found a file on disk so this is safe - - Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } ); - } - - for my $component (@comps) { - $self->add_component( $component, $class ); - # FIXME - $instance->expand_modules() is broken - my @expanded_components = $self->expand_component_module( $component ); - - if ( - !$deprecatedcatalyst_component_names && - ($deprecatedcatalyst_component_names = $component =~ m/::[CMV]::/) || - ($deprecatedcatalyst_component_names = grep { /::[CMV]::/ } @expanded_components) - ) { - # FIXME - should I be calling warn here? - $class->log->warn(qq{Your application is using the deprecated ::[MVC]:: type naming scheme.\n}. - qq{Please switch your class names to ::Model::, ::View:: and ::Controller: as appropriate.\n} - ); - } - - for my $component (@expanded_components) { - $self->add_component( $component, $class ) - unless $comps{$component}; - } - } - - $self->get_sub_container('model')->make_single_default; - $self->get_sub_container('view')->make_single_default; -} - 1; __END__ @@ -852,6 +868,8 @@ setup for the application. By default, it will use L. Specify a C config option to pass additional options directly to L. +=head2 build_setup_components_service + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm