Debian Codegraph @

README

raw
1 NAME
2
3 Commandable - utilities for commandline-based programs
4
5 DESCRIPTION
6
7 This distribution contains a collection of utilities extracted from
8 various commandline-based programs I have written, in the hope of
9 trying to find a standard base to build these from in future.
10
11 Note that "commandline" does not necessarily mean "plain-text running
12 in a terminal"; simply that the mode of operation is that the user
13 types a textual representation of some action, and the program parses
14 this text in order to perform it. This could equally apply to a command
15 input text area in a GUI program.
16
17 PROGRAM STRUCTURE
18
19 A typical program using this distribution would have a single instance
20 of a "finder", whose job is to work out the set of commands offered by
21 the program. Various subclasses of finder are provided that use
22 different techniques to locate the individual commands, depending on
23 the structure provided by the program.
24
25 * Commandable::Finder::SubAttributes - expects to find each command
26 implemented as a subroutine within a single package. These
27 subroutines should all have attributes that provide description text,
28 and specifications of argument and option parsing. The code body of
29 the subroutine is then used to implement the actual command.
30
31 * Commandable::Finder::MethodAttributes - a variant of the above
32 which expects that commands are implemented as methods on an object
33 instance.
34
35 * Commandable::Finder::Packages - expects to find each command
36 implemented as an entire package, with (constant) subroutines to give
37 the description text and argument and option parsing specifications.
38 Another subroutine within the package actually implements the
39 command.
40
41 As the user requests that commands be executed, the text of each
42 request is then wrapped in an instance of Commandable::Invocation. This
43 is then passed to the finder instance to actually invoke a command by
44 parsing its name, options and arguments, and run the actual code body.
45
46 my $finder = Commandable::Finder::...->new( ... );
47
48 my $cinv = Commandable::Invocation->new( $text );
49
50 $finder->find_and_invoke( $cinv );
51
52 The finder instance is not modified by individual invocations, and can
53 be reused if the program wishes to provide some sort of multiple
54 invocation ability; perhaps in the form of a REPL-like shell:
55
56 my $finder = ...
57
58 while( my $text = <STDIN> ) {
59 $finder->find_and_invoke( Commandable::Invocation->new( $text ) );
60 }
61
62 AUTHOR
63
64 Paul Evans <[email protected]>
65