[pve-devel] [PATCH pve-common] api_dump_remove_refs: prepare API tree for use with to_json($tree)

Dietmar Maurer dietmar at proxmox.com
Fri May 18 10:14:41 CEST 2018


> > +    if ($class eq 'ARRAY') {
> > +	my $res = [];
> > +	foreach my $el (@$tree) {
> > +	    push @$res, api_dump_remove_refs($el);
> > +	}
> > +	return $res;
> 
> above 4 lines could be written as:
> 
> 	return [ map { api_dump_remove_refs($_) } @$tree ];

I still prefer the other style.

> 
> > +    } elsif ($class eq 'HASH') {
> > +	my $res = {};
> > +	foreach my $k (keys %$tree) {
> > +	    if (my $class = ref($tree->{$k})) {
> 
> You're redeclaring $class here, not a problem per se but may be confused
> with the above declaration or could lead to subtle bugs if this gets
> refactored or copied and adapted for somewhere else.

OK, will change that. 



More information about the pve-devel mailing list