API-Plesk
view release on metacpan or search on metacpan
lib/API/Plesk/Component.pm view on Meta::CPAN
package API::Plesk::Component;
use strict;
use warnings;
use Carp;
sub new {
my ( $class, %attrs ) = @_;
$class = ref $class || $class;
confess "Required API::Plesk object!" unless $attrs{plesk};
return bless \%attrs, $class;
}
# API::Plesk object
sub plesk { $_[0]->{plesk} }
sub check_required_params {
my ( $self, $hash, @fields ) = @_;
for my $key ( @fields ) {
if ( ref $key ) {
confess "Required any of this fields: " . join( ", ", @$key) . "!"
unless grep { $hash->{$_} } @$key;
} else {
confess "Required field $key!" unless exists $hash->{$key};
}
}
}
# sort params in right order
sub sort_params {
my ( $self, $params, @fields ) = @_;
my @sorted;
for my $key ( @fields ) {
if ( ref $key ) {
($key) = grep { exists $params->{$_} } @$key
}
push @sorted, {$key => $params->{$key}}
if exists $params->{$key};
}
return \@sorted;
}
# check hosting xml section
sub check_hosting {
my ( $self, $params, $required ) = @_;
unless ( $params->{hosting} ) {
confess "Required hosting!" if $required;
return;
}
my $hosting = $params->{hosting};
my $type = delete $hosting->{type};
my $ip = delete $hosting->{ip_address};
#confess "Required ip_address" unless $ip;
if ( $type eq 'vrt_hst' ) {
$self->check_required_params($hosting, qw(ftp_login ftp_password));
my @properties;
for my $key ( sort keys %$hosting ) {
push @properties, { property => [
{name => $key},
{value => $hosting->{$key}}
( run in 0.914 second using v1.01-cache-2.11-cpan-39bf76dae61 )