perlfan has asked for the wisdom of the Perl Monks concerning the following question:
Say I am creating a web app; say with CGI::Application and Template Toolkit. Given some strict separation between my business logic and display logic (using various methods, including those espoused by metaperl, I am unsure where Javascript fits in.
There's a ton of stuff to say what HTML generation and separation options exist, but not so much when it comes to the Javascript.
I have:
- MyApp.pm (which ISA CGI::Application)
- app-driver.pl
- HTML templates (or some Xth generation method)
- some reliance on Javascript
The Javascript is responsible for:
- providing a more "enriching" UI to interface with some set of data (i.e., report controls)
- asynchronously fetching data
- potentially transforming and caching data
- displaying data (e.g., a chart or datatable, potentially pagination and result filtering)
Like "powerful" templating systems, the temptation here is to muddle the Javascript with logic that is part of both the business and display domains. However, it seems like a much darker and more treacherous place than the dark alley provided for by overly powerful templating systems.
Where does one draw the line? Is Javascript also strictly to be taken as a means of implementing the display logic? Or, as YUI encourages you, is it part of the business logic?
What is Perl's role when creating an application? Is it possible that the answer is, "it depends"? In which case, you need to make a decision in the beginning and stick with it?
For example, investing heavily in the client side potential of something like YUI makes it possible to do the MVC thing in the Javascript, treating Perl simply as a way to provide a 2-way pipe with a remote database (for example). It is also possible to do as much as possible on the Perl side (e.g., even pagination) and treat the Javascript like it's just a box of dumb widgets for the browser part of the "view".
Depending on the answer, the question then becomes: do you maintain the Javascript statically (inside of some static HTML template or Javascript file) OR do you insome way attempt to generate the Javascript using some Nth generation templating paradigm?
In otherwords, once you decide what side of the application the Javascript plays a role (shouldn't be both, right? or can it?), how do you include the Javascript as part of your "code" base (including HTML templates/gen, MyApp.pm, app-driver.pm)?
Perhaps the name of the game is to be disciplined in one way or the other. But regardless of what Perl framework you use, what is the right way to deal with the Javascript?
Thank you.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Javascript: Display Logic or Business Logic?
by suaveant (Parson) on Oct 04, 2011 at 14:30 UTC | |
Re: Javascript: Display Logic or Business Logic?
by chrestomanci (Priest) on Oct 04, 2011 at 14:40 UTC | |
by Rhandom (Curate) on Oct 05, 2011 at 13:30 UTC | |
by perlfan (Vicar) on Oct 04, 2011 at 15:50 UTC | |
Re: Javascript: Display Logic or Business Logic?
by metaperl (Curate) on Oct 04, 2011 at 15:33 UTC |