Looking for particular Mojolicious method

瀏覽次數:30 次
跳到第一則未讀訊息

Pavel Serikov

未讀,
2017年3月13日 上午8:24:222017/3/13
收件者:Mojolicious
Usually I'm releasing my Mojo apps as packages, e.g. App::MojoApp.
Also I'm creating a mojoapp CLI tool (like this) which does Mojolicious::Commands->start_app(App::MojoApp) for easy running app from any place.

Would like to implement a custom command which running my app on hypnotoad production server.
Since Mojo::Server::Hypnotoad can't load application from class, as Mojolicious::Commands::start_app() do, I need to impement finding a path to main mojo app module by myself.

Now it looks like
package App::MojoApp::Command::hypno;

use Mojo::Base 'Mojolicious::Command';
use Mojo::Server::Hypnotoad;

has description
=> 'Run app on hypnotoad production server';
has usage      
=> "Usage: APPLICATION hypno";

sub run {
 
my ($self, @args) = @_;
 
my $p = __PACKAGE__;
 
my @s = split(/::/, $p);
  $p
= join('::', $s[0], $s[1]);
  $p
=~ s/::/\//g;
  $p
=~ s/$/.pm/;
 
my $hypnotoad = Mojo::Server::Hypnotoad->new;
  $hypnotoad
->run($INC{$p});
}

1;

Is there any way built-in method to get an installation location of main mojo module ?

sri

未讀,
2017年3月13日 上午8:33:212017/3/13
收件者:Mojolicious
Don't do this, if there was a good way to have hypnotoad and morbo commands we would already have hypnotoad and morbo commands.

--
sebastian

Pavel Serikov

未讀,
2017年3月13日 上午8:40:342017/3/13
收件者:Mojolicious
Hi Sebastian,

Thanks for a quick feedback.

Could you please explain more why it's a bad idea to implement hypnotoad and morbo commands ?
And what is the recommendation in my case, do not release mojolicious apps as packages, right ?

понедельник, 13 марта 2017 г., 15:33:21 UTC+3 пользователь sri написал:

Joel Berger

未讀,
2017年3月14日 上午9:41:582017/3/14
收件者:Mojolicious
The problem is that for morbo and hypnotoad their raison-d'etre is process management in one way or the other. They must be started external to your app so that they can control the reloading of it.
If you are trying to release an app, it should never need morbo anyway since that is for development. For deployment, `hypnotoad myapp` works as well as `myapp hypnotoad` would (if that worked), so I don't see much need there. And finally if you really must do a preforking deployment via an app command the 'prefork' command does most of what hypnotoad does, it just can't hot reload.

Cheers,
Joel
回覆所有人
回覆作者
轉寄
0 則新訊息