NAME

Pitonyak::CommandLineProcessor - Recognize and parse command line arguments.


SYNOPSIS

After writing the same code to process arguments over and over again, I decided to write a processor that could handle most of the tasks for me.

This processor will process the arguments and place them in an array after matching commands with arguments for me.

The processor also recognizes and parses arguments from text files.


DESCRIPTION

More in depth description??

die_on_error

Pitonyak::CommandLineProcessor::die_on_error()

Return the state of the initial die_on_error flag.

$obj->die_on_error()

Return the state of the die_on_error flag.

$obj->die_on_error(0|1)

Set the state of the die_on_error flag.

clear

$obj->clear()

Clear the argument configuration and argument values.

clear_arg_config

$obj->clear_arg_config()

Clear the argument configuration.

clear_arg_values

$obj->clear_arg_values()

Clear the argument values.

get_processed_args

$obj->get_processed_args()

Get a reference to all of the accumulated arguments.

push_processed_arg

$obj->push_processed_arg($arg_name, $arg_value, $method_name)

Push a processed argument set onto the stack.

Argument Description
arg_name Argument name without the leading minus.
arg_value Value
method_nameName of the method to use to parse the argument/value.

process_args

$obj->process_args(@arg_list)

Process each argument based on the current configuration. An argument list is built by calling get_processed_args().

process_args_from_file

$obj->process_args_from_file($file_name, ...)

Process arguments from each file. Empty lines are ignored. The general process is to open and read values from every file and then process the lines.

configure

$obj->configure($cfg)

Configure this object using a configuration file. Typical values are as follows:

Key Description
die_on_error If 1, an error causes program termination.
arg_names Comma separated list of expected argument names.

Each supported argument is assumed to its own entry. A typical examle might be:

arg_names = s, ReadFile
arg = s
arg.${arg}.case_sensitive = 0
arg.${arg}.expects_value = 0
arg.${arg}.allows_value = 1
arg.${arg}.force_value_in_same_arg = 1
arg.${arg}.method_name =
arg.${arg}.description = Recursively traverse directories.
arg.${arg}.arg_is_file_name_to_read = 0

arg = ReadFile
arg.${arg}.case_sensitive = 0
arg.${arg}.expects_value = 1
arg.${arg}.allows_value = 1
arg.${arg}.force_value_in_same_arg = 0
arg.${arg}.method_name =
arg.${arg}.description = Read arguments from the specified text file.
arg.${arg}.arg_is_file_name_to_read = 1

The supported argument configuration items are as follows:

Key Description
case_sensitive Is this argument case sensitive?
expects_value Argument uses a corresponding value.
allows_value Will use a value in the same argument if present.
force_value_in_same_arg Will only accept a value if embedded in the argument using an equal sign.
method_name Method to call to process this argument.
description Text description to print with help.
arg_is_file_name_to_read This argument causes arguments to be read from the specified file.

copy

copy($obj)

Make a copy of one object into another

$obj1-copy($obj2)> is the same as $obj1 = $obj2.

get_class_attribute

The get_class_attribute method utilizes the fact that $obj->method(@parms) is the same as method($obj, @parms). This method does not perform type checking to verify that this is true.

The get_class_attribute method is rarely called directly.

Pitonyak::ADPLogger::get_class_attribute($attribute_name)

With only one paramter, the first parameter is assumed to be an attribute name and the default attribute value is returned.

$obj->get_class_attribute($attribute_name)

With two arguments, the first is assumed to be a ADPLogger object and the second is assumed to be an attribute name. The attribute value for the object is returned.

$obj->get_class_attribute($attribute_value, $attribute_name)

With three arguments, the first is assumed to be the object, the second is a new attribute value, and the third is the attribute name to set. Although the order seems odd, this is intentional.

Consider the method is_ok defined as return get_class_attribute( @_, 'is_ok' );

Remember that @_ refers to the argument list passed to the method. In all cases, the last argument passed to get_class_attribute is the attribute name. If the method is called directly, this is the only argument.

new

$obj = new Pitonyak::CommandLineProcessor;

Generate a new object.

$obj = $obj->new()

Generate a new copy of an object.

is_argument

$obj->is_argument($arg)

Return 1 if $arg starts with a minus sign.

get_argument_name

$obj->get_argument_name($arg)

Obtain the argument name if $arg is preceded by a minus sign. Execpted use is something like:

$arg_name = $obj->get_argument_name($arg) if $obj->is_argument($arg);

If $arg is not an argument, then undef is returned.

The returned name is take from the argument hash, and is not the precise value of the argument. So, if "filename" is not case sensitive, then FileName, and filename will both return filename.

arg_expects_value

$obj->arg_expects_value($arg)

Return 1 if $arg expects an argument, 0, otherwise.

contains_value

$obj->contains_value($arg)

Return 1 if $arg is of the form '-argument=value', otherwise, return 0.

get_value

$obj->get_value($arg)

If $arg is of the form '-argument=value', then return value. If it is not, then return undef.


Private Methods

initialize

initialize()

The initialize() method is called automatically when an object is created. The new method also calls initialize() directly

Initialize the data structure by copying values from the initial attributes hash into the newly created object. Finally, set the read properties hash to an empty reference.