App::Dochazka::CLI::Parser - Parser module
generate_semantic_tree
Populate the $semantic_tree package variable.
$semantic_tree
lookup_command
parse
Parse the command string entered by the user.
possible_words
Given a state expressed as a stack of tokens, return list of possible tokens.
process_command
Given a command string, process it (by parsing, calling the handler, etc.) and return the result.
The semantic tree is a traversable tree representation of the CLI commands, i.e. the keys of the dispatch map $App::Dochazka::CLI::CommandMap::dispatch_map
$App::Dochazka::CLI::CommandMap::dispatch_map
Generate the semantic context tree.
The set of keys of %$dispatch_map contains all the possible commands, each expressed as a sequence of tokens. The semantic context tree is generated from the dispatch map keys. Each node of the tree represents a possible token and the set of nodes at depth n of the tree is the set of possible tokens in the nth position within the command.
%$dispatch_map
Taking, for example, a dispatch map consisting of the following two commands:
ABE BABEL CAROL DALE EARL JENSEN PARLOR DALE TWIT
The semantic tree would be:
(root) | +-----------+ | | ABE DALE | | | +------+ | | | BABEL EARL TWIT | | CAROL JENSEN | PARLOR
The point of this exercise is to facilitate command completion. If two a single token ABE has been entered by the user and <TAB> is pressed, finding out that BABEL is the only possible command in this position is a simple matter of traversing the above semantic tree. (And this is exactly what is done by the possible_words routine in App::Dochazka::CLI::Parser.)
This routine takes an optional argument which, if provided, is assumed to be a reference to a dispatch map. In the absence of this argument, the $dispatch_map package variable (initialized above) is used.
$dispatch_map
For this and more examples, see t/parser/semantic_tree.t.
t/parser/semantic_tree.t
Given a normalized command string such as "GET BUGREPORT", look it up in the dispatch map and return the corresponding coderef, or nothing if the lookup fails.
Parse command string entered by the user. Takes the command string, and returns:
$nc
The normalized command - suitable for lookup via look_up_command
look_up_command
$ts
The token stack - a reference to the list of normalized tokens
$th
The token hash - a hash where the keys are the normalized tokens and the values are the raw values extracted from the command string. Whatever is left after command string parsing completes will be placed in the '_REMAINDER' key.
Given a token stack, return the list of possible tokens.
Given a command entered by the user, process it and return the result.
To install App::Dochazka::CLI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Dochazka::CLI
CPAN shell
perl -MCPAN -e shell install App::Dochazka::CLI
For more information on module installation, please visit the detailed CPAN module installation guide.