1 package MooseX::Runnable::Invocation::Plugin::Restart::Auto;
4 use MooseX::Types::Moose qw(ArrayRef RegexpRef Any Str);
5 use MooseX::Types::Path::Tiny qw(Path);
6 use Path::Tiny; # exports path()
7 use File::ChangeNotify;
8 use namespace::autoclean;
10 # coerce ArrayRef[Dir], from ArrayRef[Any], via {[
11 # map { warn $_; Path::Class::dir($_) } @$_,
14 coerce RegexpRef, from Str, via { qr/$_/i };
17 with 'MooseX::Runnable::Invocation::Plugin::Restart::Base',
18 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';
20 has 'watch_regexp' => (
25 default => sub { qr/^[^.].+[.]pmc?$/i },
28 has 'watch_directories' => (
30 isa => ArrayRef[Path],
33 default => sub { [path('.')] },
38 isa => 'File::ChangeNotify::Watcher',
42 sub _build_initargs_from_cmdline {
43 my ($self, @args) = @_;
49 # if($arg eq '--inc'){
55 elsif($arg eq '--regexp' || $arg eq '--regex'){
56 # i call them regexps, other people call them "regexen" :P
57 $next_type = 'regexp';
59 elsif($next_type eq 'dir'){
62 elsif($next_type eq 'regexp'){
66 confess 'Invalid args passed to Restart::Auto';
70 $result{watch_directories} = [map { path($_) } @dirs] if @dirs;
71 $result{watch_regexp} = $regexp if $regexp;
77 my $w = File::ChangeNotify->instantiate_watcher(
78 directories => [map { $_->stringify } @{$self->watch_directories}],
79 filter => $self->watch_regexp,
88 my @events = $self->watcher->wait_for_events();