sub model {
my ( $c, $name, @args ) = @_;
- my $appclass = ref($c) || $c;
- my $container = $c->container->get_sub_container('model');
-
- return $c->container->get_component_from_sub_container( 'model', $name, $c, @args)
- if( $name );
- if (ref $c) {
+ if (ref $c && !$name) {
return $c->stash->{current_model_instance}
- if $c->stash->{current_model_instance};
- return $c->model( $c->stash->{current_model} )
- if $c->stash->{current_model};
- }
- return $c->model( $appclass->config->{default_model} )
- if $appclass->config->{default_model};
-
-# FIXME: will this still be mantained?
- my( $comp, $rest ) = $container->get_service_list;
+ if $c->stash->{current_model_instance};
- if( $rest ) {
- $c->log->warn( Carp::shortmess('Calling $c->model() will return a random model unless you specify one of:') );
- $c->log->warn( '* $c->config(default_model => "the name of the default model to use")' );
- $c->log->warn( '* $c->stash->{current_model} # the name of the model to use for this request' );
- $c->log->warn( '* $c->stash->{current_model_instance} # the instance of the model to use for this request' );
- $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
+ $name = $c->stash->{current_model}
+ if $c->stash->{current_model};
}
- return $container->get_component( $comp, $c, @args );
+ return $c->container->get_component_from_sub_container( 'model', $name, $c, @args);
}
sub view {
my ( $c, $name, @args ) = @_;
- my $appclass = ref($c) || $c;
- my $container = $c->container->get_sub_container('view');
-
- return $c->container->get_component_from_sub_container( 'view', $name, $c, @args)
- if( $name );
- if (ref $c) {
+ if (ref $c && !$name) {
return $c->stash->{current_view_instance}
- if $c->stash->{current_view_instance};
- return $c->view( $c->stash->{current_view} )
- if $c->stash->{current_view};
- }
- return $c->view( $appclass->config->{default_view} )
- if $appclass->config->{default_view};
-
- my( $comp, $rest ) = $container->get_service_list;
+ if $c->stash->{current_view_instance};
- if( $rest ) {
- $c->log->warn( 'Calling $c->view() will return a random view unless you specify one of:' );
- $c->log->warn( '* $c->config(default_view => "the name of the default view to use")' );
- $c->log->warn( '* $c->stash->{current_view} # the name of the view to use for this request' );
- $c->log->warn( '* $c->stash->{current_view_instance} # the instance of the view to use for this request' );
- $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
+ $name = $c->stash->{current_view}
+ if $c->stash->{current_view};
}
- return $container->get_component( $comp, $c, @args );
+ return $c->container->get_component_from_sub_container( 'view', $name, $c, @args);
}
=head2 $c->controllers
);
}
+sub build_default_model {
+ Bread::Board::BlockInjection->new(
+ block => sub {
+ shift->param('config')->{default_model};
+ },
+ dependencies => [ depends_on('config') ],
+ );
+}
+
+sub build_default_view {
+ Bread::Board::BlockInjection->new(
+ name => 'default_view',
+ block => sub {
+ shift->param('config')->{default_view};
+ },
+ dependencies => [ depends_on('config') ],
+ );
+}
+
sub build_name_service {
my $self = shift;
my $sub_container = $self->get_sub_container( $sub_container_name );
+ if (!$name) {
+ my $default_name = 'default_' . $sub_container_name;
+ my $default = $self->resolve( service => $default_name )
+ if $self->has_service($default_name);
+
+ return $sub_container->get_component( $default, $c, @args )
+ if $default && $sub_container->has_service( $default );
+
+ # this is never a controller, so this is safe
+ $c->log->warn( "Calling \$c->$sub_container_name() is not supported unless you specify one of:" );
+ $c->log->warn( "* \$c->config(default_$sub_container_name => 'the name of the default $sub_container_name to use')" );
+ $c->log->warn( "* \$c->stash->{current_$sub_container_name} # the name of the view to use for this request" );
+ $c->log->warn( "* \$c->stash->{current_${sub_container_name}_instance} # the instance of the $sub_container_name to use for this request" );
+ }
+
return $sub_container->get_component_regexp( $name, $c, @args )
if ref $name;