Cosmetic: removed trailing whitespace
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / HTTP / Restarter.pm
index 7c0b90f..dfb414c 100644 (file)
@@ -1,12 +1,14 @@
 package Catalyst::Engine::HTTP::Restarter;
+use Moose;
+use Moose::Util qw/find_meta/;
+use namespace::clean -except => 'meta';
+
+extends 'Catalyst::Engine::HTTP';
 
-use strict;
-use warnings;
-use base 'Catalyst::Engine::HTTP';
 use Catalyst::Engine::HTTP::Restarter::Watcher;
-use NEXT;
 
-sub run {
+around run => sub {
+    my $orig = shift;
     my ( $self, $class, $port, $host, $options ) = @_;
 
     $options ||= {};
@@ -18,8 +20,18 @@ sub run {
         close STDIN;
         close STDOUT;
 
+        # Avoid "Setting config after setup" error restarting MyApp.pm
+        $class->setup_finished(0);
+        # Best effort if we can't trap compiles..
+        $self->_make_components_mutable($class)
+            if !Catalyst::Engine::HTTP::Restarter::Watcher::DETECT_PACKAGE_COMPILATION;
+
         my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new(
-            directory => File::Spec->catdir( $FindBin::Bin, '..' ),
+            directory => (
+                $options->{restart_directory} ||
+                File::Spec->catdir( $FindBin::Bin, '..' )
+            ),
+            follow_symlinks => $options->{follow_symlinks},
             regex     => $options->{restart_regex},
             delay     => $options->{restart_delay},
         );
@@ -63,7 +75,23 @@ sub run {
         }
     }
 
-    return $self->NEXT::run( $class, $port, $host, $options );
+    return $self->$orig( $class, $port, $host, $options );
+};
+
+# 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 = grep { defined($_) }
+                map { find_meta($_) }
+                ($class, map { blessed($_) }
+                values %{ $class->components });
+
+    foreach my $meta (@metas) {
+        # Paranoia unneeded, all component metaclasses should have immutable
+        $meta->make_mutable if $meta->is_immutable;
+    }
 }
 
 1;
@@ -93,11 +121,7 @@ L<Catalyst::Engine>.
 
 =head1 AUTHORS
 
-Sebastian Riedel, <sri@cpan.org>
-
-Dan Kubb, <dan.kubb-cpan@onautopilot.com>
-
-Andy Grundman, <andy@hybridized.org>
+Catalyst Contributors, see Catalyst.pm
 
 =head1 THANKS
 
@@ -105,7 +129,7 @@ Many parts are ripped out of C<HTTP::Server::Simple> by Jesse Vincent.
 
 =head1 COPYRIGHT
 
-This program is free software, you can redistribute it and/or modify it under
+This library is free software. You can redistribute it and/or modify it under
 the same terms as Perl itself.
 
 =cut