1 package MooseX::Runnable::Invocation::Plugin::Restart::Auto;
4 use MooseX::Types::Moose qw(ArrayRef RegexpRef Any Str);
5 use MooseX::Types::Path::Class qw(Dir);
6 use File::ChangeNotify;
8 # coerce ArrayRef[Dir], from ArrayRef[Any], via {[
9 # map { warn $_; Path::Class::dir($_) } @$_,
12 coerce RegexpRef, from Str, via { qr/$_/i };
14 use namespace::autoclean;
16 with 'MooseX::Runnable::Invocation::Plugin::Restart::Base';
18 has 'watch_regexp' => (
23 default => sub { qr/^[^.].+[.]pmc?$/i },
26 has 'watch_directories' => (
31 default => sub { [Path::Class::dir('.')] },
36 isa => 'File::ChangeNotify::Watcher',
40 sub _build_initargs_from_cmdline {
41 my ($self, @args) = @_;
47 # if($arg eq '--inc'){
53 elsif($arg eq '--regexp' || $arg eq '--regex'){
54 # i call them regexps, other people call them "regexen" :P
55 $next_type = 'regexp';
57 elsif($next_type eq 'dir'){
60 elsif($next_type eq 'regexp'){
64 confess 'Invalid args passed to Restart::Auto';
68 $result{watch_directories} = [map { Path::Class::dir($_) } @dirs] if @dirs;
69 $result{watch_regexp} = $regexp if $regexp;
75 my $w = File::ChangeNotify->instantiate_watcher(
76 directories => [map { $_->stringify } @{$self->watch_directories}],
77 filter => $self->watch_regexp,
86 my @events = $self->watcher->wait_for_events();
88 sleep .5; # "debounce" the notifier