sub controller {
my ( $c, $name, @args ) = @_;
+ my $container = $c->container->get_sub_container('controller');
my $appclass = ref($c) || $c;
if( $name ) {
unless ( ref($name) ) { # Direct component hash lookup to avoid costly regexps
my $check = $appclass."::Controller::".$name;
- my $container = $c->container->get_sub_container('controller');
- return $c->_filter_component( $container->resolve(service => "$check"), @args )
+ return $container->resolve(service => "$check", parameters => { context => \@args } )
if $container->has_service($check);
}
my @result = $c->_comp_search_prefixes( $name, qw/Controller C/ );
- return map { $c->_filter_component( $_, @args ) } @result if ref $name;
- return $c->_filter_component( $result[ 0 ], @args );
+ return map { $container->resolve(service => "$_", parameters => { context => \@args } ) } @result if ref $name;
}
return $c->component( $c->action->class );
sub model {
my ( $c, $name, @args ) = @_;
my $appclass = ref($c) || $c;
+ my $container = $c->container->get_sub_container('model');
+
if( $name ) {
unless ( ref($name) ) { # Direct component hash lookup to avoid costly regexps
my $check = $appclass."::Model::".$name;
- my $container = $c->container->get_sub_container('model');
- return $c->_filter_component( $container->resolve(service => "$check"), @args )
+ return $container->resolve( service => "$check", parameters => { context => \@args } )
if $container->has_service($check);
}
my @result = $c->_comp_search_prefixes( $name, qw/Model M/ );
- return map { $c->_filter_component( $_, @args ) } @result if ref $name;
- return $c->_filter_component( $result[ 0 ], @args );
+ return map { $container->resolve( service => "$_", parameters => { context => \@args } ) } @result if ref $name;
}
if (ref $c) {
return $c->model( $appclass->config->{default_model} )
if $appclass->config->{default_model};
+# FIXME: will this still be mantained?
my( $comp, $rest ) = $c->_comp_search_prefixes( undef, qw/Model M/);
if( $rest ) {
$c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
}
- return $c->_filter_component( $comp );
+ return $container->resolve( service => ref $comp, parameters => { context => \@args } );
}
sub view {
my ( $c, $name, @args ) = @_;
-
my $appclass = ref($c) || $c;
+ my $container = $c->container->get_sub_container('view');
+
if( $name ) {
unless ( ref($name) ) { # Direct component hash lookup to avoid costly regexps
my $check = $appclass."::View::".$name;
- my $container = $c->container->get_sub_container('view');
if ($container->has_service($check)) {
-
- return $c->_filter_component( $container->resolve(service => $check), @args );
+ return $container->resolve(service => $check, parameters => { context => \@args } );
}
else {
$c->log->warn( "Attempted to use view '$check', but does not exist" );
}
}
my @result = $c->_comp_search_prefixes( $name, qw/View V/ );
- return map { $c->_filter_component( $_, @args ) } @result if ref $name;
- return $c->_filter_component( $result[ 0 ], @args );
+ return map { $container->resolve(service => "$_", parameters => { context => \@args } ) } @result if ref $name;
}
if (ref $c) {
$c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
}
- return $c->_filter_component( $comp );
+ return $container->resolve( service => ref $comp, parameters => { context => \@args } );
}
=head2 $c->controllers
for my $component ( keys %$comps ) {
$components->{ $component } = $comps->{$component};
- my $type = _get_component_type($component);
+ my ($type, $name) = _get_component_type_name($component);
- $containers->{$type}->add_service(Bread::Board::BlockInjection->new( name => $component, block => sub { return $class->setup_component($component) } ));
+# FIXME: shouldn't the service name be $name?
+ $containers->{$type}->add_service(Catalyst::BlockInjection->new( name => $component, block => sub { return $class->setup_component($component) } ));
}
return $class->$orig($components);
for my $component (@comps) {
my $instance = $class->components->{ $component } = $class->setup_component($component);
- if ( my $type = _get_component_type($component) ) {
- $containers->{$type}->add_service(Bread::Board::BlockInjection->new( name => $component, block => sub { return $instance } ));
+ if ( my ($type, $name) = _get_component_type_name($component) ) {
+# FIXME: shouldn't the service name be $name?
+ $containers->{$type}->add_service(Catalyst::BlockInjection->new( name => $component, block => sub { return $instance } ));
}
my @expanded_components = $instance->can('expand_modules')
? $instance->expand_modules( $component, $config )
qq{Please switch your class names to ::Model::, ::View:: and ::Controller: as appropriate.\n}
) if $deprecatedcatalyst_component_names;
- if (my $type = _get_component_type($component)) {
- $containers->{$type}->add_service(Bread::Board::BlockInjection->new( name => $component, block => sub { return $class->setup_component($component) } ));
+ if (my ($type, $name) = _get_component_type_name($component)) {
+ $containers->{$type}->add_service(Catalyst::BlockInjection->new( name => $component, block => sub { return $class->setup_component($component) } ));
}
$class->components->{ $component } = $class->setup_component($component);
}
}
-sub _get_component_type {
+sub _get_component_type_name {
my $component = shift;
my @parts = split /::/, $component;
- for (@parts) {
- return 'controller' if /^c|controller$/i;
- return 'model' if /^m|model$/i;
- return 'view' if /^v|view$/i;
+ while (my $type = shift @parts) {
+ return ('controller', join '::', @parts)
+ if $type =~ /^(c|controller)$/i;
+
+ return ('model', join '::', @parts)
+ if $type =~ /^(m|model)$/i;
+
+ return ('view', join '::', @parts)
+ if $type =~ /^(v|view)$/i;
}
}