The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Term::CLI::Element - generic parent class for elements in Term::CLI

VERSION

version 0.060000

SYNOPSIS

use Term::CLI::Element;

my $arg = Term::CLI::Element->new(name => 'varname');

DESCRIPTION

Generic parent class for command line elements in Term::CLI(3p). This is used by Term::CLI::Command(3p) and Term::CLI::Argument(3p) to provide basic, shared functionality.

This class inherits from Term::CLI::Base(3p) to provide the error, term, and set_error methods.

CLASS STRUCTURE

Inherits from:

Term::CLI::Base(3p).

Consumes:

None.

CONSTRUCTORS

new ( name => VARNAME ... )

Create a new Term::CLI::Element object and return a reference to it.

The name attribute is required.

METHODS

The Term::CLI::Element class inherits accessors and methods from Term::CLI::Base(3p).

In addition, it defines:

complete ( TEXT, STATE )

Return a list of strings that are possible completions for TEXT. By default, this method returns an empty list.

Sub-classes should probably override this.

STATE is a HashRef that contains the following elements:

processed => ArrayRef

More elaborate "parse tree": a list of hashes that represent all the elements on the command line that have already been processed by parent (Term::CLI::Command) objects.

Example:

[
    {
        element => InstanceOf['Term::CLI::Command'],
        value   => 'show'
    },
    {
        element => InstanceOf['Term::CLI::Command'],
        value   => 'info'
    },
    {
        element => InstanceOf['Term::CLI::Argument'],
        value   => 'foo'
    },
    ...
]
unprocessed => ArrayRef

Refers to a list of words leading up to (but not including) the TEXT that have not yet been processed by parent objects.

For Term::CLI::Command objects this is typically a list of command line arguments and sub-commands.

For Term::CLI::Argument objects this will be empty.

options => HashRef

Command line options that have been seen in the input line so far.

For most simple cases, you would only need to examine TEXT (and, for command objects, the unprocessed list).

The processed list and options hash can be used to implement context sensitive completion, however.

SEE ALSO

Term::CLI::Argument(3p), Term::CLI::Base(3p), Term::CLI::Command(3p), Term::CLI::ReadLine(3p), Term::CLI(3p).

AUTHOR

Steven Bakker <sbakker@cpan.org>, 2018.

COPYRIGHT AND LICENSE

Copyright (c) 2018 Steven Bakker

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See "perldoc perlartistic."

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.