| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package RESTApp; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use feature 'say'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
64
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use FindBin '$Bin'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
97
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use lib ("$Bin/../lib", "$Bin/../../../lib"); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
551
|
use Raisin::API; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
6
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
plugin 'Swagger'; |
|
14
|
|
|
|
|
|
|
middleware 'CrossOrigin', |
|
15
|
|
|
|
|
|
|
origins => '*', |
|
16
|
|
|
|
|
|
|
methods => [qw/DELETE GET HEAD OPTIONS PATCH POST PUT/], |
|
17
|
|
|
|
|
|
|
headers => [qw/accept authorization content-type api_key_token/]; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
plugin 'Logger', outputs => [['Screen', min_level => 'debug']]; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
app->log(debug => 'Loading Raisin...'); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
swagger_setup( |
|
24
|
|
|
|
|
|
|
title => 'Users & hosts API', |
|
25
|
|
|
|
|
|
|
description => 'An example of API documentation.', |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
contact => { |
|
28
|
|
|
|
|
|
|
name => 'Artur Khabibullin', |
|
29
|
|
|
|
|
|
|
url => 'http://github.com/khrt', |
|
30
|
|
|
|
|
|
|
email => 'rtkh@cpan.org', |
|
31
|
|
|
|
|
|
|
}, |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
license => { |
|
34
|
|
|
|
|
|
|
name => 'Perl license', |
|
35
|
|
|
|
|
|
|
url => 'http://dev.perl.org/licenses/', |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#before sub { |
|
40
|
|
|
|
|
|
|
# my $self = shift; |
|
41
|
|
|
|
|
|
|
# say 'Before ' . $self->req->method . q{ } . $self->req->path; |
|
42
|
|
|
|
|
|
|
#}; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
mount 'RESTApp::Host'; |
|
45
|
|
|
|
|
|
|
mount 'RESTApp::User'; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Utils |
|
48
|
|
|
|
|
|
|
sub paginate { |
|
49
|
4
|
|
|
4
|
0
|
9
|
my ($data, $params) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
7
|
my $max_count = scalar(@$data) - 1; |
|
52
|
4
|
|
|
|
|
9
|
my $start = _return_max($params->{start}, $max_count); |
|
53
|
4
|
|
|
|
|
20
|
my $count = _return_max($params->{count}, $max_count); |
|
54
|
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
13
|
my @slice = @$data[$start .. $count]; |
|
56
|
4
|
|
|
|
|
14
|
\@slice; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _return_max { |
|
60
|
8
|
|
|
8
|
|
16
|
my ($value, $max) = @_; |
|
61
|
8
|
100
|
|
|
|
17
|
$value > $max ? $max : $value; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |