Demiurg
Demiurg

Reputation: 121

How to run Mojolicious app from command line with params?

I have a Mojolicious application. It runs under Starman very well, but I want to run it from command line with parameters.

Command

./myapp get /

works as well, but

./myapp get /?param=val

does not work as there is not any parameter.

Can you help me?

Upvotes: 1

Views: 943

Answers (1)

Logioniz
Logioniz

Reputation: 891

This is works.

# Automatically enables "strict", "warnings", "utf8" and Perl 5.10 features
use Mojolicious::Lite;

# Route with placeholder
get '/' => sub {
  my $self = shift;
  my $param = $self->param('param') // 'qwerty';

  $self->render(text => "Hello from $param.");
};

# Start the Mojolicious command system
app->start;

Use it something like this:

perl 1.pl get /?param=111

Upvotes: 2

Related Questions