line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Plesk::Response; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
1621
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use XML::XPath; |
6
|
|
|
|
|
|
|
use XML::XPath::XMLParser; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Net::Plesk::Response - Plesk response object |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $response = $plesk->some_method( $and, $args ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
if ( $response->is_success ) { |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $id = $response->id; |
19
|
|
|
|
|
|
|
#... |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} else { |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $error = $response->error; #error code |
24
|
|
|
|
|
|
|
my $errortext = $response->errortext; #error message |
25
|
|
|
|
|
|
|
#... |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
The "Net::Plesk::Response" class represents Plesk responses. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
|
|
|
|
|
|
my $proto = shift; |
36
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
37
|
|
|
|
|
|
|
my $self = {}; |
38
|
|
|
|
|
|
|
bless($self, $class); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $data = shift; |
41
|
|
|
|
|
|
|
if ($data =~ /^\<\?xml version=\"1.0\"\?\>(.*)$/s){ |
42
|
|
|
|
|
|
|
$data=$1; |
43
|
|
|
|
|
|
|
}else{ |
44
|
|
|
|
|
|
|
$data =~ s/[^\w\s]/ /g; # yes, we lose stuff |
45
|
|
|
|
|
|
|
$data = '' . |
46
|
|
|
|
|
|
|
'' . |
47
|
|
|
|
|
|
|
"error500" . |
48
|
|
|
|
|
|
|
"Malformed Plesk response:" . $data . "". |
49
|
|
|
|
|
|
|
""; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $xp = XML::XPath->new(xml => $data); |
53
|
|
|
|
|
|
|
my $nodeset = $xp->find('//result'); |
54
|
|
|
|
|
|
|
foreach my $node ($nodeset->get_nodelist) { |
55
|
|
|
|
|
|
|
push @{$self->{'results'}}, XML::XPath::XMLParser::as_string($node); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
$nodeset = $xp->find('//system'); |
58
|
|
|
|
|
|
|
foreach my $node ($nodeset->get_nodelist) { |
59
|
|
|
|
|
|
|
my $parsed = XML::XPath::XMLParser::as_string($node); |
60
|
|
|
|
|
|
|
$parsed =~ s/\<(\/?)system\>/<$1result>/ig; |
61
|
|
|
|
|
|
|
push @{$self->{'results'}}, $parsed; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub is_success { |
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
my $status = 1; |
70
|
|
|
|
|
|
|
foreach my $result (@{$self->{'results'}}) { |
71
|
|
|
|
|
|
|
$status = (XMLin($result)->{'status'} eq 'ok'); |
72
|
|
|
|
|
|
|
last unless $status; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
$status; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub error { |
78
|
|
|
|
|
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
my @errcode; |
80
|
|
|
|
|
|
|
foreach my $result (@{$self->{'results'}}) { |
81
|
|
|
|
|
|
|
my $errcode = XMLin($result)->{'errcode'}; |
82
|
|
|
|
|
|
|
push @errcode, $errcode if $errcode; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
return wantarray ? @errcode : $errcode[0]; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub errortext { |
88
|
|
|
|
|
|
|
my $self = shift; |
89
|
|
|
|
|
|
|
my @errtext; |
90
|
|
|
|
|
|
|
foreach my $result (@{$self->{'results'}}) { |
91
|
|
|
|
|
|
|
my $errtext = XMLin($result)->{'errtext'}; |
92
|
|
|
|
|
|
|
push @errtext, $errtext if $errtext; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
return wantarray ? @errtext : $errtext[0]; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub id { |
98
|
|
|
|
|
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
my @id; |
100
|
|
|
|
|
|
|
foreach my $result (@{$self->{'results'}}) { |
101
|
|
|
|
|
|
|
my $id = XMLin($result)->{'id'}; |
102
|
|
|
|
|
|
|
push @id, $id if $id; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
return wantarray ? @id : $id[0]; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 BUGS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Needs better documentation. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SEE ALSO |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L, |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Jeff Finucane Ejeff@cmh.netE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Copyright (C) 2006 Jeff Finucane |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
125
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |