Gisle Aas


webchatpp - Preprocessor for Web Chat scripts


 webchatpp chat-script | perl


The webchatpp program is a preprocessor that turns chat scripts into plain perl scripts. When this script is feed to perl it will perform the chatting. The webchat language consist of perl code with some lines interpreted and expanded by webchatpp. The following statements are recognized:

GET <uri>

This will fetch the indicated URI. The URI can be relative to the previous base. Each GET gets it's own eval block within the perl program to catch any exceptions. Inside this block, the following dynamically scoped variables are available:

  $uri       The current URI
  $req       The current request object        [HTTP::Request]
  $res       The response received             [HTTP::Response]
  $status    The status code of the response
  $ct        The content type of the response
  $base      The base URI for current response
  $_         The content of the response
  @forms     Forms found in current content    [HTML::Form]
  $form      Current form                      [HTML::Form]
  @links     Links found in current content
EXPECT <expr>

Evaluate the perl expression <expr> and report failure if it does not return TRUE. The fact that content of the response is available in $_ makes it easy to match it with regular expressions. The routines OK() and ERROR() is available to test the response status code.

When EXPECT fails all tests nested within this one is aborted too.

FORM[:<no>] [<name>]

Define which <FORM> should be the current one. Sets the $form variable. If no number is specified, then number 1 is assumed. If a form with the given number (or name, if specified) can not be found, then an exception is raised, and this block is aborted.

F <name>=<value>

Set input values within the current form. If the current form has no field named <name>, then an exception is raised. If the form has multiple fields named <name>, then only the first one is affected.

CLICK [<name>] [<x> <y>]

Submit a <form>. If there are multiple submit buttons, then you can specify which one by passing the <name>. You can also indicate which coordinates within the buttion, was clicked. Only makes a difference for input/image submits.

CLICK enters a new block similar to GET, and make the same dynamically scoped variables available.

You can use the keyword "SUBMIT" instead of "CLICK" if you prefer. It is a plain alias.

FOLLOW /text/

Tries to find a hyperlink with the given description, and will then follow it. Enters a new block like GET.

FOLLOW <num>

Will follow the <num>'th hyperlink on the current page. Enters a new block like GET.

BACK [<levels> | "ALL"]

Ends the previous GET or CLICK blocks. The argument can be used to get out of multiple blocks.


Stop looking for webchat language directives. The rest of the script is dumped directly (and is also ignored by perl). Implies "BACK ALL".

The following variables are global within the whole web chat script produced:

  $ua        User agent object    [LWP::UserAgent]
  $uri       Current URI
  $TRACE     Print trace showing HTTP requests/responses.


The initial value of the $TRACE variable is initialized from the WEBCHAT_TRACE environment variable.

Proxy settings are picked up from the environment too. See "env_proxy" in LWP::UserAgent.


This is a sample script:

    EXPECT OK && /perl/
    GET not_there.html

And here is another one

 F q=Gisle
 EXPECT OK && /Gisle Aas/




Copyright 1998 Gisle Aas.

This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.