Looking for particular Mojolicious method

30 views
Skip to first unread message

Pavel Serikov

unread,
Mar 13, 2017, 8:24:22 AM3/13/17
to 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

unread,
Mar 13, 2017, 8:33:21 AM3/13/17
to 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

unread,
Mar 13, 2017, 8:40:34 AM3/13/17
to 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

unread,
Mar 14, 2017, 9:41:58 AM3/14/17
to 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
Reply all
Reply to author
Forward
0 new messages