At 01:01 PM 04/04/02 -0500, Aranya Ghatak wrote:
>My Perl script is written as a controller script which takes 'action' and
>'data' as parameters. The action can be any of 'view', 'edit', 'update'
>etc. The data is just a literal indicating the datasource (does not need to
>match the actual table). The controller.pl combines the two literals, and
>looks for 2 files as a combo of <action><data>.tmpl, and .sql. The .tmpl is
>the template, and the .sql is the sql. As a result, the core controller
>script is not aware of any data fields at design time, and becomes database
>aware AT RUNTIME ONLY. This has allowed me to go against ANY table. The
>only caveat is that the fields retrieved by the SQL must match the
>fieldnames in the tmpl files. Of course there is some special processing
>logic in the controller script for inserts/updates, as they do not output
>views.
>
>Now do you see why I can't write the logic within Perl?
Not really. I think it's often easier to understand actual code than a
description of the code.
Here's an example of HTML::FillInForm, and I can not imagine anything
easier. I'm using CGI's param method, but it could be a method to fetch
data from a SQL table, too. The controller can pass in the object with the
param method, so even the code below wouldn't need to know were the data is
coming from.
There's no explicit logic in the program or the template to populate the
form, and you can see that the template designer could switch from a radio
group to a drop down list without changing anything in the program.
My only concern about this method is the time to parse the output from the
form, but I doubt that's much of an issue with forms.
#!/usr/local/bin/perl -w
use strict;
use HTML::Template;
use HTML::FillInForm;
use CGI;
my $q = CGI->new;
$q->param('option', 'Item Two'); # some example data
my @template = <DATA>;
my $template = HTML::Template->new( arrayref => \@template );
$template->param( comment => 'This seems easy' );
my $page = $template->output;
my $fif = HTML::FillInForm->new;
print $fif->fill(
scalarref => \$page,
fobject => $q,
);
__DATA__
<HTML><HEAD><TITLE>Test Template</TITLE></HEAD>
<TMPL_VAR comment>
<BODY>
<SELECT NAME="option">
<OPTION VALUE="Item One">One
<OPTION VALUE="Item Two">Two
<OPTION VALUE="Item Three">Three
</SELECT>
</BODY>
</HTML>
This generates:
<HTML><HEAD><TITLE>Test Template</TITLE></HEAD>
This seems easy
<BODY>
<SELECT NAME="option">
<option value="Item One">One
<option selected value="Item Two">Two
<option value="Item Three">Three
</SELECT>
</BODY>
</HTML>
--
Bill Moseley
mailto:[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]