]> git.proxmox.com Git - pve-common.git/blobdiff - data/PVE/RESTHandler.pm
new helper register_page_formater
[pve-common.git] / data / PVE / RESTHandler.pm
index e2e17e44cb527f63bef4480ac64f3d62af370ac0..e1fb823ac9279cafb4dcef767b04b677a4ea6b7a 100644 (file)
@@ -235,6 +235,31 @@ sub register_method {
     push @{$method_registry->{$self}}, $info;
 }
 
+sub register_page_formater {
+    my ($self, %config) = @_;
+
+    my $format = $config{format} ||
+       die "missing format";
+
+    my $path = $config{path} ||
+       die "missing path";
+
+    my $method = $config{method} ||
+       die "missing method";
+       
+    my $code = $config{code} ||
+       die "missing formater code";
+    
+    my $uri_param = {};
+    my ($handler, $info) = $self->find_handler($method, $path, $uri_param);
+    die "unabe to find handler for '$method: $path'" if !($handler && $info);
+
+    die "duplicate formater for '$method: $path'" 
+       if $info->{formater} && $info->{formater}->{$format};
+
+    $info->{formater}->{$format} = $code;
+}
+
 sub AUTOLOAD {
     my ($this) = @_;