Immutable components no longer break the restarter for the simple case
Tomas Doran [Sun, 15 Feb 2009 05:17:19 +0000 (05:17 +0000)]
Changes
lib/Catalyst/Engine/HTTP/Restarter.pm
t/optional_http-server-restart.t

diff --git a/Changes b/Changes
index 6886cee..11059bd 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Naive implementation of making packages mutable before restarting so
+          that restarter works with native Moose apps using immutable (t0m)
+          - Tests for this (t0m)
         - Bump Moose dependency to 0.70 so that we avoid nasty surprises
           with is_class_loaded and perl 5.80 when you Moosify MyApp.pm (t0m)
         - Clarify that request arguments aren't unescaped automatically
index c20943a..57ca54a 100644 (file)
@@ -1,6 +1,8 @@
 package Catalyst::Engine::HTTP::Restarter;
-
 use Moose;
+use Moose::Util qw/find_meta/;
+use namespace::clean -except => 'meta';
+
 extends 'Catalyst::Engine::HTTP';
 
 use Catalyst::Engine::HTTP::Restarter::Watcher;
@@ -18,6 +20,8 @@ around run => sub {
         close STDIN;
         close STDOUT;
 
+        $self->_make_components_mutable($class);
+
         my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new(
             directory => ( 
                 $options->{restart_directory} || 
@@ -70,7 +74,17 @@ around run => sub {
     return $self->$orig( $class, $port, $host, $options );
 };
 
-no Moose;
+# Naive way of trying to avoid Moose blowing up when you re-require components
+# which have been made immutable.
+sub _make_components_mutable {
+    my ($self, $class) = @_;
+
+    my @metas = map { find_meta(@_) } ($class, map { blessed($_) } values %{ $class->components });
+
+    foreach my $meta (@metas) {
+        $meta->make_mutable if $meta->is_immutable;
+    }
+}
 
 1;
 __END__
index e004ac8..c3bff4f 100644 (file)
@@ -65,7 +65,7 @@ while ( check_port( 'localhost', $port ) != 1 ) {
 my @files = (
     "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp.pm",
     "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Action/Begin.pm",
-"$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Engine/Request/URI.pm",
+    "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Immutable.pm",
 );
 
 # change some files and make sure the server restarts itself