Skip to content

Commit

Permalink
added -V option to eval command
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 25, 2013
1 parent 81c022b commit 3468c4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@
4.27 2013-08-25
- Added acceptors acceptors to Mojo::Server::Daemon.
- Added handle method to Mojo::IOLoop::Server.
- Added -V option to eval command.
- Added reuse option to Mojo::IOLoop::Server::listen.
- Added reuse parameter to Mojo::Server::Daemon::listen.
- Fixed console message bug in Mojo::Server::Daemon.
Expand Down
8 changes: 5 additions & 3 deletions lib/Mojolicious/Command/eval.pm
Expand Up @@ -9,23 +9,25 @@ usage: $0 eval [OPTIONS] CODE
mojo eval 'say app->ua->get("/")->res->body'
mojo eval -v 'app->home'
mojo eval -V 'app->renderer->paths'
These options are available:
-v, --verbose Print return value to STDOUT.
-V Print returned data structure to STDOUT.
EOF

sub run {
my ($self, @args) = @_;

GetOptionsFromArray \@args, 'v|verbose' => \my $verbose;
GetOptionsFromArray \@args, 'v|verbose' => \my $v1, 'V' => \my $v2;
my $code = shift @args || '';

# Run code against application
my $app = $self->app;
no warnings;
my $result = eval "package main; sub app { \$app }; $code";
say $result if $verbose && defined $result;
return $@ ? die $@ : $result;
return $@ ? die $@ : $result unless defined $result && ($v1 || $v2);
$v2 ? print($app->dumper($result)) : say $result;
}

1;
Expand Down

0 comments on commit 3468c4b

Please sign in to comment.