# Ensembl module for Bio::EnsEMBL::Analysis::Config::Funcgen::MAT
#
# Copyright (c) 2007 Ensembl
#

=head1 NAME

  Bio::EnsEMBL::Analysis::Config::Funcgen::MAT

=head1 SYNOPSIS

  use Bio::EnsEMBL::Analysis::Config::Funcgen::MAT;
  
  use Bio::EnsEMBL::Analysis::Config::Funcgen::MAT qw(CONFIG);

=head1 DESCRIPTION

This is a module needed to provide configuration for the
MAT RunnableDBs.

CONFIG is an hash of hashes which contains analysis specific
settings and is keyed on logic_name

=head1 LICENCE

This code is distributed under an Apache style licence. Please see
http://www.ensembl.org/info/about/code_licence.html for details.

=head1 AUTHOR

Stefan Graf, Ensembl Functional Genomics - http://www.ensembl.org/

=head1 CONTACT

Post questions to the Ensembl development list: ensembl-dev@ebi.ac.uk

=cut

package Bio::EnsEMBL::Analysis::Config::Funcgen::MAT;

use strict;
use vars qw(%Config);

%Config = 
    (
     CONFIG => {
         DEFAULT => {
             PROGRAM           => $ENV{PROGRAM},
             PROGRAM_FILE      => $ENV{PROGRAM_FILE},
             VERSION           => $ENV{VERSION},
             PARAMETERS        => $ENV{PARAMETERS},
             EXPERIMENT        => $ENV{EXPERIMENT},
             NORM_ANALYSIS     => $ENV{NORM_ANALYSIS},
             RESULT_SET_REGEXP => $ENV{RESULT_SET_REGEXP},
             DATASET_NAME      => $ENV{DATASET_NAME},
             ANALYSIS_WORK_DIR => $ENV{ANALYSIS_WORK_DIR},
         },
         MAT => {
             PROGRAM           => $ENV{PROGRAM},
             PROGRAM_FILE      => $ENV{PROGRAM_FILE},
             VERSION           => $ENV{VERSION},
             PARAMETERS        => $ENV{PARAMETERS},
             EXPERIMENT        => $ENV{EXPERIMENT},
             NORM_ANALYSIS     => $ENV{NORM_ANALYSIS},
             RESULT_SET_REGEXP => $ENV{RESULT_SET_REGEXP},
             DATASET_NAME      => $ENV{DATASET_NAME},
             ANALYSIS_WORK_DIR => $ENV{ANALYSIS_WORK_DIR},
         }
     });

sub import {
    my ($callpack) = caller(0); # Name of the calling package
    my $pack = shift; # Need to move package off @_
    
    # Get list of variables supplied, or else all
    my @vars = @_ ? @_ : keys(%Config);
    return unless @vars;
    
    # Predeclare global variables in calling package
    eval "package $callpack; use vars qw("
        . join(' ', map { '$'.$_ } @vars) . ")";
    die $@ if $@;
    
    
    foreach (@vars) {
        if (defined $Config{ $_ }) {
            no strict 'refs';
            # Exporter does a similar job to the following
            # statement, but for function names, not
            # scalar variables:
            *{"${callpack}::$_"} = \$Config{ $_ };
        } else {
            die "Error: Config: $_ not known\n";
        }
    }
}

1;
