line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::RestAPI::MojoGenerator; |
2
|
9
|
|
|
9
|
|
31
|
use Moo; |
|
9
|
|
|
|
|
8
|
|
|
9
|
|
|
|
|
46
|
|
3
|
|
|
|
|
|
|
|
4
|
9
|
|
|
9
|
|
5534
|
use Mojo::Template; |
|
9
|
|
|
|
|
62975
|
|
|
9
|
|
|
|
|
48
|
|
5
|
9
|
|
|
9
|
|
6211
|
use Path::Tiny; |
|
9
|
|
|
|
|
69962
|
|
|
9
|
|
|
|
|
994
|
|
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
|
14
|
my ($self, $endpoints) = @_; |
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
|
|
36
|
my $app_path = Path::Tiny->tempfile(); |
46
|
|
|
|
|
|
|
|
47
|
8
|
|
|
|
|
3226
|
$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
|
|
|
|
|
3728
|
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; |