line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::JSON::_PerRequest; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use HTTP::Status; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
398
|
|
4
|
1
|
|
|
1
|
|
6
|
use Scalar::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
966
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub data { |
7
|
33
|
|
|
33
|
0
|
2111
|
my ($self, $data) = @_; |
8
|
33
|
100
|
|
|
|
74
|
if($data) { |
9
|
4
|
50
|
|
|
|
17
|
if($self->{data}) { |
10
|
0
|
|
|
|
|
0
|
die "Can't set view data attribute if its already set"; |
11
|
|
|
|
|
|
|
} else { |
12
|
4
|
100
|
|
|
|
25
|
$data = $self->{ctx}->model($data) unless ref $data; |
13
|
|
|
|
|
|
|
#die "Model $data does not do a required method 'TO_JSON'" |
14
|
|
|
|
|
|
|
# unless $data->can('TO_JSON'); |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
|
|
1711
|
return $self->{data} = $data; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} else { |
19
|
29
|
|
66
|
|
|
310
|
return $self->{data} ||= do { |
20
|
4
|
|
|
|
|
29
|
my $default_view_model = $self->{parent}->default_view_model; |
21
|
4
|
50
|
|
|
|
51
|
$default_view_model = $self->{ctx}->model($default_view_model) |
22
|
|
|
|
|
|
|
unless ref $default_view_model; |
23
|
4
|
|
|
|
|
3843
|
$default_view_model; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub handle_encode_error { |
29
|
3
|
|
|
3
|
0
|
60
|
my ($self, $value) = @_; |
30
|
3
|
100
|
|
|
|
11
|
if(defined $value) { |
31
|
1
|
|
|
|
|
5
|
$self->{handle_encode_error} = $value; |
32
|
|
|
|
|
|
|
} |
33
|
3
|
|
|
|
|
15
|
return $self->{handle_encode_error}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub callback_param { |
37
|
0
|
|
|
0
|
0
|
0
|
my ($self, $value) = @_; |
38
|
0
|
0
|
|
|
|
0
|
if(defined $value) { |
39
|
0
|
|
|
|
|
0
|
$self->{callback_param} = $value; |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
0
|
return $self->{callback_param}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
0
|
0
|
sub res { return shift->response(@_) } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub response { |
47
|
8
|
|
|
8
|
0
|
21
|
my ($self, @proto) = @_; |
48
|
8
|
|
|
|
|
17
|
my ($status, @headers) = (); |
49
|
|
|
|
|
|
|
|
50
|
8
|
50
|
|
|
|
26
|
if(ref \$proto[0] eq 'SCALAR') { |
51
|
8
|
|
|
|
|
20
|
$status = shift @proto; |
52
|
|
|
|
|
|
|
} else { |
53
|
0
|
|
|
|
|
0
|
$status = 200; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
8
|
100
|
66
|
|
|
78
|
if( |
57
|
|
|
|
|
|
|
scalar(@proto) && |
58
|
|
|
|
|
|
|
ref $proto[$#proto] eq 'HASH' |
59
|
|
|
|
|
|
|
) { |
60
|
5
|
|
|
|
|
29
|
my $var = pop @proto; |
61
|
5
|
|
|
|
|
21
|
foreach my $key (keys %$var) { |
62
|
9
|
|
|
|
|
11106
|
$self->data->$key($var->{$key}); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
8
|
100
|
66
|
|
|
395
|
if( |
67
|
|
|
|
|
|
|
scalar(@proto) && |
68
|
|
|
|
|
|
|
Scalar::Util::blessed($proto[$#proto]) |
69
|
|
|
|
|
|
|
) { |
70
|
3
|
|
|
|
|
7
|
my $obj = pop @proto; |
71
|
3
|
|
|
|
|
14
|
$self->data($obj); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
8
|
50
|
|
|
|
28
|
if(@proto) { |
75
|
0
|
|
|
|
|
0
|
@headers = @{$proto[0]}; |
|
0
|
|
|
|
|
0
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$self->{ctx}->stats->profile(begin => "=> JSON->send". ($status ? "($status)": '')) |
79
|
8
|
0
|
|
|
|
40
|
if $self->{ctx}->debug; |
|
|
50
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
8
|
|
|
|
|
324
|
my $res = $self->{ctx}->response; |
82
|
8
|
|
|
|
|
69
|
my $json = $self->render($self->data); |
83
|
|
|
|
|
|
|
|
84
|
6
|
50
|
|
|
|
21
|
$res->headers->push_headers(@headers) if @headers; |
85
|
6
|
50
|
|
|
|
36
|
$res->status($status) unless $res->status != 200; # Catalyst default is 200... |
86
|
6
|
50
|
|
|
|
1520
|
$res->content_type('application/json') unless $res->content_type; |
87
|
|
|
|
|
|
|
|
88
|
6
|
50
|
|
|
|
2966
|
if(my $param = $self->{callback_param}) { |
89
|
0
|
|
|
|
|
0
|
my $cb = $c->req->query_parameter($cbparam); |
90
|
0
|
0
|
|
|
|
0
|
$cb =~ /^[a-zA-Z0-9\.\_\[\]]+$/ || die "Invalid callback parameter $cb"; |
91
|
0
|
|
|
|
|
0
|
$json = "$cb($json)"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
6
|
50
|
|
|
|
26
|
$res->body($json) unless $res->has_body; |
95
|
6
|
50
|
|
|
|
552
|
return $self->{ctx}->detach if $self->{auto_detach}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub render { |
99
|
8
|
|
|
8
|
0
|
20
|
my ($self, $data) = @_; |
100
|
|
|
|
|
|
|
my $json = eval { |
101
|
|
|
|
|
|
|
$self->{json}->encode($self->data); |
102
|
8
|
|
66
|
|
|
14
|
} || do { |
103
|
|
|
|
|
|
|
if(my $cb = $self->handle_encode_error) { |
104
|
|
|
|
|
|
|
delete $self->{data}; # Clear out any existing data since its not valid |
105
|
|
|
|
|
|
|
return $cb->($self, $@); |
106
|
|
|
|
|
|
|
} else { |
107
|
|
|
|
|
|
|
# Bubble up the unhandled error |
108
|
|
|
|
|
|
|
die $@; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
}; |
111
|
6
|
|
|
|
|
402
|
return $json; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub process { |
115
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $c ) = @_; |
116
|
0
|
|
|
|
|
0
|
$self->send; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Send Helpers. |
120
|
|
|
|
|
|
|
foreach my $helper( grep { $_=~/^http/i} @HTTP::Status::EXPORT_OK) { |
121
|
|
|
|
|
|
|
my $subname = lc $helper; |
122
|
|
|
|
|
|
|
$subname =~s/http_//i; |
123
|
0
|
|
|
0
|
0
|
0
|
eval "sub $subname { return shift->response(HTTP::Status::$helper,\@_) }"; |
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
1
|
|
|
1
|
0
|
1007
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
0
|
0
|
|
|
0
|
|
|
0
|
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No user servicable bits |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 DESCRIPTION |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
See L<Catalyst::View::JSON::PerRequest> for details. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SEE ALSO |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::View>, L<Catalyst::View::JSON::PerRequest>, |
144
|
|
|
|
|
|
|
L<HTTP::Status> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
John Napiorkowski L<email:jjnapiork@cpan.org> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Copyright 2015, John Napiorkowski L<email:jjnapiork@cpan.org> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
155
|
|
|
|
|
|
|
the same terms as Perl itself. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |