File Coverage

blib/lib/JMX/Jmx4Perl/Response.pm
Criterion Covered Total %
statement 6 18 33.3
branch n/a
condition 0 3 0.0
subroutine 2 12 16.6
pod 10 10 100.0
total 18 43 41.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             =head1 NAME
4              
5             JMX::Jmx4Perl::Response - A jmx4perl response
6              
7             =head1 SYNOPSIS
8              
9             my $jmx_response = $jmx_agent->request($jmx_request);
10             my $value = $jmx_response->value();
11            
12             =head1 DESCRIPTION
13              
14             A L is the result of an JMX request and encapsulates
15             the answer as returned by a L backend. Depending on the
16             C it either contains the result of a valid request or a error message.
17             The status is modelled after HTTP response codes (see
18             L). For now, only the
19             codes C<200> and C<400 .. 599> codes are used to specified successful request
20             and errors respectively.
21              
22             =head1 METHODS
23              
24             =over
25              
26             =cut
27              
28             package JMX::Jmx4Perl::Response;
29              
30 4     4   29 use strict;
  4         9  
  4         137  
31 4     4   24 use vars qw(@EXPORT);
  4         10  
  4         1200  
32              
33             =item $response = JMX::Jmx4Perl::Response->new($status,$request,$value,$error,$stacktrace)
34              
35             Internal constructor for creating a response which is use withing requesting
36             the backend. C<$error> and C<$stacktrace> are optional and should only provided
37             when C<$status != 200>.
38              
39             =cut
40              
41             sub new {
42 0     0 1   my $class = shift;
43 0           my $self = { @_ };
44 0   0       return bless $self,(ref($class) || $class);
45             }
46              
47             =item $status = $response->status()
48              
49             Return the status code of this response. Status codes are modelled after HTTP
50             return codes. C<200> is the code for a suceeded request. Any code in the range
51             500 - 599 specifies an error.
52              
53             =cut
54              
55             sub status {
56 0     0 1   return shift->{status};
57             }
58              
59             =item $timestamp = $response->timestamp()
60              
61             Get the timestamp (i.e. epoch seconds) when the request was executed on the
62             serverside.
63              
64             =cut
65              
66             sub timestamp {
67 0     0 1   return shift->{timestamp};
68             }
69              
70             =item $history = $response->history()
71              
72             Get the history if history tracking is switched on. History tracking is
73             switchen on by executing a certain JMX operation on the C
74             MBean. See the alias C and L
75             TRACKING"> for details.
76              
77             The returned arrayref (if any) contains hashes with two values: C
78             contains the historical value and C the timestamp when this value
79             was recorded.
80              
81             =cut
82              
83             sub history {
84 0     0 1   return shift->{history};
85             }
86              
87             =item $ok = $response->is_ok()
88              
89             Return true if this object contains a valid response (i.e. the status code is
90             equal 200)
91              
92             =cut
93              
94             sub is_ok {
95 0     0 1   return shift->{status} == 200;
96             }
97              
98             =item $fault = $response->is_error()
99              
100             Opposite of C, i.e. return true if the status code is B equal to
101             200
102              
103             =cut
104              
105             sub is_error {
106 0     0 1   return shift->{status} != 200;;
107             }
108              
109             =item $error = $response->error_text()
110              
111             Return the error text. Set only if C is C
112              
113             =cut
114              
115             sub error_text {
116 0     0 1   return shift->{error};
117             }
118              
119             =item $error = $response->stacktrace()
120              
121             Returns the stacktrace of an Java error if any. This is only set when
122             C is C B and Java exception occured on the Java agent's
123             side.
124              
125             =cut
126              
127 0     0 1   sub stacktrace { return shift->{stacktrace}; }
128              
129             =item $content = $response->value()
130              
131             Return the content of this response, which is a represents the JSON response as
132             returned by the Java agent as a hash reference value. This is set only when C is
133             true.
134              
135             =cut
136              
137             sub value {
138 0     0 1   return shift->{value};
139             }
140              
141             =item $request = $response->request()
142              
143             Return the L which lead to this response
144              
145             =cut
146              
147             sub request {
148 0     0 1   return shift->{request};
149             }
150              
151             =back
152              
153             =head1 LICENSE
154              
155             This file is part of jmx4perl.
156              
157             Jmx4perl is free software: you can redistribute it and/or modify
158             it under the terms of the GNU General Public License as published by
159             the Free Software Foundation, either version 2 of the License, or
160             (at your option) any later version.
161              
162             jmx4perl is distributed in the hope that it will be useful,
163             but WITHOUT ANY WARRANTY; without even the implied warranty of
164             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
165             GNU General Public License for more details.
166              
167             You should have received a copy of the GNU General Public License
168             along with jmx4perl. If not, see .
169              
170             A commercial license is available as well. Please contact roland@cpan.org for
171             further details.
172              
173             =head1 AUTHOR
174              
175             roland@cpan.org
176              
177             =cut
178              
179              
180             1;