DESCRIPTION

When a command has a set of sub-commands which are meant to be derived from another group of classes, this module lets you auto-generate those sub-commands at run time.

REQUIRED ABSTRACT METHOD

_sub_commands_from

$base_namespace = Acme::Order::Command->_sub_commands_from();
# 'Acme::Task
Returns the namespace from which target classes will be discovered, and
sub-commands will be generated.

PRIVATE API

_target_class_name

$c= Acme::Order::Command::Purchasing->_target_class_name;
# 'Acme::Task::Foo'
The name of some class under the _sub_commands_from() namespace.
This value is set during execute, revealing which sub-command the caller is using.

OPTIONAL OVERRIDES

_build_sub_commmand

This can be overridden to customize the sub-command construction.
By default, each target under _sub_commands_from will result in
a call to this method. The default implementation is below:
my $self = shift;
my ($suggested_class_name,$delegator_class_name,$target_class_name) = @_;
class {$suggested_class_name} {
is => $delegator_class_name,
sub_classify_by => 'class',
has_constant => [
_target_class_name => { value => $target_class_name },
]
};
return ($suggested_class_name);
Note that the class in question may be on the filesystem, and not need
to be created. The return list can include more than one class name,
or zero class names.

_build_all_sub_commands

This is called once for any class which inherits from Command::DynamicSubCommands.
It generates the sub-commands as needed, and returns a list.
By default it resolves the target classes, and calls _build_sub_command
It can be overridden to customize behavior, or filter results. Be sure
to call @cmds = $self->SUPER::_build_all_sub_commands() if you want
to get the default commands in addition to overriding.

The sub-commands need not be 1:1 with the target classes, though this is the default.

The sub-commands need not inherit from the Command::DynamicSubCommands base command which generates them, though this is the default.

Module Install Instructions

To install Command::DynamicSubCommands, simply copy and paste either of the commands in to your terminal