NAME

ScalarTable - scalar table component property


SYNOPSIS

  use Podius::Property::ScalarTable;
  $d = new Podius::Property::ScalarTable(['name', 'age', 'mark']);
  $d->access([['Paul', 10, 98], ['John', 12, 60], ['Jack', 11, 85]]);
  print "Name\tAge\tMark\n", $d->as_string("%s"), "\n";


DESCRIPTION

To write.


REQUIREMENTS

the Exception manpage, the Podius::Property manpage.


CONSTRUCTORS

new

description
Class constructor.

returns
New formed property reference.

new_from_serialized

description
Class constructor. Used for deserialization.

parameters
Class name (like all constructors) and string, representing the property.

returns
New formed property reference.


METHODS

serialize

description
Used for serialization.

returns
String, representing the property, from which the property can be restored later by new_from_serialized constructor.

access

parameters
Accessor: none.

Modifier, 1 parameter: value to set (ARRAY of ARRAYs of scalar). Empty ARRAY unsets all rows.

Modifier, 2 parameters: ARRAY of one index [row] and ARRAY of scalar to set.

Modifier, 2 parameters: ARRAY of two indexes [row, column] and scalar to set.

Modifier, 3 parameters: offset, length and ARRAY of additional rows (i.e. ARRAY of ARRAY of scalar) - similar to the Perl built-in function splice, to delete existing and add new rows at specified offset

examples
  my $rows = $scalar_table->access;  # two-dimensional ARRAY
  $scalar_table->access($new_rows);
  $scalar_table->access([1], [10, 20, 30]);
  $scalar_table->access([0, 2], 30);
  $scalar_table->access(4, 2, []);  # delete fifth+sixth rows
  $scalar_table->access(4, 0, [[10, 20, 30]]);  # add one row
  # Suppose, my_table property is of type ScalarTable
  my $rows = $component->my_table;  # two-dimensional ARRAY
  $component->my_table($new_rows);
  $component->my_table([1], [10, 20, 30]);
  $component->my_table([0, 2], 30);
  $component->my_table(4, 2, []);  # delete fifth+sixth rows
  $component->my_table(4, 0, [[10, 20, 30]]);  # add one row
returns
Property value. Usually ARRAY of ARRAYs, but depends on parameters.

access_column

description
Only accessor form is available.

parameters
  * column number to access
returns
Constructed ARRAY that includes scalars of the given table column.

access_headings

description
Only accessor form is available.

parameters
none

returns
ARRAY of column names, i.e. static headings this table property was defined with.

access_as_string

description
Only accessor form is available.

This is an alias to as_string method.

access_as_hash

description
Only accessor form is available.

parameters
  * optional index of column to use as hash-value (or arrayref of indexes),
    default is 1 if there two columns or [ 1 .. width - 1 ] if more columns
  * optional index of column to use as hash-key, default is 0
returns
Hash with the first column value as the hash key and another column value as the hash value, or multiple column values in arrayref as the hash value.

In scalar context returns hashref. in list context returns plain hash.

as_string

parameters
  * scalar format (optional, default is '"%s"')
  * outer delimiter (optional, default is "\n", example: '; ')
  * inner delimiter (optional, default is "\t", example: ', ')
returns
String representation of the property data.

push

parameters
  * a list of array refs to be pushed to the end of table
returns
The resulting property value, ARRAY of ARRAYs of scalars (read only).

access_push

description
Only modifier form is available.

This is an alias to push method.

add

description
Adds rows to the scalar table.

parameters
  * number of rows to add
  * optional array to initialize rows, [ ""* ] by default
  * optional boolean, if true, then add to the beggining not the end
returns
Number of rows actually added, 0 on bad input.

delete

description
Delete certain rows from the scalar table.

parameters
  * number of rows to delete
  * optional boolean, if true, then delete from the beggining not the end
  * optional starting index (default 0)
returns
Number of rows actually deleted, 0 on bad input.