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

If you have a multi-screen form and you want to write an LWP script to interact with this form just like a human, at some point, you must be able to return error's from script usage just as you would from interactive usage...

From what I can see, the biggest problem with this is how to have the script know the difference between normal HTML outuput of the screens and error alerts. Over the last 2 days, with much teeth-gnashing, I have run across or thought up a few different ways of providing "hints" to external LWP clients:

Comment the HTML

One thing you could do is edit all returned HTML with comments. Some comments would be instructions to the LWP client:
<h3>Address Form</h3> &lt;!-- BEGIN LWP: error &gt; Your city and state do not match the indicated zip code. Please re-enter &lt;!-- END LWP error &gt;

HTTP return codes

One other avenue is to use a predefined set of HTTP return codes and simply use the code to generate the error... but is it possible to "reserve" a subset of the HTTP return codes for each app's intended use?

A problem is that if a page had multiple problems, you can only return one status code and not alert the user to all problems with the input.

Parse the HTML

Admittedly a rough solution, but that's what brainstorming is all about. In my first incarnation of such a script that I wrote recently, I wrote a regexp to search for all text bracketed with  font color=red and used that as indication that the page had errors.

Replies are listed 'Best First'.
Re: Providing Hints to LWP Applications
by arturo (Vicar) on Mar 17, 2001 at 02:19 UTC

    I'd probably go with the commenting route myself, and extract the comments with HTML::Parser. This doesn't have the drawbacks you mention for the httpd code thing (i.e. is easily extensible) and won't bother anybody viewing things in a GUI browser at all, and may help 'em if they know to look for them.

    Another option which may be (ok, probably is) unavailable is to return pure XML and include explicit <error> tags in it (biggest problem: not every user's browser will support XML).

    Of course, you could combine the two approaches, include some XML in comments for the customized LWP agents; parse that with a standard XML parser (which could generate your errors as a nice data structure with only a little sweat, which is one nice thing about the XMLy approach in the first place) , and you're golden...

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor