Fix the way Catalyst::Plugin::Server adds custom dispatch types
Tomas Doran [Sat, 27 Dec 2008 15:31:25 +0000 (15:31 +0000)]
Changes
TODO
lib/Catalyst/Dispatcher.pm
t/aggregate/live_plugin_loaded.t
t/lib/TestApp.pm
t/lib/TestApp/DispatchType/CustomPostLoad.pm [new file with mode: 0644]
t/lib/TestApp/DispatchType/CustomPreLoad.pm [new file with mode: 0644]
t/lib/TestApp/Plugin/AddDispatchTypes.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index 78f01dc..ecf8006 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Fix assignment to Catalyst::Dispatcher's preload_dispatch_types and
+          postload_dispatch_types attributes - assigning a list should later 
+          return a listref. Fixes Catalyst::Plugin::Server. (t0m)
+          - Tests for this (t0m)
         - Change streaming test to serve itself rather than 01use.t, making test
           sync for engines easier (t0m)
         - Refactor capturing of $app from Catalyst::Controller into
diff --git a/TODO b/TODO
index 8e3aafe..9c225aa 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,12 @@
 Pending patches:
   - meta test for MX::Emulate::CAF needed by Catalyst::Plugin::Cache::Curried
-
+  
+  - Class::Accessor::Chained::Fast test for MX::Emulate::CAF, to fix 
+    HTML::Widget
+  
+  - Re-opening packages with MX::Emulate::CAF (for 
+    Catalyst::Plugin::HashedCookies)
+  
 Back-compat investigation / known issues:
 
   - Common engine test failures, look into and get tests into core.
@@ -12,9 +18,6 @@ Back-compat investigation / known issues:
   - Run another round of repository smokes against latest 5.80 trunk, manually
     go through all the things which are broken (t0m).
     
-     - Catalyst-Plugin-Server dies due to "package is not defined" error
-       which was reduced to a warning, retest.
-    
      - Catalyst-Plugin-Cache dies due to mk_accessors('meta')
     
      - Catalyst-Action-REST appears to have real issues, investigate
@@ -33,10 +36,6 @@ Back-compat investigation / known issues:
      - Catalyst-Plugin-Setenv
      - Catalyst-Plugin-RequireSSL - Bullshit 'cannot locate' errors
                                     Bug in smoke test rig.
-                                    
-     - Catalyst::Plugin::HTML::Widget - Undefined subroutine 
-       &HTML::Widget::Result::attributes called at 
-       lib/perl5/HTML/Widget/Result.pm line 68.
 
   - Issues with TWMC not being loaded when it used to be in 5.70 
     (Bill Moseley)
index 995cca5..0b26232 100644 (file)
@@ -33,6 +33,14 @@ has postload_dispatch_types => (is => 'rw', required => 1, lazy => 1, default =>
 has _action_hash => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
 has _container_hash => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
 
+# Wrap accessors so you can assign a list and it will capture a list ref.
+around qw/preload_dispatch_types postload_dispatch_types/ => sub {
+    my $orig = shift;
+    my $self = shift;
+    return $self->$orig([@_]) if (scalar @_ && ref $_[0] ne 'ARRAY');
+    return $self->$orig(@_);
+};
+
 no Moose;
 
 =head1 NAME
index 3881997..835f85c 100644 (file)
@@ -14,6 +14,7 @@ my @expected = qw[
   Catalyst::Plugin::Test::Headers
   Catalyst::Plugin::Test::Inline
   Catalyst::Plugin::Test::Plugin
+  TestApp::Plugin::AddDispatchTypes
   TestApp::Plugin::FullyQualified
 ];
 
index d65f6cb..058084f 100644 (file)
@@ -7,6 +7,7 @@ use Catalyst qw/
     Test::Plugin
     Test::Inline
     +TestApp::Plugin::FullyQualified
+    +TestApp::Plugin::AddDispatchTypes
 /;
 use Catalyst::Utils;
 
diff --git a/t/lib/TestApp/DispatchType/CustomPostLoad.pm b/t/lib/TestApp/DispatchType/CustomPostLoad.pm
new file mode 100644 (file)
index 0000000..fcd6145
--- /dev/null
@@ -0,0 +1,10 @@
+package TestApp::DispatchType::CustomPostLoad;
+use strict;
+use warnings;
+use base qw/Catalyst::DispatchType::Path/;
+
+# Never match anything..
+sub match { }
+
+1;
+
diff --git a/t/lib/TestApp/DispatchType/CustomPreLoad.pm b/t/lib/TestApp/DispatchType/CustomPreLoad.pm
new file mode 100644 (file)
index 0000000..277779a
--- /dev/null
@@ -0,0 +1,10 @@
+package TestApp::DispatchType::CustomPreLoad;
+use strict;
+use warnings;
+use base qw/Catalyst::DispatchType::Path/;
+
+# Never match anything..
+sub match { }
+
+1;
+
diff --git a/t/lib/TestApp/Plugin/AddDispatchTypes.pm b/t/lib/TestApp/Plugin/AddDispatchTypes.pm
new file mode 100644 (file)
index 0000000..b551e28
--- /dev/null
@@ -0,0 +1,24 @@
+package TestApp::Plugin::AddDispatchTypes;
+use strict;
+use warnings;
+use Class::C3;
+
+sub setup_dispatcher {
+    my $class = shift;
+
+    ### Load custom DispatchTypes, as done by Catalyst::Plugin::Server
+    $class->next::method( @_ );
+    $class->dispatcher->preload_dispatch_types(
+        @{$class->dispatcher->preload_dispatch_types},
+        qw/ +TestApp::DispatchType::CustomPreLoad /
+    );
+    $class->dispatcher->postload_dispatch_types(
+        @{$class->dispatcher->postload_dispatch_types},
+        qw/ +TestApp::DispatchType::CustomPostLoad /
+    );
+
+    return $class;
+}
+
+1;
+