From 52f44ed7ca529c2ac0b5c9c274db5ddcbaf34f8e Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 14 Apr 2007 10:52:29 +0000 Subject: * cleanup with respect to how modules/classes are loaded git-svn-id: http://svn.openslx.org/svn/openslx/trunk@890 95ad53e4-c205-0410-b2fa-d234c58c8868 --- lib/OpenSLX/Utils.pm | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'lib/OpenSLX/Utils.pm') diff --git a/lib/OpenSLX/Utils.pm b/lib/OpenSLX/Utils.pm index 611d6eb8..1c78f802 100644 --- a/lib/OpenSLX/Utils.pm +++ b/lib/OpenSLX/Utils.pm @@ -21,16 +21,17 @@ $VERSION = 1.01; @ISA = qw(Exporter); @EXPORT = qw( - ©File &fakeFile &linkFile &slurpFile + ©File &fakeFile &linkFile &slurpFile &instantiateClass ); ################################################################################ ### Module implementation ################################################################################ use Carp; -use OpenSLX::Basics; use File::Basename; +use OpenSLX::Basics; + sub copyFile { my $fileName = shift; @@ -86,4 +87,27 @@ sub slurpFile close(F); return $text; } + +sub instantiateClass +{ + my $class = shift; + my $requestedVersion = shift; + + unless (eval "require $class") { + if ($! == 2) { + die _tr("Class <%s> not found!\n", $class); + } else { + die _tr("Unable to load class <%s> (%s)\n", $class, $@); + } + } + if (defined $requestedVersion) { + my $classVersion = $class->VERSION; + if ($classVersion < $requestedVersion) { + die _tr('Could not load class <%s> (Version <%s> required, but <%s> found)', + $class, $requestedVersion, $classVersion); + } + } + return $class->new; +} + 1; \ No newline at end of file -- cgit v1.2.3-55-g7522