# This file documents the revision history for Perl extension Catalyst.
+TO BE RELEASED
+
+ Deprecated features:
+ - Calling model() and view() with no args when only one model or view is
+ available has been deprecated. You should explicitly pass the name of
+ the component.
+
+ Removed features:
+ - Calling model() and view() with no args when more than one model or view
+ was available no longer returns a random model/view and will croak()
+ instead.
+
5.90007 - 2011-11-22 20:35:00
New features:
my( $comp, $rest ) = $c->_comp_search_prefixes( undef, qw/Model M/);
- 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.' );
- }
-
- return $c->_filter_component( $comp );
+ if( !$rest ) {
+ ( my $name = ref $comp ) =~ s{$appclass\::M(odel)?::}{};
+ $c->log->warn( Carp::shortmess('Calling $c->model() with no arguments has been deprecated and will be removed.') );
+ $c->log->warn( "You could change the method call to \$c->model('$name') to retrieve this component." );
+ return $c->_filter_component( $comp );
+ }
+
+ croak( join( "\n",
+ 'Calling $c->model() will fail unless you specify one of:',
+ '* $c->config(default_model => "the name of the default model to use")',
+ '* $c->stash->{current_model} # the name of the model to use for this request',
+ '* $c->stash->{current_model_instance} # the instance of the model to use for this request' )
+ );
}
my( $comp, $rest ) = $c->_comp_search_prefixes( undef, qw/View V/);
- 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.' );
+ if( !$rest ) {
+ ( my $name = ref $comp ) =~ s{$appclass\::V(iew)?\::}{};
+ $c->log->warn( Carp::shortmess('Calling $c->view() with no arguments has been deprecated and will be removed.') );
+ $c->log->warn( "You could change the method call to \$c->view('$name') to retrieve this component." );
+ return $c->_filter_component( $comp );
}
- return $c->_filter_component( $comp );
+ croak( join( "\n",
+ 'Calling $c->view() will fail unless you specify one of:',
+ '* $c->config(default_view => "the name of the default view to use")',
+ '* $c->stash->{current_view} # the name of the view to use for this request',
+ '* $c->stash->{current_view_instance} # the instance of the view to use for this request' )
+ );
}
=head2 $c->controllers
-use Test::More tests => 51;
+use Test::More tests => 48;
use strict;
use warnings;
'models ok');
{
- my $warnings = 0;
- no warnings 'redefine';
- local *Catalyst::Log::warn = sub { $warnings++ };
-
- like (MyMVCTestApp->view , qr/^MyMVCTestApp\::(V|View)\::/ , 'view() with no defaults returns *something*');
- ok( $warnings, 'view() w/o a default is random, warnings thrown' );
+ eval { MyMVCTestApp->view; };
+ ok( $@, 'view() with no defaults and multiple choices dies' );
}
is ( bless ({stash=>{current_view=>'V'}}, 'MyMVCTestApp')->view , 'MyMVCTestApp::View::V', 'current_view ok');
'current_view_instance precedes current_view ok');
{
- my $warnings = 0;
- no warnings 'redefine';
- local *Catalyst::Log::warn = sub { $warnings++ };
-
- ok( my $model = MyMVCTestApp->model );
-
- ok( (($model =~ /^MyMVCTestApp\::(M|Model)\::/) ||
- $model->isa('Some::Test::Object')),
- 'model() with no defaults returns *something*' );
-
- ok( $warnings, 'model() w/o a default is random, warnings thrown' );
+ eval { MyMVCTestApp->model; };
+ ok( $@, 'model() with no defaults and multiple choices dies' );
}
is ( bless ({stash=>{current_model=>'M'}}, 'MyMVCTestApp')->model , 'MyMVCTestApp::Model::M', 'current_model ok');