package Bio::EnsEMBL::Analysis::Tools::Stashes; 

use Bio::EnsEMBL::Utils::Exception qw(verbose throw warning);
use Exporter ; 
use vars qw (@ISA @EXPORT); 

@ISA = qw(Exporter);
@EXPORT = qw( package_stash );

sub package_stash {
    my ($packageName) = @_;  

    my %result ;  

    local (*alias);  
    *stash = *{"${packageName}::"};   

    while (($varName, $globValue) = each %stash) {   
        # only return the config hash 
        next if $varName =~m/BEGIN/; 
        next if $varName =~m/import/; 

        *alias = $globValue;  
        $result{$varName}=$alias if (defined ($alias)) ; 
        $result{$varName}=\@alias if (defined (@alias)) ; 
        $result{$varName}=\%alias if (defined (%alias)) ;  
     }     

     if (scalar(keys %result >1) ) {    
       throw("Have more than one item exported from $packageName - you'll run into trouble\n")
     }  
     my $hash_name = shift @{[(keys %result)]};   
     return [$result{$hash_name},$hash_name] ; 
}

1;

package Bio::EnsEMBL::Analysis::Tools::Stashes; 

use Bio::EnsEMBL::Utils::Exception qw(verbose throw warning);
use Exporter ; 
use vars qw (@ISA @EXPORT); 

@ISA = qw(Exporter);
@EXPORT = qw( package_stash );

sub package_stash {
    my ($packageName) = @_;  

    my %result ;  

    local (*alias);  
    *stash = *{"${packageName}::"};   

    while (($varName, $globValue) = each %stash) {   
        # only return the config hash 
        next if $varName =~m/BEGIN/; 
        next if $varName =~m/import/; 

        *alias = $globValue;  
        $result{$varName}=$alias  if (defined($alias)) ; 
        $result{$varName}=\@alias if (*alias{ARRAY}) ; 
        $result{$varName}=\%alias if (*alias{HASH}) ;  
     }     

     if (scalar(keys %result >1) ) {    
       throw("Have more than one item exported from $packageName - you'll run into trouble\n")
     }  
     my $hash_name = (keys %result)[0];   
     return [$result{$hash_name},$hash_name] ; 
}

1;

Fix deprecation warning for using defined($array) in perl 5.12.
Fix deprecation warning for using defined($array) in perl 5.12.

For perl 5.12 onwards, defined(%alias) causes the following warning:
 defined(%hash) is deprecated at ...

The deprecation also holds true for defined(@alias). The correct
approach is to look into the typeglob to see if it has an ARRAY or
HASH entry. (This doesn't work for the SCALAR entry which always
exists if you check it, albeit as a reference to an undefined scalar.)
