X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=data%2FPVE%2FRESTHandler.pm;h=e1fb823ac9279cafb4dcef767b04b677a4ea6b7a;hp=e2e17e44cb527f63bef4480ac64f3d62af370ac0;hb=15a4dae162626075e802d1e6039ad2b3a7f2aad6;hpb=844a246d4434d5d346c94c73227ca1efd818727e;ds=sidebyside diff --git a/data/PVE/RESTHandler.pm b/data/PVE/RESTHandler.pm index e2e17e4..e1fb823 100644 --- a/data/PVE/RESTHandler.pm +++ b/data/PVE/RESTHandler.pm @@ -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) = @_;