Command-Template

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

INTERFACE

 command_runner

       # parse a command line template and use it for running commands
       my $cr = command_runner(qw{ ls [options=-l] <dir> });

    Returns a Command::Template::Runner object with a run method that
    allows actually running generated commands via IPC::Run.

    Each run returns a Command::Template::Runner::Record object that allows
    peeking into the actual result of the run.

       my $r = $cr->run(options => '-la', '/etc');
       say $r->stdout if $r->success;

 cr

    Alias for "command_runner".

 command_template

       my $ct = command_template(qw{ galook <foo> <bar=N> [baz] [sil=Y] })

    Returns a Command::Template::Instance object with a generate method
    that performs the actual expansion, returning a list of strings
    representing the command line.

 ct

    Alias for "command_template".

EXTENDING

    If extending Command::Template is of interest, here are a few hints:

      * class Command::Template::Instance encapsulates parsing a command
      template and expanding it for generating command lists, based on a
      hash with values binding;

      * class Command::Template::Runner provides a simple running facility
      around Command::Template::Instance that uses IPC::Run to run expanded
      commands, returning the result as a Command::Template::Runner::Record
      object.

      * class Command::Template::Runner::Record provides accessors into the
      outcome of a single run from Command::Template::Runner.

    Possible reasons for expanding might be:

      * different or additional rules for expansions are needed. If this is
      the case, the alternative to Command::Template::Instance must provide
      a generate method; Comman::Template::Runner can still be used, as
      long as a reference to the alternative object for the instance is
      passed to the constructor.

      * a different running facility is needed. In this case, it suffices
      to impelement a new runner class, leveraging
      Command::Template::Instance for the command expansion.

BUGS AND LIMITATIONS

    Minimum perl version 5.24.

    Report bugs through GitHub (patches welcome) at
    https://github.com/polettix/Command-Template.

AUTHOR

    Flavio Poletti <flavio@polettix.it>

COPYRIGHT AND LICENSE

    Copyright 2021 by Flavio Poletti <flavio@polettix.it>

    Licensed under the Apache License, Version 2.0 (the "License"); you may
    not use this file except in compliance with the License. You may obtain
    a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    implied. See the License for the specific language governing
    permissions and limitations under the License.



( run in 0.792 second using v1.01-cache-2.11-cpan-39bf76dae61 )