Lightweight, Component-based, and Database-oriented Web Application Framework

About | Overview | Documentation


Documentation > Modules and APIs > Table_List_Data




The core module to dynamically handle application's data in more organized and structured manner at application runtime. The Table_List_Data istance will exists as dynamic data structure to hold applicaton's data persisted in the form of rows and columns, and provide the logical functions to operate the data. It might also be used as an alternative to handle data items from database table besides the standard forms of data structure acquired via CPAN's DBI module.

This module also offer advantage for displaying its data items content in HTML document format. It can be done conveniently by just passed its instance to TLD_HTML_Map module.


1. Instantiation and Basic Parameter Setting

my $tld = new Table_List_Data;

1.1 Add Columns and Data Items

The arguments $column_1, ..., and $column_n are the columns name to be added. An arrays of data @data_1, ..., and @data_n should have their length equal with the number of columns added.



An array of hash references can also be used to simultaneously adding the columns and data items (rows). If they are still not exist, the columns names are automatically added using the hash key names $key_name_1, ..., and $key_name_n.
my @ahr = ({$key_name_1 => $value_1, ..., $key_name_n => $value_n}, {...}, ...);


1.2 Instance Creation via DBI_HTML_Map Module

Instead of manually instantiate and add the data items into Table_List_Data instance, it's more convenient to do so by using DBI_HTML_Map module. Using DBI_HTML_Map module instance ($dbihtml), all database table column names and row items (data) returned by the SQL command defined in $sql argument will be created and copied into $tld instance created by the get_Table_List_Data function.

my $dbihtml = new DBI_HTML_Map;



my $tld = $dbihtml->get_Table_List_Data;

2. Insert (Shifting) Data Items

Data items can be added at specific row index and automatically shift down other current existing items to the next rows.
my $array_ref = [$value_1, ..., $value_n];
$tld->insert_Row_Data($row_index, $array_ref);

As with adding columns and data items, shifting data items can also be done by using an array of hash references.
my @ahr = ({$key_name_1=>$value_1, ..., $key_name_n=>$value_n}, {...}, ...);
$tld->insert_Array_Hash_Reference($row_index, @ahr);

3. Update Column Data

Update column data at specific row index ($index_row) for the column with name $column_name.

$tld->set_Data($index_row, $column_name, $new_data);

The column data might also be used to represent HTML hypertext links. The argument $get_link is a standard HTTP-GET query string of the HTML link tag (<a ...>...</a>). Other properties of the HTML link tag can be set via $link_properties argument.
$tld->set_Data_Get_Link($index_row, $column_name, $get_link, $link_properties);

4. Sorting Data Items

The first string argument "column_1 ... column_n" (separated by single spaces) are the column's names to be imposed by the sort operation. Sort order types (ascending/descending) for each columns are defined by "sort_order_1 ... sort_order_n" respectively and their values can be either "asc" or "desc". The last string argument "column_type_1 ... column_type_n" represents how the sort operation will be applied on each columns. Use the options of "str" or "num" to sort the involved columns as a string or numerical data.

$tld->sort_Data("column_1 ... column_n", "sort_order_1 ... sort_order_n", "column_type_1 ... column_type_1");

5. Access to and Information of Data Items

Get current columns number and total row items number.

my $num_row = $tld->get_Row_Num;
my $num_col = $tld->get_Column_Num;

Get column name at specific column index ($index_col).
my $column_name = $tld->get_Column_Name($index_col);

Get column data at specific row index ($index_row) for the column with name $column_name.
my $column_data = $tld->get_Data($index_row, $column_name);

Next is the possible logical operations can be used to display all columns data in each rows from Table_List_Data instance by combining all previous functions explained in this section.
my $num_row = $tld->get_Row_Num;
my $num_col = $tld->get_Column_Num;

for (my $index_row = 0; $index_row < $num_row; $index_row++) {
    print "Row number ", $index_row + 1, "\n";
    for (my $index_col = 0; $index_col < $num_col; $index_col++) {
        my $column_name = $tld->get_Column_Name($index_col);
        my $column_data = $tld->get_Data($index_row, $column_name);
        print "$column_name = $column_data\n";
    print "\n";

Get data items in HTML table string format for quick content display purpose.
my $html_table_str = $tld->get_Table_List;