[pve-devel] [PATCH common] CLI/RESTHandler: more generic parameter mapping

Dietmar Maurer dietmar at proxmox.com
Fri Mar 2 07:05:01 CET 2018


This patch is quite hard to read. I guess it would make sense to
split this and do the function rename as extra patch?

Some questions below:

> -my $replace_file_names_with_contents = sub {
> +my $replace_mapped_contents = sub {
>      my ($param, $mapping) = @_;
>  
>      if ($mapping) {
>  	foreach my $elem ( @$mapping ) {
> -	    $param->{$elem} = PVE::Tools::file_get_contents($param->{$elem})
> -		if defined($param->{$elem});
> +	    my $mapfunc = sub { return PVE::Tools::file_get_contents($_[0]) };

why define $mapfunc, and why here? Simply use:

my $mapfunc;

> +	    if (ref($elem) eq 'ARRAY') {
> +		($elem, $mapfunc) = @$elem;

you overwrite here anyways.

> +	    }
> +	    if (defined(my $value = $param->{$elem})) {
> +		$param->{$elem} = $mapfunc->($value);

                $param->{$elem} = PVE::Tools::file_get_contents($value) 

> +	    }
>  	}
>      }




More information about the pve-devel mailing list