Perhaps you're right. That was a bad example. One way CGI.pm shows its usefulness which seems to been obscured here is with deeply nested constructs (table within a table within a form, etc.).
By replacing the BEGIN/END (tag) paradigm with a nested function call paradigm, CGI all but eliminates the kind of unbalanced tag nuisances one frequently encounters when generating HTML dynamically.
IMHO, I find looking at naked HTML (in a HEREDOC or otherwise) annoying for its waste of space (I suppose XML rubs me much the same way) and its near-redundancy; I dislike typing it even more.
I suppose the advantage is better illustrated with this comparison:
<FORM METHOD='POST>
<INPUT TYPE="hidden" NAME="mode" VALUE="confirm">
<TABLE BORDER=0>
<TR>
<TD>
<TABLE WIDTH='100%'>
<TR>
<TH>ColA</TH>
<TH>ColB</TH>
<TH>ColC</TH>
</TR>
<TR>
<TD>Value A</TD>
<TD>Value B</TD>
<TD>Value C</TD>
</TR>
<TR>
<TD><INPUT TYPE="submit"></TD>
<TD><INPUT TYPE="reset"</TD>
<TD> </TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
Compared with:
form( { -method => 'POST' },
hidden( -name => 'mode', -value => 'confirm' ),
table( { -border => 0 },
Tr( td( table( { -width => '100%' },
Tr( th( [ 'ColA','ColB','ColC' ] ),
td( [ 'Value A','Value B','Value C'
+] )
td( [ submit, reset, ' ' ] ))
)))
)
)
Oh, you want to write all that to the browser?
print form( { -method => 'POST' },
hidden( -name => 'mode', -value => 'confirm' ),
table( { -border => 0 },
Tr( td( table( { -width => '100%' },
Tr( th( [ 'ColA','ColB','ColC' ] ),
td( [ 'Value A','Value B','Value C'
+] )
td( [ submit, reset, ' ' ] ))
)))
)
)
dmm
You can give a man a fish and feed him for a day ...
Or, you can teach him to fish and feed him for a lifetime
|