line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package REST::Cypher::Agent; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$REST::Cypher::Agent::DIST = 'REST-Cypher'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
$REST::Cypher::Agent::VERSION = '0.0.2'; # TRIAL |
6
|
3
|
|
|
3
|
|
102905
|
use Moo; |
|
3
|
|
|
|
|
16555
|
|
|
3
|
|
|
|
|
24
|
|
7
|
3
|
|
|
3
|
|
7492
|
use MooX::Types::MooseLike::Base qw/Bool/; |
|
3
|
|
|
|
|
6717
|
|
|
3
|
|
|
|
|
200
|
|
8
|
3
|
|
|
3
|
|
797
|
use MooseX::Params::Validate; |
|
3
|
|
|
|
|
583246
|
|
|
3
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
1919056
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
15354909
|
|
|
3
|
|
|
|
|
1356
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has base_url => ( |
13
|
|
|
|
|
|
|
is => 'rw', |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
writer => '_base_url', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has cypher_url => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
lazy => 1, |
21
|
|
|
|
|
|
|
default => sub { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $base = $self->base_url; |
25
|
|
|
|
|
|
|
if($base =~ s{/$}{}) { |
26
|
|
|
|
|
|
|
$self->_base_url( $base ); |
27
|
|
|
|
|
|
|
warn $self->base_url; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sprintf( |
31
|
|
|
|
|
|
|
'%s/db/data/cypher', |
32
|
|
|
|
|
|
|
$self->base_url, |
33
|
|
|
|
|
|
|
) |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has agent_string => ( |
38
|
|
|
|
|
|
|
is => 'ro', |
39
|
|
|
|
|
|
|
default => sub { q[REST::Cypher::Agent/0.0.0] }, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has agent => ( |
43
|
|
|
|
|
|
|
is => 'ro', |
44
|
|
|
|
|
|
|
lazy => 1, |
45
|
|
|
|
|
|
|
default => sub { |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
LWP::UserAgent->new( |
48
|
|
|
|
|
|
|
agent => $self->agent_string, |
49
|
|
|
|
|
|
|
protocols_allowed => [ 'http', 'https'], |
50
|
|
|
|
|
|
|
default_header => [ Accept => 'application/json' ], |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has auth_token => ( |
56
|
|
|
|
|
|
|
is => 'ro', |
57
|
|
|
|
|
|
|
lazy => 1, |
58
|
|
|
|
|
|
|
default => 'bmVvNGo6ZHJhZzk5', |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has last_response => ( |
62
|
|
|
|
|
|
|
is => 'rw', |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has debug => ( |
66
|
|
|
|
|
|
|
is => 'rw', |
67
|
|
|
|
|
|
|
isa => Bool, |
68
|
|
|
|
|
|
|
default => 0, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub GET { |
73
|
0
|
|
|
0
|
1
|
0
|
my ($self, %params) = validated_hash( |
74
|
|
|
|
|
|
|
\@_, |
75
|
|
|
|
|
|
|
query_string => { isa => 'Str' }, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $string = |
79
|
|
|
|
|
|
|
sprintf( |
80
|
|
|
|
|
|
|
'%s/db/data%s', |
81
|
|
|
|
|
|
|
$self->base_url, |
82
|
|
|
|
|
|
|
$params{query_string}, |
83
|
0
|
|
|
|
|
0
|
); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
$self->last_response( |
86
|
|
|
|
|
|
|
$self->agent->get($string) |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub POST { |
92
|
2
|
|
|
2
|
1
|
163
|
my ($self, %params) = validated_hash( |
93
|
|
|
|
|
|
|
\@_, |
94
|
|
|
|
|
|
|
query_string => { isa => 'Str', optional => 0, }, |
95
|
|
|
|
|
|
|
query_params => { isa => 'HashRef', optional => 1, }, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
3
|
|
|
3
|
|
2881
|
use JSON::Any; |
|
3
|
|
|
|
|
11828
|
|
|
3
|
|
|
|
|
21
|
|
99
|
|
|
|
|
|
|
my $json = JSON::Any->objToJson( |
100
|
|
|
|
|
|
|
{ |
101
|
|
|
|
|
|
|
query => $params{query_string}, |
102
|
|
|
|
|
|
|
params => $params{query_params}, |
103
|
|
|
|
|
|
|
} |
104
|
2
|
|
|
|
|
1013
|
); |
105
|
|
|
|
|
|
|
|
106
|
2
|
50
|
|
|
|
125
|
if ($self->debug) { |
107
|
0
|
|
|
|
|
0
|
my $tmp = $params{query_string}; |
108
|
0
|
|
|
|
|
0
|
$tmp =~ s{\s+}{ }g; |
109
|
0
|
|
|
|
|
0
|
warn "[POST] $tmp\n"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
514
|
$DB::single=1; |
113
|
2
|
|
|
|
|
41
|
$self->last_response( |
114
|
|
|
|
|
|
|
$self->agent->post( |
115
|
|
|
|
|
|
|
$self->cypher_url, |
116
|
|
|
|
|
|
|
Content => $json, |
117
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
118
|
|
|
|
|
|
|
'Authorization' => "Basic " . $self->auth_token, |
119
|
|
|
|
|
|
|
) |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=pod |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=encoding UTF-8 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 NAME |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
REST::Cypher::Agent |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 VERSION |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
version 0.0.2 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 base_url |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 cypher_url |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 agent_string |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 agent |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 auth_token |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 last_response |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 debug |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 METHODS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 GET |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 POST |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Chisel <chisel@chizography.net> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Chisel Wright. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
171
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |