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