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

Class::DBI::Plugin::HTML - Generate HTML Tables and Forms in conjunction with Class::DBI

SYNOPSIS

 # Inside of your sub-class of Class::DBI add this line:
 use Class::DBI::Plugin::HTML;
   
 # if you want to use the pager function you will need to
 use Class::DBI::Pager; # as well
   
 .....
   
 # Inside your script you will be able to use this modules
 # methods on your table class or object as needed.
   
 my $pager = Table::User->pager(20, $cgi->param('page') || 1);

 my $html_table = Table::User->html_table(-align=>'center');

 $html_table->addRow('User Name','First Name','Last Name');
 
 my $table = Table::User->build_table(
      -pager   => $pager,
      -columns => [ 'user_name','first_name','last_name' ],
      -exclude => [ 'created_on' , 'modified_on' ],
      -table   => $html_table,
     ranking_report_id => sub {
          return qq!<a href="show.htm?id=! . shift() . qq!">view</a>!  
     }, );

 my $nav = Table::User->html_table_navigation(
     -pager        => $pager,
     -navigation   => 'next',
     -page_url     => 'render_test.pl',
 );

 print "'$nav'\n";

 Table::User->add_bottom_span($table,$nav);
     
 print $table;

 my $user = Table::User->retrieve(1);

 #my $form = Table::User->build_form(

 # OR if you want to use the data record to fill in the form
 # make the form via a object versus the class.

 my $form = $user->build_form(                         
     -pager   => $pager,
     # -columns => [ 'user_name','first_name','last_name' ],
     -exclude => [ 'user_id' , 'created_on' , 'modified_on' ],
     -label        => { user_name => 'User Name' },
     user_name => sub {
        return shift() . qq! <a href="view.pl">view</a>!  
     }, );
 print $form;

 my $params = { user_name => 'trs80', first_name => 'TRS' };
 my $ignore = [ 'last_name' ];

 print Table::User->fill_in_form(
    scalarref     => \$form,
    fdat          => $params,
    ignore_fields => $ignore
 );

DESCRIPTION

The intention of this module is to simply the creation of HTML tables and forms without having to write the HTML, either in your script or in templates.

This module is still in a pre-release state and using it for anything other then evalution/development is not recommended.

Feedback on this module, its interface, usage, documentation etc. is welcome.

The use of HTML::Table was selected because it allows for several advanced sorting techniques that can provide for easy manipulation of the data outside of the SQL statement. This is very useful in scenarios where you want to provide/test a sort routine and not write SQL for it.

METHOD NOTES

The parameters are passed in via a hash for most of the methods, the Class::DBI::Plugin::HTML specific keys in the hash are preceeded by a hypen (-). Column names can be passed in with there own anonymous subroutine (callback) if you needed to produce any special formating or linkage.

METHODS

html_table

returns an HTML::Table object, this is a public method and accepts a hash as its constructor options. See HTML::Table for valid arguments.

build_table

Accepts a hash of options to define the table parameters and content.

   my $table = Table::User->build_table(
   # pass in the Class::DBI::Pager object if applicable
   -pager   => $pager,
   
   # define the columns (this is also the order)
   -columns => [ 'user_name','first_name','last_name' ],
                
   # what columns not to show, useful if you are dynamically
   # turning off columns and don't want to alter the columns
   # list at the page/script level for whatever reason
   -exclude => [ 'created_on' , 'modified_on' ],
                
   # can pass in an existing HTML::Table object, this
   # allows for the header to be assigned etc. prior to
   # dynamically adding the records from the database
   -table   => $html_table,
                
   # using the column name as the key you can pass in
   # sub routines to dynamically alter the way the column             
   # is displayed 
   user_id => sub {    return qq!<a href="show.htm?id=! . shift() . qq!">view</a>!   },

   ):

build_form

Accepts a hash of options to define the form options

    my $form = Table::User->build_form(
                
       -columns => [ 'user_name','first_name','last_name' ],
       -exclude => [ 'user_id' , 'created_on' , 'modified_on' ],
       
       # assign the friendly name for the cell with the form
       # element name
       -label   => { user_name => 'User Name' },
       
       # same as the build_table method, this allows for custom
       # handling of a specific field based on the column name
       user_name => sub { 
               return shift() . qq! <a href="view.pl">view</a>! },
     );
     
     print $form;

html_table_navigation

Creates HTML anchor tag (link) based navigation for datasets. Requires Class::DBI::Pager. Navigation can be in google style (1 2 3 4) or block (previous,next).

    my $nav = Table::User->html_table_navigation(
                                -pager        => $pager,
                                -navigation   => 'next',
                                -page_url     => 'render_test.pl', 
                           );
    print "'$nav'\n";

fill_in_form

Wrapper method for HTML::FillInForm, pass the arguments you would normally pass into HTML::FillInForm.

    my $params = { user_name => 'trs80', first_name => 'TRS' };
    my $ignore = [ 'last_name' ];

    print Table::User->fill_in_form(
        scalarref     => \$form,
        fdat          => $params,
        ignore_fields => $ignore
    );

add_bottom_span

Places the content you pass in at the bottom of the HTML::Table object passed in. Used for adding "submit" buttons or navigation to the bottom of a table.

BUGS

Unknown at this time.

AUTHOR

Aaron Johnson solution@gina.net

THANKS

Thanks to my Dad for buying that TRS-80 in 1981 and getting me addicted to computers.

Thanks to my wife for leaving me alone while I write my code :^)

The CDBI community for all the feedback on the list and contributors that make these utilities possible.

CHANGES

Changes file included in distro

COPYRIGHT

Copyright (c) 2004 Aaron Johnson. All rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.