Please sign in to comment.
Make handling of MAIN completely pluggable and documentable
But keep the old interface working as to not break any ecosystem modules that rely on the old interface. An ecosystem module now has 3 intercept vectors it can use: - provide a sub RUN-MAIN This allows *COMPLETE* control over the handling of MAIN. It gets a Callable that is the MAIN that should be executed (so no callframe gymnastics needed anymore), the return value of the mainline execution (currently always Nil) and additional named variables: :in-as-argsfiles which will be True if STDIN should be treated as $*ARGFILES. If RUN-MAIN is not provided, a default one will be run that looks for subroutines of the old interface, such as MAIN_HELPER and USAGE. If found, will execute following the "old" semantics. - provide a sub ARGS-TO-CAPTURE This allows control on how the command line arguments are converted to a capture. If specified, it should receive a Callable (which is the MAIN that will be executed), and an array of command line arguments. It should return a Capture object. This should allow most GetOpt:: modules to severely simplify their logic, as they usually are only interested in that part, not in the actual dispatch part. - provide a sub GENERATE-USAGE If available, this sub will be called to generate any usage information for the user. It should accept a Callable as the first parameter (which is the MAIN that couldn't get executed because the dispatch failed) and any other parameters from the Capture that was generated from the command line arguments. It should return a string with the usage information If no GENERATE-USAGE sub could be found, it will check for the existence of a USAGE sub (assuming the old interface) and call that if available: this is expected to actually print the usage. If neither is available, then the default usage generation will be used and printed on STDOUT/STDERR as appropriate with the correct exit() value. The plan is to mark the old interface for DEPRECATED as soon as with hit 6.d, to be removed with 6.e. This should allow module developers to provide a 6.d version of their GetOpt::... modules that would only need to provide the new interface.
- Loading branch information...
Showing with 83 additions and 47 deletions.