[Catalyst-commits] r9312 - in Catalyst-Runtime/5.80/trunk: .
lib/Catalyst/Engine/HTTP/Restarter t t/lib/TestApp/Controller
t/lib/TestApp/Controller/Immutable
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Sun Feb 15 05:22:59 GMT 2009
Author: t0m
Date: 2009-02-15 05:22:59 +0000 (Sun, 15 Feb 2009)
New Revision: 9312
Added:
Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Immutable/
Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Immutable/HardToReload.pm
Modified:
Catalyst-Runtime/5.80/trunk/Changes
Catalyst-Runtime/5.80/trunk/Makefile.PL
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm
Catalyst-Runtime/5.80/trunk/t/optional_http-server-restart.t
Log:
Make restarters immutable handling less naive + tests
Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes 2009-02-15 05:22:49 UTC (rev 9311)
+++ Catalyst-Runtime/5.80/trunk/Changes 2009-02-15 05:22:59 UTC (rev 9312)
@@ -1,8 +1,12 @@
# 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)
+ - Non-naive implementation of making mutable on restart using
+ B::Hooks::OP::Check::StashChange if installed (t0m)
- Tests for this (t0m)
+ - Naive implementation of making all components mutable in the
+ forked restart watcher process so native Moose apps using
+ immutable restart correctly. (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
Modified: Catalyst-Runtime/5.80/trunk/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/trunk/Makefile.PL 2009-02-15 05:22:49 UTC (rev 9311)
+++ Catalyst-Runtime/5.80/trunk/Makefile.PL 2009-02-15 05:22:59 UTC (rev 9312)
@@ -34,6 +34,8 @@
requires 'Text::Balanced'; # core in 5.8.x but mentioned for completeness
requires 'MRO::Compat';
+recommends 'B::Hooks::OP::Check::StashChange';
+
test_requires 'Class::Data::Inheritable';
test_requires 'Test::MockObject';
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm 2009-02-15 05:22:49 UTC (rev 9311)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm 2009-02-15 05:22:59 UTC (rev 9312)
@@ -7,7 +7,19 @@
use File::Modified;
use File::Spec;
use Time::HiRes qw/sleep/;
+use Moose::Util qw/find_meta/;
+use namespace::clean -except => 'meta';
+BEGIN {
+ # If we can detect stash changes, then we do magic
+ # to make their metaclass mutable (if they have one)
+ # so that restarting works as expected.
+ eval { require B::Hooks::OP::Check::StashChange; };
+ *DETECT_PACKAGE_COMPILATION = $@
+ ? sub () { 0 }
+ : sub () { 1 }
+}
+
has delay => (is => 'rw');
has regex => (is => 'rw');
has modified => (is => 'rw');
@@ -15,10 +27,8 @@
has watch_list => (is => 'rw');
has follow_symlinks => (is => 'rw');
-no Moose;
-
sub BUILD {
- shift->_init;
+ shift->_init;
}
sub _init {
@@ -126,7 +136,18 @@
sub _test {
my ( $self, $file ) = @_;
- delete $INC{$file};
+ my $id;
+ if (DETECT_PACKAGE_COMPILATION) {
+ $id = B::Hooks::OP::Check::StashChange::register(sub {
+ my ($new, $old) = @_;
+ my $meta = find_meta($new);
+ if ($meta) {
+ $meta->make_mutable if $meta->is_immutable;
+ }
+ });
+ }
+
+ delete $INC{$file}; # Remove from %INC so it will reload
local $SIG{__WARN__} = sub { };
open my $olderr, '>&STDERR';
@@ -134,6 +155,8 @@
eval "require '$file'";
open STDERR, '>&', $olderr;
+ B::Hooks::OP::Check::StashChange::unregister($id) if $id;
+
return ($@) ? $@ : 0;
}
Added: Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Immutable/HardToReload.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Immutable/HardToReload.pm (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Immutable/HardToReload.pm 2009-02-15 05:22:59 UTC (rev 9312)
@@ -0,0 +1,26 @@
+package TestApp::Controller::Immutable::HardToReload;
+use Moose;
+BEGIN { extends 'Catalyst::Controller' }
+no Moose;
+__PACKAGE__->meta->make_immutable;
+
+package # Standard PAUSE hiding technique
+ TestApp::Controller::Immutable::HardToReload::PAUSEHide;
+use Moose;
+BEGIN { extends 'Catalyst::Controller' }
+no Moose;
+__PACKAGE__->meta->make_immutable;
+
+# Not an inner package
+package TestApp::Controller::Immutable2;
+use Moose;
+BEGIN { extends 'Catalyst::Controller' }
+no Moose;
+__PACKAGE__->meta->make_immutable;
+
+# Not even in the app namespace
+package Frobnitz;
+use Moose;
+BEGIN { extends 'Catalyst::Controller' }
+no Moose;
+__PACKAGE__->meta->make_immutable;
Modified: Catalyst-Runtime/5.80/trunk/t/optional_http-server-restart.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/optional_http-server-restart.t 2009-02-15 05:22:49 UTC (rev 9311)
+++ Catalyst-Runtime/5.80/trunk/t/optional_http-server-restart.t 2009-02-15 05:22:59 UTC (rev 9312)
@@ -13,6 +13,7 @@
use LWP::Simple;
use IO::Socket;
use IPC::Open3;
+use Catalyst::Engine::HTTP::Restarter::Watcher;
use Time::HiRes qw/sleep/;
eval "use Catalyst::Devel 1.0;";
@@ -68,6 +69,9 @@
"$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Immutable.pm",
);
+push(@files, "$FindBin::Bin/../t/tmp/TestApp/lib/TestApp/Controller/Immutable/HardToReload.pm")
+ if Catalyst::Engine::HTTP::Restarter::Watcher::DETECT_PACKAGE_COMPILATION();
+
# change some files and make sure the server restarts itself
NON_ERROR_RESTART:
for ( 1 .. 20 ) {
More information about the Catalyst-commits
mailing list