The notion that web applications have to respond to more than one context has always struck me as being less-than-optimal. Imagine a typical web form: we tend to use a Perl/CGI program to draw up the form (context 1) and when the user submits the form data some parameter gets checked to see what context we are in, and we accept the form data via the same program (context 2). The first lines of code in the program center around finding out what context it is supposed to be in. Furthermore the program has to have multiple sections of code, each dealing with actions related to a particular context.

More recently I played around with CGI::Ajax. Interestingly the Ajax web client/server communication concept deals with the context issue in a very clean and intuitive way. Instead of the usual submit-form action the web client will directly address my server side Perl sub e.g. to request a database and the page is updated using the return values from my server side sub.
To achieve this CGI::Ajax requires a few extra functions to reside in the web client to support communication with the server. Therefore it injects Javascript functions in the head part of the HTML form before that form is sent to the web client.

The concept of cooperation between client-side Javascript and server-side Perl where the Javascript is totally encapsulated/hidden within a Perl module strikes me as a promising approach: we can make the web client more productive without having to write an extensive amount of Javascript as some set of functionality can be provided via Perl modules.
I am looking for a few modules so that I only need to maintain Perl code while I can still benefit from web client side actions.

What is your (production) experience with these concepts? Any caveats? Any Perlmonks that have created Perl modules that encapsulate web client code e.g. to deal with drag-n-drop functions and server side actions related to them? Any stable interfaces that help cooperate with existing Javascript libraries perhaps?


In reply to Encapsulating web client side code in Perl modules? by varian

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.