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;
7 use namespace::autoclean;
9 # coerce ArrayRef[Dir], from ArrayRef[Any], via {[
10 # map { warn $_; Path::Class::dir($_) } @$_,
13 coerce RegexpRef, from Str, via { qr/$_/i };
16 with 'MooseX::Runnable::Invocation::Plugin::Restart::Base',
17 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';
19 has 'watch_regexp' => (
24 default => sub { qr/^[^.].+[.]pmc?$/i },
27 has 'watch_directories' => (
32 default => sub { [Path::Class::dir('.')] },
37 isa => 'File::ChangeNotify::Watcher',
41 sub _build_initargs_from_cmdline {
42 my ($self, @args) = @_;
48 # if($arg eq '--inc'){
54 elsif($arg eq '--regexp' || $arg eq '--regex'){
55 # i call them regexps, other people call them "regexen" :P
56 $next_type = 'regexp';
58 elsif($next_type eq 'dir'){
61 elsif($next_type eq 'regexp'){
65 confess 'Invalid args passed to Restart::Auto';
69 $result{watch_directories} = [map { Path::Class::dir($_) } @dirs] if @dirs;
70 $result{watch_regexp} = $regexp if $regexp;
76 my $w = File::ChangeNotify->instantiate_watcher(
77 directories => [map { $_->stringify } @{$self->watch_directories}],
78 filter => $self->watch_regexp,
87 my @events = $self->watcher->wait_for_events();