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

Config::Objective::Table - table data type class for Config::Objective

SYNOPSIS

  use Config::Objective;
  use Config::Objective::Table;

  my $conf = Config::Objective->new('filename', {
                        'tableobj'      => Config::Objective::Table->new()
                });

DESCRIPTION

The Config::Objective::Table module provides a class that represents a table value in an object so that it can be used with Config::Objective. Its methods can be used to manipulate the encapsulated table value from the config file.

The table data is represented as a list of lists. Both rows and columns are indexed starting at 0. It is derived from the Config::Objective::List class, but it supports the following additional methods:

insert_row()

Inserts a new row into the table before a specified row.

The first argument is used to determine the existing row before which the new row should be inserted. It must be a reference to a hash that maps column numbers to a regular expression that the column's value must match. If the hash is empty, the new row will be inserted before the first existing row.

The second argument is a reference to an array. It contains the row to be inserted.

find_row()

Finds a row in the table. The argument must be a reference to a hash that maps column numbers to a regular expression that the column's value must match. If the hash is empty, the first row will be returned.

This function is not very useful for calling from a config file, but it's sometimes useful to call it from perl once the config file has been read.

replace_row_cells()

Replaces one or more cells in a given row.

The first argument is used to determine the row to be modified. It must be a reference to a hash that maps column numbers to a regular expression that the column's value must match. If the hash is empty, the first row is used.

The second argument represents the new values for the matching row. It must be a reference to a hash that maps column numbers to the new value for that column.

append_to_row_cells()

Similar to replace_row_cells(), but appends to the existing value instead of replacing it. A space character is appended before the new value.

In addition, the following deprecated methods are available for backward compatibility:

add_before()

Inserts a new row into the table before a specified row. The argument must be a reference to a list containing three elements: a number indicating what column to search on, a string which is used as a regular expression match to find a matching row in the table, and a reference to the new list to be inserted before the matching row.

find()

Finds a row with a specified word in a specified column. The column number is the first argument, and the word to match on is the second. It returns a reference to the matching row, or undef if no matches were found.

replace()

Finds a row in the same manner as find(), and then replaces that row's value in a specified column with a new value. The arguments are the column number to search on, the word to search for, the column number to replace, and the text to replace it with.

modify()

Similar to replace(), but appends to the existing value instead of replacing it. A space character is appended before the new value.

Note that these deprecated methods should not be used by new applications. They will be removed altogether in a future release.

AUTHOR

Mark D. Roth <roth@uiuc.edu>

SEE ALSO

perl

Config::Objective

Config::Objective::List