Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: HTML - seperating design and logic

by submersible_toaster (Chaplain)
on Jul 03, 2004 at 11:45 UTC ( #371569=note: print w/ replies, xml ) Need Help??


in reply to HTML - separating design and logic

MUBA,
You raise a valid point, what concerns me the most with code I write and/or maintain is when architecture says that code and display logic are supposed to be seperate but you end up resorting to stuff like.

my $t= HTML::Template->new( $sometemplate ); my $insert = $q->table ( $self->build_some_table ); $t->param ( bigtable=>$insert );
This is obviously a naff example, since $insert should be a TMPL_INCLUDE (if you talk HTML:Template).

As raised earlier , display logic within templates is seen to be a necessary evil, less important that seperating WHAT data should be rendered as opposed to HOW that data should be presented. Your code should build valid structures of data that make sense to your templating system.

What this suggests to me is that there is room in the design for a pre-output process between generating valid data and filling a template with that data. When I find myself writing objects with a data struct one way, but a method to output something that makes sense to a template system. eg

my $self = Some::CGI::Class->new( %params ); $self->update_data; return $self->template_data;
It feels like the reformatting of my object's data for a template system is NOT the responsibility of my object. There ought to be a preprocessing phase. Yet another level of complexity. This pre-processing stage is where I would expect the addition of things like odd/even line BG color changes, or turning a structure inside out to list it as entities by sorted key. For example , your method returns an hash of object references with names as keys that are valid and relevant to the current application's run_mode, you pass that data structure to a template preprocessor because you would like the data ordered by keys and flattened into an array of hashes suitable for a TMPL_LOOP. MIght look more like.
$self->update_data; my $t = HTML::Template->new( $sometemplate ); my $tpp = HTML::Template::PreProcessor->( hash=>'sorted' , style=>'arr +ay' , object=>$self ); $t->param ( $tpp->preprocess ); return $t->output;


I can't believe it's not psellchecked


Comment on Re: HTML - seperating design and logic
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://371569]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (14)
As of 2014-12-18 17:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls