use MooseX::Types::Path::Class qw(Dir);
use List::MoreUtils qw(first_index);
+use FindBin;
+
use namespace::autoclean -also => ['_look_for_dash_something', '_delete_first'];
has 'argv' => (
return [@args];
}
+# XXX: bad
+sub guess_cmdline {
+ my ($self, %opts) = @_;
+
+ confess 'Parser is help' if $self->is_help;
+
+ my @perl_flags = @{$opts{perl_flags} || []};
+ my @without_plugins = @{$opts{without_plugins} || []};
+
+ # invoke mx-run
+ my @cmdline = ($^X, @perl_flags, $FindBin::Bin.'/'.$FindBin::Script);
+ push @cmdline, map { "-I$_" } $self->include_paths;
+ push @cmdline, map { "-M$_" } $self->modules;
+
+ p:
+ for my $plugin (keys %{$self->plugins}){
+ for my $without (@without_plugins) {
+ next p if $without eq $plugin;
+ }
+ push @cmdline, "+$plugin", @{$self->plugins->{$plugin} || []};
+ }
+ push @cmdline, '--';
+ push @cmdline, $self->class_name;
+ push @cmdline, $self->app_args;
+
+ return @cmdline;
+}
+
1;
__END__
--- /dev/null
+use strict;
+use warnings;
+use Test::More tests => 1;
+
+use MooseX::Runnable::Util::ArgParser;
+
+my $str = '-MFoo -Ilib -MBar +Plugout +Plugin --with-args -- MyApp --with args';
+
+my $args = MooseX::Runnable::Util::ArgParser->new(
+ argv => [split ' ', $str],
+);
+
+local $^X = '/path/to/perl';
+local $FindBin::Bin = '/path/to';
+local $FindBin::Script = 'mx-run';
+my @cmdline = $args->guess_cmdline(
+ perl_flags => ['--X--'],
+ without_plugins => ['Plugout'],
+);
+
+is join(' ', @cmdline),
+ "/path/to/perl --X-- /path/to/mx-run -Ilib -MFoo -MBar +Plugin --with-args -- MyApp --with args",
+ 'cmdline reverses reasonably';