X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=7c51d8de924b3d75a26b985a4012c0f9c1aeb328;hb=5cd3e38f295b5e88b588f4a2dbd09cb5ccb2342f;hp=0cd35b0de10bef22d98d8f89500498e259d1ce50;hpb=88d81c1bf707f932bc56c83376c8fe8cfe82c870;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 0cd35b0..7c51d8d 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -564,13 +564,7 @@ If you want to search for controllers, pass in a regexp as the argument. =cut -sub controller { - my ( $c, $name, @args ) = @_; - - $name ||= Catalyst::Utils::class2classshortsuffix( $c->action->class ); - - return $c->container->get_component_from_sub_container( 'controller', $name, $c, @args); -} +sub controller { shift->_lookup_mvc('controller', @_) } =head2 $c->model($name) @@ -593,20 +587,7 @@ If you want to search for models, pass in a regexp as the argument. =cut -sub model { - my ( $c, $name, @args ) = @_; - - if (ref $c && !$name) { - my $current_instance = $c->stash->{current_model_instance}; - return $current_instance - if $current_instance; - - $name = $c->stash->{current_model}; - } - - return $c->container->get_component_from_sub_container( 'model', $name, $c, @args); -} - +sub model { shift->_lookup_mvc('model', @_) } =head2 $c->view($name) @@ -629,18 +610,23 @@ If you want to search for views, pass in a regexp as the argument. =cut -sub view { - my ( $c, $name, @args ) = @_; +sub view { shift->_lookup_mvc('view', @_) } + +sub _lookup_mvc { + my ( $c, $type, $name, @args ) = @_; if (ref $c && !$name) { - my $current_instance = $c->stash->{current_view_instance}; + my $current_instance = $c->stash->{"current_${type}_instance"}; return $current_instance - if $current_instance; + if $current_instance && $type ne 'controller'; - $name = $c->stash->{current_view}; + $name = $type eq 'controller' + ? Catalyst::Utils::class2classshortsuffix($c->action->class) + : $c->stash->{"current_${type}"} + ; } - return $c->container->get_component_from_sub_container( 'view', $name, $c, @args); + return $c->container->get_component_from_sub_container($type, $name, $c, @args); } =head2 $c->controllers @@ -1031,11 +1017,11 @@ EOF if ( $class->debug and - my @comps_types = $class->container->get_components_types + my @comps_names_types = $class->container->get_components_names_types ) { my $column_width = Catalyst::Utils::term_width() - 8 - 9; my $t = Text::SimpleTable->new( [ $column_width, 'Class' ], [ 8, 'Type' ] ); - $t->row( @$_ ) for @comps_types; + $t->row( @$_ ) for @comps_names_types; $class->log->debug( "Loaded components:\n" . $t->draw . "\n" ); } @@ -1446,9 +1432,7 @@ sub components { my $container = $class->container; if ( $comps ) { - $container->add_component( - $_, $class - ) for keys %$comps; + $container->add_component( $_ ) for keys %$comps; } return $container->get_all_components(); @@ -2293,7 +2277,7 @@ sub setup_config { my $container = $container_class->new( %args, application_name => "$class", name => "$class" ); $class->container($container); - my $config = $container->resolve(service => 'config'); + my $config = $container->resolve( service => 'config' ); $class->config($config); $class->finalize_config; # back-compat } @@ -2320,10 +2304,27 @@ sub setup_components { shift->container->setup_components(); } +=head2 locate_components + +=cut + # FIXME - removed locate_components # don't people mess with this method directly? # what to do with that? +sub locate_components { + my $class = shift; + + $class->log->warn('The locate_components method has been deprecated.'); + $class->log->warn('Please read Catalyst::IOC::Container documentation to'); + $class->log->warn('update your application.'); + + # XXX think about ditching this sort entirely + return sort { length $a <=> length $b } + @{ $class->container->resolve( service => 'locate_components' ) }; +} + + =head2 $c->setup_dispatcher Sets up dispatcher.