Boldra has asked for the wisdom of the Perl Monks concerning the following question:

I've been looking at MooseX::App documentat trying to understand what exactly is mean by a "command"...

What I'd like to do is create a base class with certain switches and functionality which will be usable across a range of separate scripts, for example:

igner-cli.pl  --db=demo "rm /dev/null"
igner-url.pl  --db=prod --proxy=none http://boldra.com/

This is what I'm trying:

package Igner::App; use MooseX::App; parameter db => ( #all igner apps need a "db" required => 1, ... ); package Igner::App::URL; extends 'Igner::App'; use MooseX::App::Command; # because this script has additional paramet +ers and options paramter proxy => ( # only Igner::App::URL needs a proxy required => 1, ... ); sub run { ... }
Then in the script I expected to be able to write:
#!/usr/bin/perl use Igner::App::URL; Igner::App::URL->new_with_command->run;
And the run sub would be executed if the user provided db and proxy, and the user would get help information if not.

Instead, I'm getting "new_with_command may only be called from the application base package:Igner::App::URL" which doesn't shed any light. As I said at the start - I'm lacking a clear concept of what the modules mean by "command". The MooseX::App::Command documentation could use some examples of how it relates to actually executing commands on the command-line.



- Boldra

Replies are listed 'Best First'.
Re: What's a MooseX Command
by karlgoethebier (Abbot) on Aug 06, 2024 at 10:51 UTC

    App::Cmd::Tutorial

    From ibidem: App::Cmd is a set of tools designed to make it simple to write sophisticated command line programs. It handles commands with multiple subcommands, generates usage text, validates options, and lets you write your program as easy-to-test classes. An App::Cmd-based application is made up of three main parts: the script, the application class, and the command classes.

      Thanks - that would strongly suggest it's not suitable for my use case... "commands" there refer to the first argument after the application name. I'm curious how you got from MooseX::App::Command to App::Cmd?



      - Boldra
Re: What's a MooseX Command
by Danny (Chaplain) on Aug 06, 2024 at 18:44 UTC
    I would probably try calling new_with_command directly in your two packages to see if they are available.