Skip to content

Commit

Permalink
allow an arbitrary then-able
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Dec 30, 2018
1 parent b5dda5a commit b67fb23
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Mojolicious/Command/eval.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Mojolicious::Command::eval;
use Mojo::Base 'Mojolicious::Command';

use Mojo::Promise;
use Mojo::Util 'getopt';
use Scalar::Util 'blessed';

Expand All @@ -18,9 +19,10 @@ sub run {
no warnings;
my $result = eval "package main; sub app; local *app = sub { \$app }; $code";
die $@ if $@;
if (blessed $result && $result->isa('Mojo::Promise')) {
if (blessed $result && $result->can('then')) {
my $err;
$result->then(sub { $result = shift }, sub { $err = shift })->wait;
Mojo::Promise->resolve($result)
->then(sub { $result = shift }, sub { $err = shift })->wait;
die $err if $err;
}
return $result unless defined $result && ($v1 || $v2);
Expand Down Expand Up @@ -56,7 +58,7 @@ Mojolicious::Command::eval - Eval command
=head1 DESCRIPTION
L<Mojolicious::Command::eval> runs code against applications. If the result is
a L<Mojo::Promise>, it will wait until the promise is fulfilled or rejected and
a promise (then-able), it will wait until the promise is fulfilled or rejected and
the result is returned.
This is a core command, that means it is always enabled and its code a good
Expand Down

0 comments on commit b67fb23

Please sign in to comment.