Skip to content

Commit

Permalink
single_valued_arrayref_to_scalar() returns the same kind of value whi…
Browse files Browse the repository at this point in the history
…ch it was originally given.
  • Loading branch information
oalders committed Apr 22, 2016
1 parent 0320556 commit 4f2e12e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/MetaCPAN/Web/Role/Elasticsearch/Adapter.pm
Expand Up @@ -63,7 +63,9 @@ yields:

sub single_valued_arrayref_to_scalar {
my ( $self, $array, $fields ) = @_;
$array = [$array] unless is_arrayref($array);
my $is_arrayref = is_arrayref($array);

$array = [$array] unless $is_arrayref;

my $has_fields = defined $fields ? 1 : 0;
$fields ||= [];
Expand All @@ -74,14 +76,11 @@ sub single_valued_arrayref_to_scalar {
my $value = $hash->{$field};

# We only operate when have an ArrayRef of one value
next
if not( ref($value)
and ( ref($value) eq 'ARRAY' )
and ( scalar @{$value} == 1 ) );
next unless is_arrayref($value) && scalar @{$value} == 1;
$hash->{$field} = $value->[0];
}
}
return $array;
return $is_arrayref ? $array : @{$array};
}

=head2 scalar_to_single_valued_arrayref
Expand Down

0 comments on commit 4f2e12e

Please sign in to comment.