Search code examples
perlmojolicious

Using Mojolicious commands in system CLI


My app, Alambic, uses The Great Mojolicious framework, and defines commands that can be executed with e.g. $ script/alambic alambic init.

Now when I look at Joel Berger's Galileo and other great pieces of work, I find they have a system command that can be directly invoked in a shell, e.g. $ galileo init. I looked into the mojolicious doc but found nothing to do that for my app. Now I'm not even sure if it's Mojolicious or the Perl CPAN Build process that makes it possible.. Any hint would be greatly appreciated.


Solution

  • I'll provide the complete answer here as a complement to @simbabque 's comment.

    So for a Mojolicious application, one has to make it installable (i.e. cpan-aware) in order to have the binaries copied to a directory in the path. More specifically for Alambic I had to:

    1. Setup InstallablePaths (I decided to go for Module::Build), see the documentation for the module
    2. Create a Build.PL file
    3. Run the Module::Build sequence to build the module:

    perl Build.PL
    ./Build manifest
    ./Build
    ./Build test
    ./Build install

    During the install step, binaries are copied to a Perl-managed directory that is in the $PATH. After that step the alambic command was available as a command in my shell.

    Note: For one to have her/his own commands available on the CLI, the Mojolicious application has to define one or more commands of course.