3

I'm trying to figure out if it's possible to give an argument when calling an mojolicious app. This indicates that it's not easily done, at least not five years ago. By looking at the documentation, it looks like there is an option for it (or I'm I reading this wrong?).

Mojolicious::Commands->start_app('MyApp');
Mojolicious::Commands->start_app(MyApp => @ARGV);

If it's indeed possible, how do I access it from the startup function? I've tried some of the most obvious one, like...

sub startup {
    my ($self, $arg) = @_;
    ....

This didn't work.

Orjanp
  • 10,641
  • 12
  • 36
  • 39

1 Answers1

5

Take a look at the source. When you do start_app, it eventually runs $app->start, which passes @ARGV to $self->commands->run. That's another instance of Mojolicious::Commands, which parses the args and figures out what to do with them.

My best guess is you need to implement a Mojolicious::Command, and then you can pass along your args. That could be as simple as setting properties in the app object (which might exist already, not sure).

simbabque
  • 53,749
  • 8
  • 73
  • 136