line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::JSON::RPC::Autodoc::Request; |
2
|
4
|
|
|
4
|
|
13235
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
91
|
|
3
|
4
|
|
|
4
|
|
11
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
80
|
|
4
|
4
|
|
|
4
|
|
351
|
use parent qw/HTTP::Request/; |
|
4
|
|
|
|
|
221
|
|
|
4
|
|
|
|
|
28
|
|
5
|
4
|
|
|
4
|
|
47932
|
use Clone qw/clone/; |
|
4
|
|
|
|
|
7299
|
|
|
4
|
|
|
|
|
193
|
|
6
|
4
|
|
|
4
|
|
1060
|
use JSON qw/to_json/; |
|
4
|
|
|
|
|
15555
|
|
|
4
|
|
|
|
|
19
|
|
7
|
4
|
|
|
4
|
|
397
|
use Test::Builder; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
67
|
|
8
|
4
|
|
|
4
|
|
1201
|
use Try::Tiny; |
|
4
|
|
|
|
|
2738
|
|
|
4
|
|
|
|
|
171
|
|
9
|
4
|
|
|
4
|
|
1674
|
use Test::JSON::RPC::Autodoc::Response; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
104
|
|
10
|
4
|
|
|
4
|
|
1444
|
use Test::JSON::RPC::Autodoc::Validator; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
121
|
|
11
|
4
|
|
|
4
|
|
1749
|
use Plack::Test::MockHTTP; |
|
4
|
|
|
|
|
1626
|
|
|
4
|
|
|
|
|
2800
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
5
|
|
|
5
|
1
|
23
|
my ($class, %opt) = @_; |
15
|
5
|
|
|
|
|
31
|
my $self = $class->SUPER::new(); |
16
|
5
|
|
100
|
|
|
75
|
$self->uri($opt{path} || '/'); |
17
|
5
|
|
|
|
|
9513
|
$self->{method} = 'POST'; |
18
|
5
|
|
|
|
|
9
|
$self->{app} = $opt{app}; |
19
|
5
|
|
50
|
|
|
25
|
$self->{id} = $opt{id} || 1; |
20
|
5
|
|
100
|
|
|
19
|
$self->{label} = $opt{label} || undef; |
21
|
5
|
|
|
|
|
15
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub json_rpc_method { |
25
|
3
|
|
|
3
|
0
|
4
|
my ($self, $name) = @_; |
26
|
3
|
50
|
|
|
|
13
|
return $self->{json_rpc_method} unless $name; |
27
|
0
|
|
|
|
|
0
|
$self->{json_rpc_method} = $name; |
28
|
0
|
|
|
|
|
0
|
return $name; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub main_content { |
32
|
3
|
|
|
3
|
0
|
102
|
my ($self, $content) = @_; |
33
|
3
|
50
|
|
|
|
10
|
return $self->{main_content} unless $content; |
34
|
0
|
|
|
|
|
0
|
$self->{main_content} = $content; |
35
|
0
|
|
|
|
|
0
|
return $content; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub params { |
39
|
3
|
|
|
3
|
0
|
286
|
my ($self, %params) = @_; |
40
|
3
|
|
|
|
|
65
|
$self->{rule} = clone \%params; |
41
|
3
|
|
|
|
|
10
|
for my $p (%params) { |
42
|
8
|
100
|
|
|
|
23
|
next unless ref $p eq 'HASH'; |
43
|
4
|
|
|
|
|
10
|
for my $key (keys %$p) { |
44
|
12
|
100
|
|
|
|
28
|
if ( $key eq 'required' ) { |
45
|
3
|
|
|
|
|
7
|
$p->{optional} = !$p->{required}; |
46
|
3
|
|
|
|
|
8
|
delete $p->{$key}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
3
|
|
|
|
|
64
|
my $validator = Data::Validator->new(%params)->with('NoThrow'); |
51
|
3
|
|
|
|
|
8600
|
$self->{validator} = $validator; |
52
|
3
|
|
|
|
|
8
|
return $validator; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub validator { |
56
|
21
|
|
|
21
|
0
|
76
|
my $self = shift; |
57
|
21
|
100
|
|
|
|
85
|
return $self->{validator} if $self->{validator}; |
58
|
3
|
|
|
|
|
15
|
return Data::Validator->new->with('NoThrow'); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub post_ok { |
62
|
5
|
|
|
5
|
0
|
1048
|
my ($self, $method, $params, $headers) = @_; |
63
|
5
|
|
100
|
|
|
16
|
$params ||= {}; |
64
|
5
|
|
|
|
|
8
|
my $args = $self->validator->validate(%$params); |
65
|
5
|
|
|
|
|
576
|
my $ok = 1; |
66
|
5
|
50
|
|
|
|
93
|
$ok = 0 if $self->validator->has_errors; |
67
|
5
|
|
|
|
|
422
|
$self->validator->clear_errors(); |
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
|
|
414
|
my $json = $self->_make_request($method, $params, $headers); |
70
|
|
|
|
|
|
|
|
71
|
5
|
|
|
|
|
24
|
my $mock = Plack::Test::MockHTTP->new($self->{app}); |
72
|
5
|
|
|
|
|
25
|
my $res = $mock->request($self); |
73
|
5
|
50
|
|
|
|
4580
|
$ok = 0 if $res->code != 200; |
74
|
5
|
|
|
|
|
62
|
my $Test = Test::Builder->new(); |
75
|
5
|
|
|
|
|
27
|
$Test->ok($ok); |
76
|
|
|
|
|
|
|
|
77
|
5
|
|
|
|
|
1220
|
$self->{response} = $res; |
78
|
5
|
|
|
|
|
8
|
$self->{main_content} = $json; |
79
|
5
|
|
|
|
|
7
|
$self->{json_rpc_method} = $method; |
80
|
5
|
|
|
|
|
20
|
return $res; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub post_only { |
84
|
1
|
|
|
1
|
0
|
6
|
my ($self, $method, $params, $headers) = @_; |
85
|
1
|
|
|
|
|
2
|
$self->_make_request($method, $params, $headers); |
86
|
1
|
|
|
|
|
7
|
my $mock = Plack::Test::MockHTTP->new($self->{app}); |
87
|
1
|
|
|
|
|
6
|
my $res = $mock->request($self); |
88
|
1
|
|
|
|
|
1060
|
return $res; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub post_not_ok { |
92
|
2
|
|
|
2
|
0
|
206
|
my ($self, $method, $params, $headers) = @_; |
93
|
2
|
|
50
|
|
|
5
|
$params ||= {}; |
94
|
2
|
|
|
|
|
4
|
my $args = $self->validator->validate(%$params); |
95
|
|
|
|
|
|
|
|
96
|
2
|
50
|
|
|
|
140
|
my $ok = 1 if $self->validator->has_errors; |
97
|
2
|
|
|
|
|
4
|
$self->validator->clear_errors(); |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
5
|
$self->_make_request($method, $params, $headers); |
100
|
|
|
|
|
|
|
|
101
|
2
|
|
|
|
|
10
|
my $mock = Plack::Test::MockHTTP->new($self->{app}); |
102
|
2
|
|
|
|
|
12
|
my $res = $mock->request($self); |
103
|
2
|
50
|
|
|
|
628
|
$ok = 1 if $res->code == 200; |
104
|
2
|
|
|
|
|
21
|
my $Test = Test::Builder->new(); |
105
|
2
|
|
|
|
|
10
|
$Test->ok($ok); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _make_request { |
109
|
8
|
|
|
8
|
|
69
|
my ($self, $method, $params, $headers) = @_; |
110
|
|
|
|
|
|
|
my $json = to_json( |
111
|
|
|
|
|
|
|
{ |
112
|
|
|
|
|
|
|
jsonrpc => '2.0', |
113
|
|
|
|
|
|
|
id => $self->{id}, |
114
|
8
|
|
|
|
|
39
|
method => $method, |
115
|
|
|
|
|
|
|
params => $params, |
116
|
|
|
|
|
|
|
}, { pretty => 1, utf8 => 1 } |
117
|
|
|
|
|
|
|
); |
118
|
8
|
|
|
|
|
271
|
$self->header('Content-Type' => 'application/json'); |
119
|
8
|
|
|
|
|
342
|
$self->header('Content-Length' => length $json); |
120
|
8
|
100
|
66
|
|
|
206
|
if($headers && ref $headers eq 'ARRAY') { |
121
|
1
|
|
|
|
|
2
|
for my $header (@$headers) { |
122
|
1
|
|
|
|
|
3
|
$self->header(@$header); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
8
|
|
|
|
|
57
|
$self->content($json); |
126
|
8
|
|
|
|
|
93
|
return $json; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
13
|
|
|
13
|
1
|
8281
|
sub method { shift->{method} } |
130
|
17
|
|
|
17
|
0
|
65
|
sub rule { shift->{rule} } |
131
|
4
|
|
|
4
|
0
|
11
|
sub label { shift->{label} } |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub response { |
134
|
13
|
|
|
13
|
0
|
67244
|
my $self = shift; |
135
|
13
|
100
|
|
|
|
45
|
return $self->{response} if $self->{response}; |
136
|
2
|
|
|
|
|
13
|
return; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |