summaryrefslogtreecommitdiffstats
path: root/lib/OpenSLX/Utils.pm
diff options
context:
space:
mode:
authorOliver Tappe2007-04-14 12:52:29 +0200
committerOliver Tappe2007-04-14 12:52:29 +0200
commit52f44ed7ca529c2ac0b5c9c274db5ddcbaf34f8e (patch)
treeaf5cda7118d9eadfea5aab80aba51b2aa535c68c /lib/OpenSLX/Utils.pm
parent* added hook for checking the requirements of a specific export type (for NBD... (diff)
downloadcore-52f44ed7ca529c2ac0b5c9c274db5ddcbaf34f8e.tar.gz
core-52f44ed7ca529c2ac0b5c9c274db5ddcbaf34f8e.tar.xz
core-52f44ed7ca529c2ac0b5c9c274db5ddcbaf34f8e.zip
* 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
Diffstat (limited to 'lib/OpenSLX/Utils.pm')
-rw-r--r--lib/OpenSLX/Utils.pm28
1 files changed, 26 insertions, 2 deletions
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(
- &copyFile &fakeFile &linkFile &slurpFile
+ &copyFile &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