in reply to Re: object-oriented composition of model-view with HTML::Seamstress
in thread RFC - Template::Empty
Thanks for the softball.and thank you for taking a swing :)
Without manipulating the data in the perl layer, please provide one template that shows them in a bullet list and another template that shows them in a table with three columns with data oriented in columns with one item per cell.I read your definition of Perl layer below. The first comment is that Perl layer is not a fine-grained term. It is a monolithic concept which does not accurately point out the (supposed) source of problems with push-style dynamic html generation. The second comment is that Perl is the practical extraction and report language. It excels at manipulating data. I therefore refuse to use a template system for manipulating data. Model actions belong in model, not anywhere else. And the model is best done in pure perl.
Your sample tt code mixes concerns. Data processing should be testable completely offline.. and completely free of any view. Mine is. Yours isn't.
On the column oriented version fill in wherever there isn't a defined value.uh... no. I will fill in space in my model code function reformat_data. Then delegate the conversion of space to to the HTML renderer....
Be sure external whitespace is nice and consistent.What is external whitespace?
For extra credit - make the template decide conditionally that if you have less than n items use the bullet list - otherwise use the table.That's really just basic Perl:
my $model = Model->new; @$model < $n ? render_bullets($model) : render_table($model);
For extra extra credit - do this exercise - but do it in a text-only based email that will be sent to a user (ie - no html tags).Well you didnt do it. I'm not sure how I would do that. Maybe an html2text tool?
To me the code layer would be your perl modules and your cgi script (or your mod_perl application). The example given is simplified and contrived - but represents real life situations.It's a good example. But once you see my code, please point out the perrin-rhandom syndrome in the push-style approach or recant the criticism.
Update 2 s/specifying/manipulating the data/Again a request I cannot comply with. I will never forget the time that Ovid tried to justify things like this, by calling it "presentation logic" and saying that a "presentation tool" like tt would be good for it. I disagreed with him then and with you now. No one should request data processing anywhere but a data processing giant (Perl).
Now, it has taken me probably 1 hour to write that code. I'm sure it took you less than 5 minutes. I'm a bit rusty in Perl, since I mainly convert Perl ETL scripts to Ab Initio data flow graphs these days. But I would not have been much faster. Push-style development is much slower. And I am grateful to have had a chance to shake the rust off myself :)
Code post follows.
|I have beheld the tarball of 22.1 on ftp.gnu.org with my own eyes. How can you say that there is no God in the Church of Emacs? -- David Kastrup||
|Enforce strict model-view separation in template engines via HTML::Seamstress||The car is in the cdr, not the cdr in the car|
|Replies are listed 'Best First'.|
Re^3: object-oriented composition of model-view with HTML::Seamstress
by Rhandom (Curate) on Feb 25, 2008 at 21:37 UTC