man CGI::FormBuilder::Util () - Utility functions for FormBuilder

NAME

CGI::FormBuilder::Util - Utility functions for FormBuilder

SYNOPSIS

    use CGI::FormBuilder::Util;

    belch "Badness";
    puke "Egads";
    debug 2, "Debug message for level 2";

DESCRIPTION

This module exports some common utility functions for FormBuilder. These functions are intended for internal use, however I must admit that, from time to time, I just import this module and use some of the routines directly (like CWhtmltag() to generate HTML).

USEFUL FUNCTIONS

These can be used directly and are somewhat useful. Don't tell anyone I said that, though. This prints out the given string only if CW$DEBUG is greater than the CW$level specified. For example:

    $CGI::FormBuilder::Util::DEBUG = 1;
    debug 1, "this is printed";
    debug 2, "but not this one";

A newline is automatically included, so don't provide one of your own.

belch($string)

A modified CWwarn that prints out a better message with a newline added.

puke($string)

A modified CWdie that prints out a useful message.

escapeurl($string)

Returns a properly escaped string suitable for including in URL params.

escapehtml($string)

Returns an HTML-escaped string suitable for embedding in HTML tags. This dispatches to CWHTML::Entities::encode() if available.

escapejs($string)

Returns a string suitable for including in JavaScript. Minimal processing. This generates an XHTML-compliant tag for the name CW$name based on the CW%attr specified. For example:

    my $table = htmltag('table', cellpadding => 1, border => 0);

No routines are provided to close tags; you must manually print a closing CW</table> tag. This cleans any internal FormBuilder attributes from the specified tag. It is automatically called by CWhtmltag().

toname($string)

This is responsible for the auto-naming functionality of FormBuilder. Since you know Perl, it's easiest to just show what it does:

    $name =~ s!\.\w+$!!;                # lose trailing ".suf"
    $name =~ s![^a-zA-Z0-9.-/]+! !g;    # strip non-alpha chars
    $name =~ s!\b(\w)!\u$1!g;           # convert _ to space/upper

This results in something like cgi_script.pl becoming Cgi Script.

tovar($string)

Turns a string into a variable name. Basically just strips CW\W, and prefixes fb_ on the front of it. Returns true if CW$el is in CW@array

USELESS FUNCTIONS

These are totally useless outside of FormBuilder internals.

autodata($ref)

This dereferences CW$ref and returns the underlying data. For example:

    %hash  = autodata($hashref);
    @array = autodata($arrayref);

cleanargs(@_)

This returns a hash of options passed into a sub:

    sub field {
        my $self = shift;
        my %opt  = cleanargs(@_);
    }

It does some minor sanity checks as well.

    # strip off any leading '-opt' crap
    my @args;
    while (@_) {
        (my $k = shift) =~ s/^-//;
        push @args, $k, shift;
    }

indent($num)

A simple sub that returns 4 spaces x CW$num. Used to indent code.

optalign(\@opt)

This returns the options specified as an array of arrayrefs, which is what FormBuilder expects internally. This sorts and returns the options based on CW$sortref. It expects CW@opt to be in the format returned by CWoptalign(). The CW$sortref spec can be the string CWNAME, CWNUM, or a reference to a CW&sub which takes pairs of values to compare.

optval($opt)

This takes one of the elements of CW@opt and returns it split up. Useless outside of FormBuilder.

basename

Returns the script name or CW$0 hacked up to the first dir

SEE ALSO

CGI::FormBuilder

REVISION

$Id: Util.pm,v 1.26 2005/04/06 18:46:32 nwiger Exp $

AUTHOR

Copyright (c) 2000-2005 Nathan Wiger <nate@sun.com>. All Rights Reserved.

This module is free software; you may copy this under the terms of the GNU General Public License, or the Artistic License, copies of which should have accompanied your Perl kit.