remove horrid hack, add test cases 5.90081
John Napiorkowski [Sat, 10 Jan 2015 22:34:52 +0000 (16:34 -0600)]
Changes
lib/Catalyst.pm
lib/Catalyst/Runtime.pm
t/plack-middleware.t

diff --git a/Changes b/Changes
index 79dcfeb..f921176 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,11 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+5.90081 - 2014-01-10
+  - created class attribute 'finalized_default_middleware' which determines
+    if the default middleware has been added to the stack yet or not.  This
+    removes a horrible hack that polluted the configuration hash.  Added
+    test case to prevent regressions.
+
 5.90080 - 2014-01-09
   - Minor documentation corrections
   - Make the '79 development series stable
index 8800cf0..e32c735 100644 (file)
@@ -120,7 +120,7 @@ __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 run_options _psgi_middleware
-  _data_handlers _encoding _encode_check/;
+  _data_handlers _encoding _encode_check finalized_default_middleware/;
 
 __PACKAGE__->dispatcher_class('Catalyst::Dispatcher');
 __PACKAGE__->request_class('Catalyst::Request');
@@ -129,7 +129,7 @@ __PACKAGE__->stats_class('Catalyst::Stats');
 __PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC);
 
 # Remember to update this in Catalyst::Runtime as well!
-our $VERSION = '5.90080';
+our $VERSION = '5.90081';
 $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
 
 sub import {
@@ -3533,8 +3533,8 @@ sub setup_middleware {
       @middleware_definitions = reverse(@_);
     } else {
       @middleware_definitions = reverse(@{$class->config->{'psgi_middleware'}||[]})
-        unless $class->config->{__configured_from_psgi_middleware};
-      $class->config->{__configured_from_psgi_middleware} = 1; # Only do this once, just in case some people call setup over and over...
+        unless $class->finalized_default_middleware;
+      $class->finalized_default_middleware(1); # Only do this once, just in case some people call setup over and over...
     }
 
     my @middleware = ();
index b5db7f4..466d54a 100644 (file)
@@ -7,7 +7,7 @@ BEGIN { require 5.008003; }
 
 # Remember to update this in Catalyst as well!
 
-our $VERSION = '5.90080';
+our $VERSION = '5.90081';
 $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
 
 =head1 NAME
index 4cc3e72..f6bf563 100644 (file)
@@ -54,4 +54,15 @@ ok my($res, $c) = ctx_request('/');
   ok $response->headers->{"x-runtime"}, "Got value for expected middleware";
 }
 
+{
+  my $total_mw = scalar(TestMiddleware->registered_middlewares);
+
+  TestMiddleware->setup_middleware;
+  TestMiddleware->setup_middleware;
+
+  my $post_mw = scalar(TestMiddleware->registered_middlewares);
+
+  is $total_mw, $post_mw, 'Calling ->setup_middleware does not re-add default middleware';
+}
+
 done_testing;