[Catalyst] PATCH: refactor Catalyst::Engine::HTTP::Restarter to standalone module

2007-07-22 Thread Mark Stosberg
Hello, 

I like the auto-restart feature that is in the Catalyst HTTP::Restarter
server. I wanted to use the restarting trick with a project based on
HTTP::Server::Simple, so I looked to see how tied this functionality was to
Catalyst. Here's what I found:

Catalyst::Engine::HTTP::Restarter::Watcher is not functionally tied to
Catalyst at all. It just shares a namespace. 

Catalyst::Engine::HTTP::Restarter depends on no functionality from Catalyst
but was still coupled with it through a base-class relationship which could
be easily avoided.

The attached patch moves these to modules into the HTTP::Server::Restarter
namespace, and makes slight alternations to the other Catalyst files so
that the functionality remains the same, as well as the dependencies. 

The patch provides significantly improved documentation for some related
functions as well.

Thank you for your consideration.

       Mark
Sat Jul 21 22:40:44 EDT 2007  Mark Stosberg [EMAIL PROTECTED]
  * refactor HTTP::Server::Restarter out as stand-alone module.
Sat Jul 21 17:46:28 EDT 2007  Mark Stosberg [EMAIL PROTECTED]
  * add documentation to Catalyst::Engine::HTTP::Restarter
diff -rN -u old-catalyst_vs_cgiapp/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm new-catalyst_vs_cgiapp/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm
--- old-catalyst_vs_cgiapp/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm	2007-07-21 22:43:56.0 -0400
+++ new-catalyst_vs_cgiapp/lib/Catalyst/Engine/HTTP/Restarter/Watcher.pm	1969-12-31 19:00:00.0 -0500
@@ -1,200 +0,0 @@
-package Catalyst::Engine::HTTP::Restarter::Watcher;
-
-use strict;
-use warnings;
-use base 'Class::Accessor::Fast';
-use File::Find;
-use File::Modified;
-use File::Spec;
-use Time::HiRes qw/sleep/;
-
-__PACKAGE__-mk_accessors(
-qw/delay
-  directory
-  modified
-  regex
-  watch_list/
-);
-
-sub new {
-my ( $class, %args ) = @_;
-
-my $self = {%args};
-
-bless $self, $class;
-
-$self-_init;
-
-return $self;
-}
-
-sub _init {
-my $self = shift;
-
-my $watch_list = $self-_index_directory;
-$self-watch_list($watch_list);
-
-$self-modified(
-File::Modified-new(
-method = 'mtime',
-files  = [ keys %{$watch_list} ],
-)
-);
-}
-
-sub watch {
-my $self = shift;
-
-my @changes;
-my @changed_files;
-
-my $delay = ( defined $self-delay ) ? $self-delay : 1;
-
-sleep $delay if $delay  0;
-
-eval { @changes = $self-modified-changed };
-if ($@) {
-
-# File::Modified will die if a file is deleted.
-my ($deleted_file) = $@ =~ /stat '(.+)'/;
-push @changed_files, $deleted_file || 'unknown file';
-}
-
-if (@changes) {
-
-# update all mtime information
-$self-modified-update;
-
-# check if any files were changed
-@changed_files = grep { -f $_ } @changes;
-
-# Check if only directories were changed.  This means
-# a new file was created.
-unless (@changed_files) {
-
-# re-index to find new files
-my $new_watch = $self-_index_directory;
-
-# look through the new list for new files
-my $old_watch = $self-watch_list;
-@changed_files = grep { !defined $old_watch-{$_} }
-  keys %{$new_watch};
-
-return unless @changed_files;
-}
-
-# Test modified pm's
-for my $file (@changed_files) {
-next unless $file =~ /\.pm$/;
-if ( my $error = $self-_test($file) ) {
-print STDERR qq/File $file modified, not restarting\n\n/;
-print STDERR '*' x 80, \n;
-print STDERR $error;
-print STDERR '*' x 80, \n;
-return;
-}
-}
-}
-
-return @changed_files;
-}
-
-sub _index_directory {
-my $self = shift;
-
-my $dir   = $self-directory || die No directory specified;
-my $regex = $self-regex || '\.pm$';
-my %list;
-
-finddepth(
-{
-wanted = sub {
-my $file = File::Spec-rel2abs($File::Find::name);
-return unless $file =~ /$regex/;
-return unless -f $file;
-$file =~ s{/script/..}{};
-$list{$file} = 1;
-
-# also watch the directory for changes
-my $cur_dir = File::Spec-rel2abs($File::Find::dir);
-$cur_dir =~ s{/script/..}{};
-$list{$cur_dir} = 1;
-},
-no_chdir = 1
-},
-$dir
-);
-return \%list;
-}
-
-sub _test {
-my ( $self, $file ) = @_;
-
-delete $INC{$file};
-local $SIG{__WARN__} = sub { };
-
-open my $olderr, 'STDERR';
-open STDERR, '', File::Spec-devnull;
-eval require '$file';
-open STDERR, '', $olderr;
-
-return ($@) ? $@ : 0;
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Catalyst::Engine::HTTP::Restarter::Watcher - Watch for changed 

Re: [Catalyst] PATCH: refactor Catalyst::Engine::HTTP::Restarter to standalone module

2007-07-22 Thread Matt S Trout
On Sun, Jul 22, 2007 at 08:58:42AM -0400, Mark Stosberg wrote:
 Hello, 
 
 I like the auto-restart feature that is in the Catalyst HTTP::Restarter
 server. I wanted to use the restarting trick with a project based on
 HTTP::Server::Simple, so I looked to see how tied this functionality was to
 Catalyst. Here's what I found:
 
 Catalyst::Engine::HTTP::Restarter::Watcher is not functionally tied to
 Catalyst at all. It just shares a namespace. 
 
 Catalyst::Engine::HTTP::Restarter depends on no functionality from Catalyst
 but was still coupled with it through a base-class relationship which could
 be easily avoided.
 
 The attached patch moves these to modules into the HTTP::Server::Restarter
 namespace, and makes slight alternations to the other Catalyst files so
 that the functionality remains the same, as well as the dependencies. 

Wouldn't Devel::Restart::Automatic or similar be more sensible name-wise?

I don't see that there needs to be anything HTTP-dependent in the code
you're factoring out.

Once we've settled one a name, I'd be happy to set up a directory under
Catalyst svn for the factored out code and give you commit to it, then we
can move the core across to it once everybody's had a chance to play with
the factored-out code and stabilise it.

-- 
  Matt S Trout   Need help with your Catalyst or DBIx::Class project?
   Technical DirectorWant a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/ 

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] PATCH: refactor Catalyst::Engine::HTTP::Restarter to standalone module

2007-07-22 Thread Matt S Trout
And can we move this to the -dev list where it belongs, please?

-- 
  Matt S Trout   Need help with your Catalyst or DBIx::Class project?
   Technical DirectorWant a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/ 

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/