Mention setting default_view option as this is also sane
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 7cd76d5..6849c4e 100644 (file)
@@ -75,7 +75,7 @@ our $GO        = Catalyst::Exception::Go->new;
 __PACKAGE__->mk_classdata($_)
   for qw/components arguments dispatcher engine log dispatcher_class
   engine_loader context_class request_class response_class stats_class
-  setup_finished _psgi_app loading_psgi_file/;
+  setup_finished _psgi_app loading_psgi_file run_options/;
 
 __PACKAGE__->dispatcher_class('Catalyst::Dispatcher');
 __PACKAGE__->request_class('Catalyst::Request');
@@ -84,7 +84,7 @@ __PACKAGE__->stats_class('Catalyst::Stats');
 
 # Remember to update this in Catalyst::Runtime as well!
 
-our $VERSION = '5.90005';
+our $VERSION = '5.90007';
 
 sub import {
     my ( $class, @arguments ) = @_;
@@ -676,15 +676,20 @@ sub model {
 
     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.' );
+    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" );
+        $c->log->warn( "or you should set \$c->config(default_model => '$name')." );
+        return $c->_filter_component( $comp );
     }
 
-    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' )
+    );
 }
 
 
@@ -740,15 +745,20 @@ sub view {
 
     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," );
+        $c->log->warn( "or you should set \$c->config(default_view => '$name')." );
+        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
@@ -1573,6 +1583,16 @@ sub welcome_message {
 EOF
 }
 
+=head2 run_options
+
+Contains a hash of options passed from the application script, including
+the original ARGV the script received, the processed values from that
+ARGV and any extra arguments to the script which were not processed.
+
+This can be used to add custom options to your application's scripts
+and setup your application differently depending on the values of these
+options.
+
 =head1 INTERNAL METHODS
 
 These methods are not meant to be used by end users.
@@ -2643,7 +2663,7 @@ sub setup_engine {
 
         $meta->add_method(handler => sub {
             my $r = shift;
-            my $psgi_app = $class->psgi_app;
+            my $psgi_app = $class->_finalized_psgi_app;
             $apache->call_app($r, $psgi_app);
         });
 
@@ -2734,7 +2754,16 @@ sub apply_default_middlewares {
 
     # If we're running under Lighttpd, swap PATH_INFO and SCRIPT_NAME
     # http://lists.scsys.co.uk/pipermail/catalyst/2006-June/008361.html
-    $psgi_app = Plack::Middleware::LighttpdScriptNameFix->wrap($psgi_app);
+    $psgi_app = Plack::Middleware::Conditional->wrap(
+        $psgi_app,
+        builder   => sub { Plack::Middleware::LighttpdScriptNameFix->wrap($_[0]) },
+        condition => sub {
+            my ($env) = @_;
+            return unless $env->{SERVER_SOFTWARE} && $env->{SERVER_SOFTWARE} =~ m!lighttpd[-/]1\.(\d+\.\d+)!;
+            return unless $1 < 4.23;
+            1;
+        },
+    );
 
     # we're applying this unconditionally as the middleware itself already makes
     # sure it doesn't fuck things up if it's not running under one of the right
@@ -3148,7 +3177,26 @@ headers.
 
 If you do not wish to use the proxy support at all, you may set:
 
-    MyApp->config(ignore_frontend_proxy => 1);
+    MyApp->config(ignore_frontend_proxy => 0);
+
+=head2 Note about psgi files
+
+Note that if you supply your own .psgi file, calling
+C<< MyApp->psgi_app(@_); >>, then B<this will not happen automatically>.
+
+You either need to apply L<Plack::Middleware::ReverseProxy> yourself
+in your psgi, for example:
+
+    builder {
+        enable "Plack::Middleware::ReverseProxy";
+        MyApp->psgi_app
+    };
+
+This will unconditionally add the ReverseProxy support, or you need to call
+C<< $app = MyApp->apply_default_middlewares($app) >> (to conditionally
+apply the support depending upon your config).
+
+See L<Catalyst::PSGI> for more information.
 
 =head1 THREAD SAFETY