line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::JSONP; |
2
|
2
|
|
|
2
|
|
1392
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
10
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub register { |
7
|
2
|
|
|
2
|
1
|
70
|
my ($self, $app, $conf) = @_; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$app->helper( |
10
|
|
|
|
|
|
|
render_jsonp => sub { |
11
|
4
|
|
|
4
|
|
106197
|
my ($self, $callback, $ref) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# $callback is optional |
14
|
4
|
100
|
|
|
|
24
|
$ref = $callback, undef $callback if !defined $ref; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# use default from plugin conf if callback not specified |
17
|
|
|
|
|
|
|
#$callback //= $self->param($conf->{callback}); |
18
|
4
|
100
|
|
|
|
28
|
$callback = $self->param($conf->{callback}) if !$callback; |
19
|
|
|
|
|
|
|
|
20
|
4
|
|
33
|
|
|
2041
|
my $method = $self->can('render_to_string') || $self->can('render'); |
21
|
|
|
|
|
|
|
|
22
|
4
|
100
|
|
|
|
33
|
return $callback |
23
|
|
|
|
|
|
|
? $self->render(text => $callback . '(' |
24
|
|
|
|
|
|
|
. $self->$method(json => $ref, partial => 1) . ')') |
25
|
|
|
|
|
|
|
: $self->render(json => $ref); |
26
|
|
|
|
|
|
|
} |
27
|
2
|
|
|
|
|
25
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
__END__ |