[wellwell] Add [wrapper] tag to load a class and instantiate an object with parameters passed to the tag.

Stefan Hornburg interchange-cvs at icdevgroup.org
Fri Feb 10 09:52:30 UTC 2017


commit 2381e04d2f24d0bcad4321b112bc76a1b9f220fb
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Fri Feb 10 10:34:23 2017 +0100

    Add [wrapper] tag to load a class and instantiate an object with parameters passed to the tag.
    You can also set a scratch variable to the resulting object and use it elsewhere in tags or ITL.

 global/wrapper.tag |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/global/wrapper.tag b/global/wrapper.tag
new file mode 100644
index 0000000..a6104ac
--- /dev/null
+++ b/global/wrapper.tag
@@ -0,0 +1,35 @@
+UserTag wrapper Order class
+UserTag wrapper AddAttr
+UserTag wrapper Routine <<EOR
+sub {
+    my ($class, $opt) = @_;
+    my (%args, $object, $scratch_var);
+
+    # copy tag attributes, drop class and reparse
+    %args = %$opt if $opt;
+    delete $args{class};
+    delete $args{reparse};
+    $scratch_var = delete $args{scratch};
+
+    # load class
+    eval "require $class";
+
+    if ($@) {
+        die "[wrapper]: Failed to load class $class: $@";
+    }
+
+    eval {
+        $object = $class->new(%args);
+    };
+
+    if ($@) {
+        die "[wrapper] Failed to instantiate class $class: $@";
+    }
+
+    if ($scratch_var) {
+        $Scratch->{$scratch_var} = $object;
+    }
+
+    return $object;
+}
+EOR



More information about the interchange-cvs mailing list