|
I can use subcommand_alias() to give a subcommand whatever alias I choose.
The name of the subcommand has to match the name of the class that inherits from My::Queue::Command::Property
I am not looking for a way to name a command anything I want. I am looking to understand how the subcommand dispatching works.
Let me try and give a concrete example using examples/queue:
first, I delete the subcommand_alias() method from My::Queue::Command::Property
next, I create a class called My::Queue::Command::Property::Gist that inherits from My::Queue::Command::Property (it's run() method just returns "GOT HERE!\n")
Right now, without me defining any subcommand dispatch table, I have a subcommand on the commandline called 'gist'. It must be called 'gist'
$ examples/queue property gist
My::Queue::Command::Property::notify...() about to run My::Queue::Command::Property::Gist
GOT HERE!
$ examples/queue property Gist
property: work with queue properties
ARGUMENTS (subcommands)
list: list queue properties
set: set queue properties
gist: the gist of it
If I change the class name to My::Queue::Command::Property::gist
it still works with the 'gist' sub-command.
So, my question are, how does the subcommand dispatching work?
How does CLI know that 'gist' maps to 'My::Queue::Command::Property::[Gg]ist'?
What if I create 2 subcommands classes that inherit from My::Queue::Command::Property:
My::Queue::Command::Property::Gist
My::OtherModule:Property::Gist
Which one gets mapped to the 'gist' subcommand?
What is becoming obvious, if I want to have a subcommand of 'property' called 'gist' (without subcommand aliases), I must have a subcommand class named Gg]ist that inherits from My::Queue::Command::Property.
If I want to use an existing class named 'MyGist' for the 'gist' subcommand, I would need to make it inherit from the property class, and use 'gist' as the subcommand alias on the command line:
sub subcommand_alias {
'gist' => 'mygist',
}
$ examples/queue property gist
My::Queue::Command::Property::notify...() about to run My::Queue::Command::Property::MyGist
GOT HERE!
$ examples/queue property mygist
My::Queue::Command::Property::notify...() about to run My::Queue::Command::Property::MyGist
GOT HERE!
Is this correct?
|