Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an argument to a mojolicious app

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.

like image 385
Orjanp Avatar asked Dec 14 '25 18:12

Orjanp


1 Answers

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).

like image 161
simbabque Avatar answered Dec 16 '25 21:12

simbabque