From: André Walker Date: Thu, 7 Jul 2011 21:26:54 +0000 (-0300) Subject: changing get_component and get_component_args X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=77e27f6ec357bc9b622587b49ca10bca9dd89117 changing get_component and get_component_args --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index d4c2192..f1263a8 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -558,14 +558,13 @@ If you want to search for controllers, pass in a regexp as the argument. sub controller { my ( $c, $name, @args ) = @_; my $container = $c->container->get_sub_container('controller'); - unshift @args, $c; if( $name ) { # Direct component hash lookup to avoid costly regexps - return $container->get_component($name, \@args) + return $container->get_component( $name, $c, @args ) if $container->has_service($name) && !ref $name; - return $container->get_component_regexp( $c, $name, \@args ); + return $container->get_component_regexp( $name, $c, @args ); } return $c->component( $c->action->class ); @@ -596,14 +595,13 @@ sub model { my ( $c, $name, @args ) = @_; my $appclass = ref($c) || $c; my $container = $c->container->get_sub_container('model'); - unshift @args, $c; if( $name ) { # Direct component hash lookup to avoid costly regexps - return $container->get_component($name, \@args) + return $container->get_component( $name, $c, @args ) if $container->has_service($name) && !ref $name; - return $container->get_component_regexp( $c, $name, \@args ); + return $container->get_component_regexp( $name, $c, @args ); } if (ref $c) { @@ -626,7 +624,7 @@ sub model { $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' ); } - return $container->get_component( $comp, \@args ); + return $container->get_component( $comp, $c, @args ); } @@ -655,16 +653,15 @@ sub view { my ( $c, $name, @args ) = @_; my $appclass = ref($c) || $c; my $container = $c->container->get_sub_container('view'); - unshift @args, $c; if( $name ) { # Direct component hash lookup to avoid costly regexps - return $container->get_component($name, \@args) + return $container->get_component( $name, $c, @args ) if !ref $name && $container->has_service($name); $c->log->warn( "Attempted to use view '$name', but does not exist" ); - return $container->get_component_regexp( $c, $name, \@args ); + return $container->get_component_regexp( $name, $c, @args ); } if (ref $c) { @@ -686,7 +683,7 @@ sub view { $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' ); } - return $container->get_component( $comp, \@args ); + return $container->get_component( $comp, $c, @args ); } =head2 $c->controllers diff --git a/lib/Catalyst/IOC/SubContainer.pm b/lib/Catalyst/IOC/SubContainer.pm index 8306db8..11c6657 100644 --- a/lib/Catalyst/IOC/SubContainer.pm +++ b/lib/Catalyst/IOC/SubContainer.pm @@ -2,7 +2,6 @@ package Catalyst::IOC::SubContainer; use Bread::Board; use Moose; use Catalyst::IOC::BlockInjection; -use Catalyst::Utils; extends 'Bread::Board::Container'; @@ -13,26 +12,27 @@ has disable_regex_fallback => ( ); sub get_component { - my ( $self, $name, $args ) = @_; + my ( $self, $name, @args ) = @_; return $self->resolve( service => $name, - parameters => { accept_context_args => $args }, + parameters => { accept_context_args => \@args }, ); } sub get_component_regexp { - my ( $self, $c, $name, $args ) = @_; + my ( $self, $name, $c, @args ) = @_; return if $self->disable_regex_fallback && !ref $name; - my $query = ref $name ? $name : qr{$name}i; - my $prefix = Catalyst::Utils::class2classprefix($query) // ''; - $query =~ s/^${prefix}:://i; + my $query = ref $name ? $name : qr{$name}i; + my $appname = $self->parent->name; + $query =~ s/^${appname}:://i; + $query =~ s/[MVC]|(Model|View|Controller):://i; my @result = map { - $self->get_component( $_, $args ) + $self->get_component( $_, $c, @args ) } grep { m/$query/ } $self->get_service_list; if (!ref $name && $result[0]) {