NAME
API::Plesk::Response - Class for processing server answers with errors handling.
SYNOPSIS
use API::Plesk::Response;
my $res = API::Plesk::Response->new($server_answer, @errors_list);
# $server_answer -- data from server
# @errors_list -- list of errors
DESCRIPTION
This class is intended for convenient processing results of work of methods of class API::Plesk.
METHODS
- new($server_answer, @errors))
-
Create server response object.
API::Plesk::Response->new($server_answer, @errors) $server_answer - server answer, @errors - list of errors.
- get_id
-
Get executed operation ID
Return $self->get_data->[0]->{id}, if no errors and server answer consists of only one block.
- is_success
-
Get operation result
Return true if server answer not blank and no errors in answer.
- get_data
-
Get data from response
Return answer response if $instance->is_success is true.
- get_error_code
-
Get all error codes from response as arref
- get_error_string
-
Return joined by ', ' error codes.
EXAMPLES
use API::Plesk::Response;
# API::Plesk::Response->new ('server answer', @errors_list)
# Good answers
my $res1 = API::Plesk::Response->new('server answer', '');
print 'All ok' if $res1->is_success;
# print "All ok"
print $res1->get_data;
# print "server answer"
print $res1->get_error_string;
# Print '', # because no errors
# One error present
my $res2 = API::Plesk::Response->new('', 'error1');
print 'Operation failed' unless $res2->is_success;
# print "Operation Failed"
print $res2->get_data;
# print ''
print $res2->get_error_string;
# Print '', # print "error1"
# Multiple errors
my $res3 = API::Plesk::Response->new('', 'error1', 'error2', 'error3');
print $res3->get_error_string; # print "error1, error2, error3"
EXPORT
None by default.
SEE ALSO
Blank.
AUTHOR
Odintsov Pavel <nrg[at]cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2008 by NRG
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.