Immutable components no longer break the restarter for the simple case
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / HTTP / Restarter.pm
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__