line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nephia::Plugin::JSON; |
2
|
3
|
|
|
3
|
|
14372
|
use 5.008005; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
199
|
|
3
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
90
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
85
|
|
5
|
3
|
|
|
3
|
|
920
|
use parent 'Nephia::Plugin'; |
|
3
|
|
|
|
|
336
|
|
|
3
|
|
|
|
|
20
|
|
6
|
3
|
|
|
3
|
|
1587
|
use JSON (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
48
|
|
7
|
3
|
|
|
3
|
|
1060
|
use Nephia::Response; |
|
3
|
|
|
|
|
23357
|
|
|
3
|
|
|
|
|
1292
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
0
|
39
|
my ($class, %opts) = @_; |
13
|
2
|
|
|
|
|
20
|
my $self = $class->SUPER::new(%opts); |
14
|
2
|
|
|
|
|
129
|
my $app = $self->app; |
15
|
2
|
|
|
|
|
56
|
$app->{json_obj} = JSON->new->utf8; |
16
|
2
|
|
|
|
|
9
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
1
|
75018
|
sub exports { qw/json_res encode_json decode_json/ } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub json_res { |
22
|
4
|
|
|
4
|
1
|
28
|
my ($self, $context) = @_; |
23
|
|
|
|
|
|
|
return sub ($) { |
24
|
2
|
|
|
2
|
|
179
|
my $content_body = $_[0]; |
25
|
2
|
|
|
|
|
9
|
my $headers = [ |
26
|
|
|
|
|
|
|
'Content-Type' => 'application/json; charset=UTF-8', |
27
|
|
|
|
|
|
|
'X-Content-Type-Options' => 'nosniff', ### For IE 9 or later. See http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-1297 |
28
|
|
|
|
|
|
|
'X-Frame-Options' => 'DENY', ### Suppress loading web-page into iframe. See http://blog.mozilla.org/security/2010/09/08/x-frame-options/ |
29
|
|
|
|
|
|
|
'Cache-Control' => 'private', ### no public cache |
30
|
|
|
|
|
|
|
]; |
31
|
2
|
100
|
|
|
|
12
|
if ($self->{enable_api_status_header}) { |
32
|
1
|
|
50
|
|
|
9
|
$content_body->{status} ||= 200; |
33
|
1
|
|
|
|
|
4
|
push @$headers, ('X-API-Status', $content_body->{status}); |
34
|
|
|
|
|
|
|
} |
35
|
2
|
|
|
|
|
15
|
$context->set(res => Nephia::Response->new( |
36
|
|
|
|
|
|
|
200, $headers, |
37
|
|
|
|
|
|
|
$self->app->{json_obj}->encode($content_body) |
38
|
|
|
|
|
|
|
)); |
39
|
4
|
|
|
|
|
28
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub encode_json { |
43
|
4
|
|
|
4
|
1
|
29
|
my ($self, $context) = @_; |
44
|
4
|
|
|
0
|
|
20
|
return sub ($) {$self->app->{json_obj}->encode($_[0])}; |
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub decode_json { |
48
|
4
|
|
|
4
|
1
|
28
|
my ($self, $context) = @_; |
49
|
4
|
|
|
1
|
|
23
|
return sub ($) {$self->app->{json_obj}->decode($_[0])}; |
|
1
|
|
|
|
|
1535
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |