line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::PromiseActions; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1208
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
360
|
use Scalar::Util 'blessed'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
490
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
2
|
|
|
2
|
1
|
71
|
my ($elf, $app, $config) = @_; |
11
|
|
|
|
|
|
|
$app->hook( |
12
|
|
|
|
|
|
|
around_action => sub { |
13
|
3
|
|
|
3
|
|
135944
|
my ($next, $c) = @_; |
14
|
3
|
|
|
|
|
11
|
my $res = $next->(); |
15
|
3
|
100
|
66
|
|
|
657
|
if (blessed($res) && $res->can('then')) { |
16
|
2
|
|
|
|
|
10
|
my $tx = $c->render_later; |
17
|
2
|
50
|
|
|
|
50
|
$res->then(undef, sub { $c->reply->exception(pop) and undef $tx }); |
|
1
|
|
|
|
|
100983
|
|
18
|
|
|
|
|
|
|
} |
19
|
3
|
|
|
|
|
85
|
return $res; |
20
|
|
|
|
|
|
|
} |
21
|
2
|
|
|
|
|
18
|
); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
1; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Mojolicious::Plugin::PromiseActions - Automatic async and error handling for Promises |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
plugin 'PromiseActions'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
get '/' => sub { |
35
|
|
|
|
|
|
|
my $c=shift; |
36
|
|
|
|
|
|
|
app->ua->get_p('ifconfig.me/all.json')->then(sub { |
37
|
|
|
|
|
|
|
$c->render(text=>shift->res->json('/ip_addr')); |
38
|
|
|
|
|
|
|
}); |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 register |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Sets up a around_dispatch hook to disable automatic rendering and |
46
|
|
|
|
|
|
|
add a default catch callback to render an exception page when |
47
|
|
|
|
|
|
|
actions return a L |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Copyright (C) 2018, Marcus Ramberg. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
54
|
|
|
|
|
|
|
the terms of the Artistic License version 2.0. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SEE ALSO |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
L, L, |
59
|
|
|
|
|
|
|
L, L |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |