http://www.perlmonks.org?node_id=929555

perlfan has asked for the wisdom of the Perl Monks concerning the following question:

I tried to search around and find the answer to this, but it's a hard question to search for; so here's a new node asking it. Feel free to point me to nodes that might answer this in some way.

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:

The Javascript is responsible for:

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.