I am wokring on a perl project and i have to dynamically use perl modules. I have the following module called CT.pm:
sub new {
my $class = shift;
my ($debug, $debug_matches,%checkHash) = @_;
my $self = {};
$self->{DEBUG} = shift;
$self->{DEBUG_MATCHES} = shift;
$self->{CHECKRESULT_OK} = "COMPLIANT";
$self->{CHECKRESULT_ERROR} = "NONCOMPLIANT";
%{$self->{checkHash}} = %checkHash;
eval{
use $checkHash{"type"};
$check = $checkHash{"type"}->new($self->{DEBUG},$self->{DEBUG_MATCHES},%checkHash);
};
bless($self,$class);
return $self;
}
This constructor gets a hash called %checkHash as parameter. This hash has a key called type. The value that this key maps to a name of a perl module i want to use dynamically.
I have come up with the following way to do it:(which i know wont work and i also know that people say that eval is bad):
eval{
use $checkHash{"type"};
$check = $checkHash{"type"}->new($self->{DEBUG},$self->{DEBUG_MATCHES},%checkHash);
};
But the idea is to dynamically use a perl module with the name of $checkHash{"type"}.
If anyone has any idea on how to do this pls help :) thx! :D