diff --git a/modules/Bio/EnsEMBL/Utils/Logger.pm b/modules/Bio/EnsEMBL/Utils/Logger.pm index 8cdde2995c610bc119e8d288e04b07fa5bb3e33d..244f89a19e7a0389b7725d6fad75a3f205a1e774 100644 --- a/modules/Bio/EnsEMBL/Utils/Logger.pm +++ b/modules/Bio/EnsEMBL/Utils/Logger.pm @@ -161,10 +161,10 @@ sub log_error { $txt = "ERROR: ".$txt; $self->log($txt, $indent); - $self->log("Exiting prematurely.\n\n"); + $self->log("\nExiting prematurely.\n\n"); $self->log("Runtime: ".$self->runtime." ".$self->date_and_mem."\n\n"); - exit; + exit(1); } diff --git a/modules/Bio/EnsEMBL/Utils/ScriptUtils.pm b/modules/Bio/EnsEMBL/Utils/ScriptUtils.pm index 24b2308d64ae7542bcf1e9c6e135a8441c8b1d77..11a345c5068912bda1ccd0aecad371ce12efaf7b 100644 --- a/modules/Bio/EnsEMBL/Utils/ScriptUtils.pm +++ b/modules/Bio/EnsEMBL/Utils/ScriptUtils.pm @@ -40,6 +40,8 @@ our @EXPORT_OK = qw( commify sort_chromosomes parse_bytes + directory_hash + dynamic_use ); @@ -181,4 +183,44 @@ sub parse_bytes { return "$parsed ".$suffixes[$order]; } + +sub directory_hash { + my $filename = shift; + + my (@md5) = md5_hex($filename) =~ /\G(..)/g; + return join('/', @md5[0..2]); +} + + +=head2 dynamic_use + + Arg [1] : String $classname - The name of the class to require/import + Example : $self->dynamic_use('Bio::EnsEMBL::DBSQL::DBAdaptor'); + Description: Requires and imports the methods for the classname provided, + checks the symbol table so that it doesnot re-require modules + that have already been required. + Returntype : true on success + Exceptions : Warns to standard error if module fails to compile + Caller : internal + +=cut + +sub dynamic_use { + my $classname = shift; + my ($parent_namespace, $module) = $classname =~/^(.*::)(.*)$/ ? + ($1,$2) : ('::', $classname); + no strict 'refs'; + + # return if module has already been imported + return 1 if $parent_namespace->{$module.'::'}; + + eval "require $classname"; + die("Failed to require $classname: $@") if ($@); + + $classname->import(); + + return 1; +} + 1; +