PVE::JSONSchema::register_renderer - allow to register renderers by name
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 29 Jun 2018 11:15:18 +0000 (13:15 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 29 Jun 2018 12:39:48 +0000 (14:39 +0200)
We want to use those renderer to format CLI output nicely.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
src/PVE/JSONSchema.pm

index 41a6652..f0ac441 100644 (file)
@@ -121,6 +121,22 @@ sub get_format {
     return $format_list->{$format};
 }
 
+my $renderer_hash = {};
+
+sub register_renderer {
+    my ($name, $code) = @_;
+
+    die "renderer '$name' already registered\n"
+       if $renderer_hash->{$name};
+
+    $renderer_hash->{$name} = $code;
+}
+
+sub get_renderer {
+    my ($name) = @_;
+    return $renderer_hash->{$name};
+}
+
 # register some common type for pve
 
 register_format('string', sub {}); # allow format => 'string-list'