Forgetting the whole separate design from code question, incidentally.

You can't really do that, being a programmer. It isn't so much a question of design/code, but of dynamic/static.

Stitching together static text dynamically via costly sub calls (yes, subroutine calls in perl are costly) every time you output the same chunk of data is unwise and inefficient, no matter whether your usage of the underlying module to do that is efficient or not.

Then there's the question of maintainability. Inserting another row of label/text fields is tedious at the same level as with plain html code, so nothing gained here either. I'd use at least a structure like

# Table data my @rows = ( ['FaultFinder ID', [{ id => 'ff-job-id' }] ], ['Username', [{ id => 'searchby-user'}] ], ['Status', [{ id => 'searchby-status'}] ], ['Time', [ { id => 'searchby-date-start', label => 'begin', onchange => 'checkDate(this)', }, { id => 'searchby_date_end', label => 'end', onchange => 'checkDate(this)', }, ] ], ['', [ { id => 'right_submit_button', type => 'submit', onmousedown => "checkForm('searchForm')", value => 'Go', }, { id => 'submitted', type => 'hidden', value => 'get_existing_ff', }, ] ] );

to hold the relevant data, document that structure and organize my code to deal with that structure. That way if you ever were to insert a row containing e.g. a database identifier against which to run the search (or such), you haven't got to go through your code to find the right place, but just add an element to that array.

update:

The generating code could be in terms of CGI, or something else. I prefer HTML::Writer to produce templates or static HTML files.

#!/usr/bin/perl # use HTML::Writer qw(xhtml1-strict.dtd); # above @rows definition goes here. render { HTML { HEAD { TITLE { "Some Form" } }; BODY { FORM { action_ "/cgi-bin/ff-webclient.pl"; name_ "searchForm"; id_ "searchForm"; FIELDSET { LEGEND { 'Query finished/currently running jobs' }; DIV { class_ 'instructions' }; TABLE { for (@rows) { my ($label, $inputs) = @$_; my $cs; TR { if ($label) { TD { LABEL { class_ 'small'; for_ $inputs->[0]->{id}; $label; }; }; } else { $cs = 2; } TD { $cs and colspan_ $cs; for ( @$inputs ) { if ($_->{label}) { t $_->{label}; BR {}; }; INPUT { type_ $_->{type} || 'text'; name_ $_->{id}; id_ $_->{id}; $_->{value} && value_ $_->{value}; $_->{onchange} && onchange_ $_->{onchange}; $_->{onmousedown} && onmousedown_ $_->{onmousedo +wn}; }; BR {} if @$inputs > 0 and $inputs->[-1]->{id} ne $_->{id}; } }; }; } }; }; }; }; }; } 1;

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: overuse of CGI module HTML methods? by shmem
in thread overuse of CGI module HTML methods? by weedom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.