From: Jonathan Rockway Date: Wed, 29 Apr 2009 14:43:59 +0000 (-0500) Subject: fix a bug found via $work_app X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2123b3b8eed7e62baedecf3dcd999bccf66e49c9;p=gitmo%2FMooseX-Runnable.git fix a bug found via $work_app --- diff --git a/lib/MooseX/Runnable/Util/ArgParser.pm b/lib/MooseX/Runnable/Util/ArgParser.pm index a373a92..a5b4317 100644 --- a/lib/MooseX/Runnable/Util/ArgParser.pm +++ b/lib/MooseX/Runnable/Util/ArgParser.pm @@ -195,12 +195,12 @@ sub _build_app_args { _delete_first $_, @args for map { "-I$_" } $self->include_paths; my %plugins = %{ $self->plugins }; + for my $p (keys %plugins){ my $vl = scalar @{ $plugins{$p} }; - splice @args, first_index { $_ eq "+$p" } @args, $vl + 1; + splice @args, (first_index { $_ eq "+$p" } @args), $vl + 1; } - # sanity check if($args[0] eq '--'){ shift @args; } diff --git a/t/arg-parser.t b/t/arg-parser.t index ea19237..277d7bb 100644 --- a/t/arg-parser.t +++ b/t/arg-parser.t @@ -15,7 +15,8 @@ use Test::TableDriven ( '+Plugin1 --args --go --here -- Foo' => 'Foo', '+P --args --arehere +Q --more --args -- Foo' => 'Foo', '-Ilib +P --args --arehere +Q --more --args -Ilib -- Foo' => 'Foo', - '+P --args -- Foo -- Bar', 'Foo', + '+P --args -- Foo -- Bar' => 'Foo', + '-Ilib +Debug -- PlanFinder' => 'PlanFinder', }, modules => { @@ -30,6 +31,7 @@ use Test::TableDriven ( '-Ilib +End -MFoo -- OH::HAI' => [], '-Ilib -MFoo OH::HAI' => ['Foo'], '-Ilib -MFoo +End -MBar -- OH::HAI' => ['Foo'], + '-Ilib +Debug -- PlanFinder' => [], }, include_paths => { @@ -44,7 +46,7 @@ use Test::TableDriven ( '-Ilib -MFoo +End -IBar -- OH::HAI' => ['lib'], '-Ilib -MFoo -I../../../../lib +End -IBar -- OH::HAI' => ['lib', '../../../../lib'], - + '-Ilib +Debug -- PlanFinder' => ['lib'], }, plugins => { @@ -53,34 +55,37 @@ use Test::TableDriven ( '-Ilib -MFoo -- Bar' => {}, '+One --arg +Two --arg2 -- End' => { One => ['--arg'], Two => ['--arg2'] }, '+Debug +PAR +Foo::Bar -- Baz' => { Debug => [], PAR => [], 'Foo::Bar' => [] }, + '-Ilib +Debug -- PlanFinder' => { Debug => [] }, }, is_help => { - '--help' => 1, - '-h' => 1, - '-?' => 1, - '--?' => 0, - '--h' => 0, - '+Foo --help' => 0, - 'Foo' => 0, - '-Ilib -MFoo --help' => 1, - '-- Foo --help' => 0, - 'Foo --help' => 0, - 'Foo -?' => 0, - 'Foo -h' => 0, + '--help' => 1, + '-h' => 1, + '-?' => 1, + '--?' => 0, + '--h' => 0, + '+Foo --help' => 0, + 'Foo' => 0, + '-Ilib -MFoo --help' => 1, + '-- Foo --help' => 0, + 'Foo --help' => 0, + 'Foo -?' => 0, + 'Foo -h' => 0, + '-Ilib +Debug -- PlanFinder' => 0, }, app_args => { - 'Foo' => [], - '-Ilib Foo' => [], - '-Ilib -MFoo Bar' => [], - 'Foo Bar' => ['Bar'], - 'Foo Bar Baz' => ['Bar', 'Baz'], - '-- Foo Bar Baz' => ['Bar', 'Baz'], - '-Ilib Foo -Ilib' => ['-Ilib'], - '-MFoo Foo -MFoo' => ['-MFoo'], - '-MFoo -MFoo Foo -MFoo' => ['-MFoo'], - '-- Foo --help' => ['--help'], + 'Foo' => [], + '-Ilib Foo' => [], + '-Ilib -MFoo Bar' => [], + 'Foo Bar' => ['Bar'], + 'Foo Bar Baz' => ['Bar', 'Baz'], + '-- Foo Bar Baz' => ['Bar', 'Baz'], + '-Ilib Foo -Ilib' => ['-Ilib'], + '-MFoo Foo -MFoo' => ['-MFoo'], + '-MFoo -MFoo Foo -MFoo' => ['-MFoo'], + '-- Foo --help' => ['--help'], + '-Ilib +Debug -- PlanFinder' => [], }, );