Subject: | Error when XML::Simple don't create arrays in fetch_array_abstract |
When we do API::CPanel::User::list( $connection_params ); CPanel can
return this XML:
<listaccts>
<acct>
<disklimit>50M</disklimit>
...
</acct>
</listaccts>
If the number of users is one, XML::Simple don't create an array of acct
(the container) because only have one element.
fetch_array_abstract() receive from query_abstract a hash reference, not
a array reference:
$VAR1 = {
'acct' => {
'disklimit' => '50M',
...
},
};
then fetch_array_abstract() return a empty list:
return $result_list unless $result && ref $result eq 'ARRAY';
A possible solution (work verified for one user list):
sub fetch_array_abstract {
my %params = @_;
my $result_field = $params{result_field} || '';
my $result_list = [ ];
my $result = query_abstract(
params => $params{params},
func => $params{func},
container => $params{container},
allowed_fields => $params{allowed_fields},
);
return $result_list unless $result; # <= exit
$result = [$result] unless ref $result eq 'ARRAY'; # <= make an
array ref
foreach my $elem ( @{ $result } ) {
push @$result_list, $result_field ? $elem->{$result_field} : $elem;
};
return $result_list;
}