line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Splunk::HEC::Response; |
2
|
2
|
|
|
2
|
|
47092
|
use Carp; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
158
|
|
3
|
2
|
|
|
2
|
|
367
|
use Splunk::Base -base; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
43
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
507
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has success => 1; |
7
|
|
|
|
|
|
|
has status => 200; |
8
|
|
|
|
|
|
|
has reason => ''; |
9
|
|
|
|
|
|
|
has content => ''; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub is_error { |
12
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
13
|
1
|
|
|
|
|
3
|
return !$self->success; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub is_success { |
17
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
18
|
1
|
|
|
|
|
3
|
return $self->success; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub TO_JSON { |
22
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
my %res = map { $_ => $self->{$_} } keys %$self; |
|
0
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return \%res; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=encoding utf8 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Splunk::HEC::Response - An object wrapper for HEC responses |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use Splunk::HEC; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $hec = Splunk::HEC->new; |
40
|
|
|
|
|
|
|
my $res = $hec->send(event => 'testEvent'); |
41
|
|
|
|
|
|
|
if ($res->is_success) { say $res->content } |
42
|
|
|
|
|
|
|
elsif ($res->is_error) { say $res->reason } |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
L is an object wrapper for HEC responses |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
L implements the following attributes. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 success |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $sucess = $res->success; |
55
|
|
|
|
|
|
|
$success = $res->success(0); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Indicates if the HEC request was successful. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 status |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $status = $res->status; |
62
|
|
|
|
|
|
|
$status = $res->status(200); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
HTTP Status Code from HEC request. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 reason |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $reason = $res->reason; |
69
|
|
|
|
|
|
|
$reason = $res->reason('An error occurred.'); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
String error message if the response was an error. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 content |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $content = $res->content; |
76
|
|
|
|
|
|
|
$content = $res->content({text => 'Success', code => 0}); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The contents of a successful HEC request (decoded from JSON) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 is_error |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $is_error = $res->is_error; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Returns true if the response was an error. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 is_success |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $is_success = $res->is_success; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns true if the request was a success. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 METHODS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L implements the following methods. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 new |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $res = Splunk::HEC::Response->new; |
99
|
|
|
|
|
|
|
my $res = Splunk::HEC::Response->new(success => 0, reason => 'Generic Error'); |
100
|
|
|
|
|
|
|
my $res = Splunk::HEC::Response->new({success => 0, reason => 'Generic Error'}); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This is the constructor used to create the Splunk::HEC::Response object. You can |
103
|
|
|
|
|
|
|
pass it either a hash or a hash reference with attribute values. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 TO_JSON |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $hash = $res->TO_JSON; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Returns a JSON encoding friendly hashref for use with L |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SEE ALSO |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L, L, L, L, L |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |