diff --git a/bin/prove b/bin/prove index 4617c4f0..6ec5afe5 100755 --- a/bin/prove +++ b/bin/prove @@ -291,12 +291,12 @@ parser interprets particular I of TAP. If you want to provide config to the source you can use: prove --source MyCustom \ - --source 'Perl: {foo: bar baz, avg: 0.278}' \ - --source 'File: {extensions: [.txt, .tmp]}' t + --source Perl --perl-option 'foo=bar baz' --perl-option avg=0.278 \ + --source File --file-option extensions=.txt --file-option extensions=.tmp t -In this case you must have L installed, and the configuration you pass -must be a valid YAML string (a C<"\n"> is appended to whatever you pass), or an -error will be thrown. +Each C<--$source-option> option must specify a key/value pair separated by an +C<=>. If an option can take multiple values, just specify it multiple times, +as with the C examples above. All C<--sources> are combined into a hash, and passed to L's C parameter. diff --git a/lib/App/Prove.pm b/lib/App/Prove.pm index 8e7ff67a..4fba2689 100644 --- a/lib/App/Prove.pm +++ b/lib/App/Prove.pm @@ -197,7 +197,7 @@ sub process_args { { local @ARGV = @args; - Getopt::Long::Configure( 'no_ignore_case', 'bundling' ); + Getopt::Long::Configure(qw(no_ignore_case bundling pass_through)); # Don't add coderefs to GetOptions GetOptions( @@ -420,25 +420,21 @@ sub _load_extensions { sub _parse_source { my ( $self, $handler ) = @_; - my ($name, $config); - if ($handler =~ /\W/) { - eval 'require YAML'; - if (my $e = $@) { - die "couldn't parse sources '$handler': YAML not available"; - } - my $hash; - eval { $hash = YAML::Load( $handler . "\n" ) }; - if (my $e = $@) { - die "couldn't parse sources '$handler': $e"; - } - ($name) = keys %$hash; - $config = $hash->{$name}; - } else { - $name = $handler; - $config = {}; - } - - return( $name, $config ); + # Load any options. + (my $opt_name = lc $handler) =~ s/::/-/g; + local @ARGV = @{ $self->{argv} }; + my %config; + Getopt::Long::GetOptions("$opt_name-option=s%" => sub { + my (undef, $k, $v) = @_; + if (exists $config{$k}) { + $config{$k} = [ $config{$k} ] unless ref $config{$k} eq 'ARRAY'; + push @{ $config{$k} } => $v; + } else { + $config{$k} = $v; + } + }); + $self->{argv} = \@ARGV; + return ($handler, \%config); } =head3 C diff --git a/t/prove.t b/t/prove.t index aeaea621..d1d25398 100644 --- a/t/prove.t +++ b/t/prove.t @@ -1121,9 +1121,13 @@ BEGIN { # START PLAN skip => $HAS_YAML ? 0 : 1, skip_reason => "YAML not available", switches => - [ '--source', 'Perl: {foo: bar baz, avg: 0.278}', + [ '--source', 'Perl', + '--perl-option', 'foo=bar baz', + '--perl-option', 'avg=0.278', '--source', 'MyCustom', - '--source', 'File: {extensions: [.txt, .tmp]}', + '--source', 'File', + '--file-option', 'extensions=.txt', + '--file-option', 'extensions=.tmp', $dummy_test ], expect => { sources =>