@@ -243,52 +243,45 @@ sub detect_source {
243243 confess(' no raw source ref defined!' ) unless defined $source -> raw;
244244
245245 # find a list of handlers that can handle this source:
246- my %handlers ;
247- for my $dclass ( @{ $self -> handlers } ) {
248- my $confidence = $dclass -> can_handle($source );
249-
250- # warn "handler: $dclass: $confidence\n";
251- $handlers {$dclass } = $confidence if $confidence ;
246+ my %confidence_for ;
247+ for my $handler ( @{ $self -> handlers } ) {
248+ my $confidence = $handler -> can_handle($source );
249+ # warn "handler: $handler: $confidence\n";
250+ $confidence_for {$handler } = $confidence if $confidence ;
252251 }
253252
254- if ( !%handlers ) {
255-
256- # use Data::Dump qw( pp );
257- # warn pp( $meta );
258-
253+ if ( !%confidence_for ) {
259254 # error: can't detect source
260255 my $raw_source_short = substr ( ${ $source -> raw }, 0, 50 );
261256 confess(" Cannot detect source of '$raw_source_short '!" );
262257 return ;
263258 }
264259
265260 # if multiple handlers can handle it, choose the most confident one
266- my @handlers = (
267- map {$_ }
268- sort { $handlers {$a } <=> $handlers {$b } }
269- keys %handlers
270- );
261+ my @handlers =
262+ sort { $confidence_for {$b } <=> $confidence_for {$a } }
263+ keys %confidence_for ;
271264
272265 # Check for a tie.
273266 if ( @handlers > 1 &&
274- $handlers {$handlers [0]} == $handlers {$handlers [1]}
267+ $confidence_for {$handlers [0]} == $confidence_for {$handlers [1]}
275268 ) {
276269 my $filename = $source -> meta-> {file }{basename };
277270 die (" There is a tie between $handlers [0] and $handlers [1].\n " .
278- " Both voted $handlers {$handlers [0]} on $filename .\n " );
271+ " Both voted $confidence_for {$handlers [0]} on $filename .\n " );
279272 }
280273
281274 # this is really useful for debugging handlers:
282275 if ( $ENV {TAP_HARNESS_SOURCE_FACTORY_VOTES } ) {
283276 warn (
284277 " votes: " ,
285- join ( ' , ' , map {" $_ : $handlers {$_ }" } @handlers ),
278+ join ( ' , ' , map {" $_ : $confidence_for {$_ }" } @handlers ),
286279 " \n "
287280 );
288281 }
289282
290283 # return 1st
291- return pop @ handlers ;
284+ return $ handlers[0] ;
292285}
293286
2942871;
0 commit comments