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
|
|
|
|
|
412
|
|
4
|
1
|
|
|
1
|
|
5
|
use Scalar::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
751
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub data { |
7
|
21
|
|
|
21
|
0
|
1895
|
my ($self, $data) = @_; |
8
|
21
|
100
|
|
|
|
44
|
if($data) { |
9
|
2
|
50
|
|
|
|
8
|
if($self->{data}) { |
10
|
0
|
|
|
|
|
0
|
die "Can't set view data attribute if its already set"; |
11
|
|
|
|
|
|
|
} else { |
12
|
2
|
100
|
|
|
|
19
|
$data = $self->{ctx}->model($data) unless ref $data; |
13
|
2
|
50
|
|
|
|
1423
|
die "Model $data does not do a required method 'TO_JSON'" |
14
|
|
|
|
|
|
|
unless $data->can('TO_JSON'); |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
|
|
8
|
return $self->{data} = $data; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} else { |
19
|
19
|
|
66
|
|
|
222
|
return $self->{data} ||= do { |
20
|
2
|
|
|
|
|
15
|
my $default_view_model = $self->{parent}->default_view_model; |
21
|
2
|
50
|
|
|
|
30
|
$default_view_model = $self->{ctx}->model($default_view_model) |
22
|
|
|
|
|
|
|
unless ref $default_view_model; |
23
|
2
|
|
|
|
|
1859
|
$default_view_model; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub callback_param { |
29
|
0
|
|
|
0
|
0
|
0
|
my ($self, $value) = @_; |
30
|
0
|
|
|
|
|
0
|
$self->{callback_param} = $value; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
0
|
0
|
sub res { return shift->response(@_) } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub response { |
36
|
4
|
|
|
4
|
0
|
12
|
my ($self, @proto) = @_; |
37
|
4
|
|
|
|
|
9
|
my ($status, @headers) = (); |
38
|
|
|
|
|
|
|
|
39
|
4
|
50
|
|
|
|
17
|
if(ref \$proto[0] eq 'SCALAR') { |
40
|
4
|
|
|
|
|
7
|
$status = shift @proto; |
41
|
|
|
|
|
|
|
} else { |
42
|
0
|
|
|
|
|
0
|
$status = 200; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
4
|
100
|
66
|
|
|
35
|
if( |
46
|
|
|
|
|
|
|
scalar(@proto) && |
47
|
|
|
|
|
|
|
ref $proto[$#proto] eq 'HASH' |
48
|
|
|
|
|
|
|
) { |
49
|
3
|
|
|
|
|
6
|
my $var = pop @proto; |
50
|
3
|
|
|
|
|
40
|
foreach my $key (keys %$var) { |
51
|
7
|
|
|
|
|
25867
|
$self->data->$key($var->{$key}); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
4
|
100
|
66
|
|
|
158
|
if( |
56
|
|
|
|
|
|
|
scalar(@proto) && |
57
|
|
|
|
|
|
|
Scalar::Util::blessed($proto[$#proto]) |
58
|
|
|
|
|
|
|
) { |
59
|
1
|
|
|
|
|
2
|
my $obj = pop @proto; |
60
|
1
|
|
|
|
|
7
|
$self->data($obj); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
4
|
50
|
|
|
|
19
|
if(@proto) { |
64
|
0
|
|
|
|
|
0
|
@headers = @{$proto[0]}; |
|
0
|
|
|
|
|
0
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$self->{ctx}->stats->profile(begin => "=> JSON->send". ($status ? "($status)": '')) |
68
|
4
|
0
|
|
|
|
22
|
if $self->{ctx}->debug; |
|
|
50
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
4
|
|
|
|
|
136
|
my $res = $self->{ctx}->response; |
71
|
|
|
|
|
|
|
|
72
|
4
|
50
|
|
|
|
41
|
$res->headers->push_headers(@headers) if @headers; |
73
|
4
|
50
|
|
|
|
28
|
$res->status($status) unless $res->status != 200; # Catalyst default is 200... |
74
|
4
|
50
|
|
|
|
998
|
$res->content_type('application/json') unless $res->content_type; |
75
|
|
|
|
|
|
|
|
76
|
4
|
|
|
|
|
2000
|
my $json = $self->render($self->data); |
77
|
|
|
|
|
|
|
|
78
|
4
|
50
|
|
|
|
399
|
if(my $param = $self->{callback_param}) { |
79
|
0
|
|
|
|
|
0
|
my $cb = $c->req->query_parameter($cbparam); |
80
|
0
|
0
|
|
|
|
0
|
$cb =~ /^[a-zA-Z0-9\.\_\[\]]+$/ || die "Invalid callback parameter $cb"; |
81
|
0
|
|
|
|
|
0
|
$json = "$cb($json)"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
4
|
50
|
|
|
|
18
|
$res->body($json) unless $res->has_body; |
85
|
4
|
50
|
|
|
|
302
|
return $self->{ctx}->detach if $self->{auto_detach}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub render { |
89
|
4
|
|
|
4
|
0
|
7
|
my ($self, $data) = @_; |
90
|
4
|
|
|
|
|
13
|
return $self->{json}->encode($self->data); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub process { |
94
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $c ) = @_; |
95
|
0
|
|
|
|
|
0
|
$self->send; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Send Helpers. |
99
|
|
|
|
|
|
|
foreach my $helper( grep { $_=~/^http/i} @HT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ON views that own data |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SYNOPSIS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
No user servicable bits |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 DESCRIPTION |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
See L<Catalyst::View::JSON::PerRequest> for details. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 SEE ALSO |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::View>, L<Catalyst::View::JSON::PerRequest>, |
123
|
|
|
|
|
|
|
L<HTTP::Status> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
John Napiorkowski L<email:jjnapiork@cpan.org> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Copyright 2015, John Napiorkowski L<email:jjnapiork@cpan.org> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
134
|
|
|
|
|
|
|
the same terms as Perl itself. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |