PerlDoc

26 August 2025 - 17:41 | Version 1 |
See PublishedAPI for packages intended to be used by Plugin and Contrib authors, or browse all packages.
See also Developing plugins, Developer's Bible, Technical Overview


Parent package: Foswiki::Tables
Child packages:

    internal package Foswiki::Tables::Table

    Abstract model of a table in a topic, suitable for use with the tables parser.

    A table consists of specification and a set of rows. The specification gives type information about the columns it the table, to allow suitable editors to be instantiated on cells.

    The rows in the tables are divided into a block of (uneditable) header rows, a block of (ediatble) body rows, and a block of (uneditable) footer rows. Any of these blocks may be empty.

    A Table object has the following public fields:

    ClassMethod new($specs [, $supertag])

    Constructor The following entries in attrs are used:

    ClassMethod row_class() → $classname

    Perl class used for constructing table rows (default Foswiki::Tables::Row) Designed to be overridden in subclasses that want to use their own subclass of Foswiki::Tables::Row for their rows.

    ClassMethod getMacros() → @macronames

    Get a list of the macro names for additional attributes for tables e.g 'EDITTABLE'. These macros will be processed and combined onto the first recognisable table that follows the macro. Subclasses can choose to override this to ignore TABLE tags, or call SUPER and add their own tags.

    ObjectMethod finish()

    Clean up for disposal

    ObjectMethod makeConsistent()

    Check that the table is consistent with the spec, and fix it if not. If there are header and footer rows defined in the the spec, there have to be enough rows in the table for them. If fix is true, empty rows will be added to flesh out to the required number of rows.

    Added rows will have the number of columns and initial data specified by the format spec (minimum 1 colun)

    ObjectMethod totalRows() → $integer

    Return the total number of rows in the table (including header and footer rows)

    ObjectMethod number([$set]) → $number

    Setter/getter for the table number. The table number uniquely identifies the table within the context of a topic. The table number is undef until it is set by some external agency.

    ObjectMethod stringify()

    Generate a TML representation of the table

    ObjectMethod getHeaderRows() → $integer

    Get the number of header rows on the table. Defaults to 0.

    ObjectMethod getFooterRows() → $integer

    Get the number of footer rows on the table.

    ObjectMethod getID() → $id

    Generate a unique string ID that uniquely identifies this table within a topic. Useful for identifying a table in the context of REST calls that modify the table.

    ObjectMethod getFirstBodyRow() → $integer

    Get the 0-based row index of the first editable row after the header. The row may not actually exist in the {rows}; this is just the index of the row if it does exist.

    ObjectMethod getLastBodyRow() → $integer

    Get the 0-based row index of the last row before the footer. The row may not actually exist in the {rows}; this is just the index of the row if it does exist, given the current size of the table.

    ObjectMethod getCellData([$row [, $col]]) → $data

    Get cell, row, column or entire table, depending on params.

    Only data which exists in the table is returned; columns missing from rows will be filled out with undef.

    ObjectMethod getLabelRow() → $rowobj

    Get the last header row before the first body row. undef if there is no label row.

    ObjectMethod addRow($row [, $newRow [, $any_row]]) → $rowObject

    Construct and add a row after the given row * $row - 0-based index of the row to add after * $newRow - the row to add. A new row will be created using the row_class if this is undefined. If !$any_row, and $row is < 0, then adds to the start of the body rows. If !$any_row and $row is after the last body row, then adds the row to the end of the body rows. if $any_row, and $row < 0, then adds to the start of the table. If $any_row, and $row is after the last table row (including the footer) the adds the row to the end of the table.

    New rows are created with the number of columns specified in the format spec for the table or, failing that, the width of row 0 of the table.

    If $any_row is false, the table will be made consistent (missing header/footer rows added) before anything else is done.

    Returns the new row.

    ObjectMethod isEditableRow($row) → $boolean

    Return true if the given row is editable i.e. is a body row, and exists.

    deleteRow($row [, $any_row]) → $boolean

    Delete the given row * $row - 0-based index of the row to delete * $any_row - true to request deletion of header and footer rows The row must exist. The row must be an editable row unless $any_row is true.

    If $any_row is false, the table will be made consistent (missing header/footer rows added) before anything else is done.

    Returns true if the row was deleted.

    ObjectMethod moveRow($from, $to [, $any_row]) → $boolean

    Move a row Rows must exist. The rows must be editable rows unless $any_row is true.

    If $any_row is false, the table will be made consistent (missing header/footer rows added) before anything else is done.

    If $to is outside the editable part of the table, the row will be moved to the first or last editable position respectively.

    Returns true if the move succeeded.

    ObjectMethod upRow($row [, $any_row]) → $boolean

    Move a row up one position in the table Row must exist. The row must be editable row unless $any_row is true.

    If $any_row is false, the table will be made consistent (missing header/footer rows added) before anything else is done.

    Returns 1 if the move succeeded.

    ObjectMethod downRow($row [, $any_row]) → $boolean

    Move a row down one position in the table Row must exist. The row must be editable row unless $any_row is true.

    If $any_row is false, the table will be made consistent (missing header/footer rows added) before anything else is done.

    Returns 1 if the move succeeded.