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.

In reply to Providing Hints to LWP Applications by princepawn

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.