line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#--------------------------------------------------------------------# |
2
|
|
|
|
|
|
|
# @class : Chef::Rest::Client::EndPoints # |
3
|
|
|
|
|
|
|
# @author : Bhavin Patel # |
4
|
|
|
|
|
|
|
#--------------------------------------------------------------------# |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Chef::REST::Client::EndPoints; |
7
|
|
|
|
|
|
|
$Chef::REST::Client::EndPoints::VERSION = 1.0; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=pod |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Chef::REST::Client::EndPoints |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
1.0 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $obj = new Chef::REST::Client::EndPoints( 'api_end_point' => $end_point ); |
22
|
|
|
|
|
|
|
$obj->populate($result); |
23
|
|
|
|
|
|
|
$obj->raw; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
used internally by other classes |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 Constructor |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
initialized api_end_point |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 api_end_point( $end_point ) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
set api_end_point if passed otherwise returns current value |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 populate($result) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
internal method generates data structure based on the result of the http request |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 raw |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
returns the raw data structure. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my @base; |
50
|
|
|
|
|
|
|
BEGIN { |
51
|
3
|
|
|
3
|
|
2621
|
use File::Basename qw { dirname }; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
234
|
|
52
|
3
|
|
|
3
|
|
22
|
use File::Spec::Functions qw { splitdir rel2abs }; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
312
|
|
53
|
3
|
|
|
3
|
|
198
|
@base = ( splitdir ( rel2abs ( dirname(__FILE__) ) ) ); |
54
|
3
|
|
|
|
|
107
|
pop @base; #REST |
55
|
3
|
|
|
|
|
7
|
pop @base; #Chef |
56
|
3
|
|
|
|
|
90
|
push @INC, '/', @base; |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
3
|
|
5025
|
use Mojo::JSON; |
|
3
|
|
|
|
|
174648
|
|
|
3
|
|
|
|
|
936
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new { |
62
|
2
|
|
|
2
|
0
|
1114
|
my $class = shift; |
63
|
2
|
|
|
|
|
8
|
my $param = {@_}; |
64
|
2
|
|
|
|
|
5
|
my $self = {}; |
65
|
2
|
|
|
|
|
6
|
bless $self, $class; |
66
|
2
|
|
|
|
|
14
|
$self->api_end_point($param->{'api_end_point'}); |
67
|
2
|
|
|
|
|
8
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub api_end_point |
71
|
|
|
|
|
|
|
{ |
72
|
2
|
|
|
2
|
1
|
6
|
my ($self,$api_end_point) = (@_); |
73
|
2
|
50
|
|
|
|
14
|
$self->{ 'API_END_POINT' } = $api_end_point if defined $api_end_point; |
74
|
2
|
|
|
|
|
13
|
return $self->{ 'API_END_POINT' }; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub populate |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
my $result = shift; |
81
|
0
|
|
|
|
|
|
$self->___data___($result); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub ___data___ |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
0
|
|
|
my $self = shift; |
87
|
0
|
|
|
|
|
|
my $result = shift; |
88
|
0
|
|
|
|
|
|
my $mojo_json = new Mojo::JSON(); |
89
|
0
|
0
|
|
|
|
|
$self->{'___data___'} = |
90
|
|
|
|
|
|
|
$mojo_json->decode( $result ) |
91
|
|
|
|
|
|
|
if defined $result; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $self->{'___data___'}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
1
|
|
sub raw { return $_[0]->___data___; } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 KNOWN BUGS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SUPPORT |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
open a github ticket or email comments to Bhavin Patel |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This Software is free to use , licensed under : The Artisic License 2.0 (GPL Compatible) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |