line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::RestAPI::MojoGenerator; |
2
|
9
|
|
|
9
|
|
44
|
use Moo; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
53
|
|
3
|
|
|
|
|
|
|
|
4
|
9
|
|
|
9
|
|
9360
|
use Mojo::Template; |
|
9
|
|
|
|
|
92778
|
|
|
9
|
|
|
|
|
67
|
|
5
|
9
|
|
|
9
|
|
8497
|
use Path::Tiny; |
|
9
|
|
|
|
|
103584
|
|
|
9
|
|
|
|
|
1519
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Test::RestAPI::MojoGenerator - class for generate Mojo app |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $gen = Test::RestAPI::MojoGenerator->new(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $app_path = $gen->create_app([ |
16
|
|
|
|
|
|
|
Test::RestAPI::Endpoint->new(...) |
17
|
|
|
|
|
|
|
]); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This class generate mojo application. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Mojo application have /app_mojo_healtcheck endpoint which return text 'OK everytime. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Each endpoint append request body to file. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 new(%attribute) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head3 %attribute |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 create_app($endpoints) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
list (ArrayRef) of L |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
create mojo app with C<$endpoints> and return temp file with application |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
sub create_app { |
43
|
8
|
|
|
8
|
1
|
20
|
my ($self, $endpoints) = @_; |
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
|
|
54
|
my $app_path = Path::Tiny->tempfile(); |
46
|
|
|
|
|
|
|
|
47
|
8
|
|
|
|
|
4858
|
$app_path->spew(Mojo::Template->new->render(<<'EOF', $endpoints)); |
48
|
|
|
|
|
|
|
% my ($endpoints) = @_; |
49
|
|
|
|
|
|
|
use Mojolicious::Lite; |
50
|
|
|
|
|
|
|
use Path::Tiny; |
51
|
|
|
|
|
|
|
use Mojo::JSON qw(encode_json); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
% foreach my $endpoint (@$endpoints) { |
54
|
|
|
|
|
|
|
<%= $endpoint->method %> '<%= $endpoint->path %>' => sub { |
55
|
|
|
|
|
|
|
my ($c) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
path(app->home(), "<%= $endpoint->path_as_filename %>")->append(encode_json($c->req->body)."\n"); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$c->render(%{<%= $endpoint->render_as_string %>}); |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
% } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
any '/app_mojo_healtcheck' => sub { |
64
|
|
|
|
|
|
|
my ($c) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$c->render(text => 'OK'); |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
app->start(); |
70
|
|
|
|
|
|
|
EOF |
71
|
|
|
|
|
|
|
|
72
|
8
|
|
|
|
|
6760
|
return $app_path; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 LICENSE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Copyright (C) Avast Software. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
80
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Jan Seidl Eseidl@avast.comE |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |