Permalink
Browse files

Return a scalar in scalar context, as per the specifications

  • Loading branch information...
1 parent 7b60a06 commit 960f306c54416df6692c125a1ea9360ff026625e @fangly fangly committed Jun 24, 2013
Showing with 8 additions and 4 deletions.
  1. +1 −1 Bio/DB/Taxonomy/entrez.pm
  2. +1 −1 Bio/DB/Taxonomy/list.pm
  3. +6 −2 t/RemoteDB/Taxonomy.t
@@ -472,7 +472,7 @@ sub get_taxonids {
$DATA_CACHE->{name_to_id}->{$query} = [@data];
}
- wantarray() ? @data : shift @data;
+ return wantarray() ? @data : shift @data;
}
*get_taxonid = \&get_taxonids;
View
@@ -399,7 +399,7 @@ sub get_taxon {
sub get_taxonids {
my ($self, $name) = @_;
- return @{$self->{name_to_id}->{$name} || []};
+ return wantarray() ? @{$self->{name_to_id}->{$name}} : $self->{name_to_id}->{$name}->[0];
}
*get_taxonid = \&get_taxonids;
View
@@ -7,7 +7,7 @@ BEGIN {
use lib '.';
use Bio::Root::Test;
- test_begin(-tests => 142,
+ test_begin(-tests => 144,
-requires_module => 'XML::Twig');
use_ok('Bio::DB::Taxonomy');
@@ -285,7 +285,11 @@ Culicoidea, Culicidae, Anophelinae, Anopheles, Anopheles, Angusticorn,
Anopheles, maculipennis group, maculipennis species complex, Anopheles daciae"))]);
my @taxonids = $db_list->get_taxonids('Anopheles');
-is @taxonids, 3;
+is @taxonids, 3, 'List context';
+
+my $taxonid = $db_list->get_taxonids('Anopheles');
+isa_ok \$taxonid, 'SCALAR', 'Scalar context';
+ok exists { map({$_ => undef} @taxonids) }->{$taxonid};
# but we should still be able to merge in an incomplete lineage of a sister
# species and have the 'tree' remain consistent:

0 comments on commit 960f306

Please sign in to comment.