NAME

Weblibs.pm - Fill-in-the-blanks funnythings for the Web


AUTHOR

 David M. Chess, weblibs@davidchess.com


SYNOPSIS

    use Weblibs;

    # Initialize the titles and bodies (in practice,
    # these would be considerably longer!)
    $libarray = [
      { hinttitle => "Important Words",
        fulltitle => "Proverbs",
        body => "These are [plural noun] that try men's [plural noun].<br>
                 A [noun] saved is a penny [verb, past tense].<br>
                 Too many [plural noun] [verb] the [food item]."
      },
      { hinttitle => "Poem",
        fulltitle => "That thing about ships",
        body => "I must go down to the [noun] again,<br>
                 To the [adjective] sea and the [noun].<br>
                 All I [verb] is a tall [noun],<br>
                 And a [noun] to [verb] her by."
      }];

    # Create a new set of Libs from it
    $ls = new Weblibs::Libset($libarray);

    # Tell it where the script is
    $ls->{scripturl} = "WeblibDriver.cgi";

    # Do a little tailoring
    $ls->{menutitle} = "Fred's Weblibs Page";
    $ls->{inputtitle} = "Fred's Weblibs -- &hinttitle;";
    $ls->{resulttitle} = "&fulltitle;";
    $ls->{result_intro_text} = "Here's what you've created!<p>\n";
    $ls->{inputbuttontext} = "GO!";

    # Print whatever the current CGI state calls for
    print $ls->getCgiPage();


USAGE

The Weblibs package provides a Web/CGI-based interface to a set of amusing things, similar to the amusing things that constitute the popular ``Mad Libs'' paper-and-pencil party game.

(``Lib'', here, is pronounced to rhyme with ``bib'', and has no connection to the use of ``lib'', generally pronounced so as to rhyme with ``vibe'', and used as shorthand for ``library''.)

The Weblibs user is first presented with a menu of available Libs, described by vague and general descriptions, and asked to choose one. Upon choosing one, a list of parts of speech is presented, and the user prompted to give a word for each part of speech. Finally, the full filled-in Lib is shown to the user, with its actual title, and the user's chosen words filled into critical places in the text. The result is always amusing.


HISTORY

  1999/09/11 - First release version, 1.00


LIMITATIONS

The author is too lazy to document all the different instance variables that you can mess with to tailor the html output. See the code for the ``new'' routine to see them all being initialized.


Details


Setting up


new($list_reference)

creates a new Weblibs::Libset object, associated with a given set of Weblibs. The set is passed as an array of hash references. Each hash has fields ``hinttitle'', ``fulltitle'', and ``body''. The ``hinttitle'' is used on the menu page to give the user some vague idea of the Libs available; the ``fulltitle'' is shown on the final results page, as the actual title of the final thing.

The ``body'' field consists of the text of the Lib, with the ``blanks'' represented by part-of-speech names in square brackets. See the SYNOPSIS. The ``body'' field may also contain HTML markup if desired.

The new method returns, of course, a new Weblibs::Libset, or undef if error (currently there is no such thing as an error).


The scripturl instance variable


$object->{scripturl} = "http://www.whatever.com/path/whatever.ext";

This instance variable must be set to the URL of the script itself, before any methods are called on the new object, so that the HTML forms produced will cause the script to be called again when the user completes the form.


Instance Methods


$stuff_to_print = $object->getCgiPage()

The getCgiPage() method returns the stuff that a CGI script using the module would normally return, given the current contents of STDIN, @ENV, and so on. If the script was invoked directly from an HTML page, the menu of Libs will be presented; if it was invoked by the user selecting an individual lib, the fill-in-the-blanks page for that lib will be presented; and if the script was invoked by the user returning the fill-in-the-blanks form for a lib, the filled-in result will be presented.

The returned value will include the usual CGI ``Content-type: text/html\n\n'' at the top, so a normal CGI script needs to do nothing but print it (see the SYNOPSIS).


$menu_page_html = $object->getMenuPage()

returns the HTML (with no CGI prolog) for the menu page associated with the Libset. A normal CGI script will not have to use this (use getCgiPage() instead), but here it is anyway.


$input_page_html = $object->getInputPage($n)

returns the HTML (with no CGI prolog) for the fill-in-the-blanks form associated with the nth lib in the Libset. A normal CGI script will not have to use this (use getCgiPage() instead), but here it is anyway.


$input_result_html = $object->getResultPage($n,$arrayref)

returns the HTML (with no CGI prolog) for the result of filling in the nth lib in the Libset with the words in the given (referenced) array, in the obvious order. A normal CGI script will not have to use this (use getCgiPage() instead), but here it is anyway.


Tailoring the generated HTML

The HTML pages generated by the Weblibs module are generated by an absurdly flexible process of recursive expansion. For instance, the menu page is generated by expanding the symbol ``&menu_page;'', whose default value is

  &menu_prolog;
  &menu_form;
  &menu_epilog;

The default expansion of &menu_prolog; is in turn

  <html><head><title>&menutitle;</title></head>
  <body &backattrib; text=&textcolor; bgcolor=&bgcolor;>

  <h1>&menutitle;</h1>

  &menu_intro_text;

and so on and so on. See the code for the ``new'' method for the default expansions of most of the symbols.

There are a few special cases: for instance, ``&menu_lines;'' is always expanded by expanding the symbol ``&menu_line;'' once for each available lib, ``&input_lines;'' is always expanded by expanding the symbol ``&input_line;'' once for each to-be-filled-in blank in the active lib, ``&backattrib;'' is expanded to ``background=&background;'' if the symbol ``&background;'' is set, and to null otherwise. See the internal _dosub() method for the other exceptions if you're wildly curious.

To change how a symbol (except the special cases) is expanded, simply alter the corresponding instance variable before calling one of the getXxxPage() methods. See the SYNOPSIS for a few simple examples; experiment if you want to figure out more complex ones.