.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "CGI::FormBuilder::Util 3" .TH CGI::FormBuilder::Util 3 2023-07-25 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME CGI::FormBuilder::Util \- Utility functions for FormBuilder .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use CGI::FormBuilder::Util; \& \& belch "Badness"; \& puke "Egads"; \& debug 2, "Debug message for level 2"; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module exports some common utility functions for \fBFormBuilder\fR. 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 \f(CWhtmltag()\fR to generate HTML). .SH "USEFUL FUNCTIONS" .IX Header "USEFUL FUNCTIONS" These can be used directly and are somewhat useful. Don't tell anyone I said that, though. .ie n .SS "debug($level, $string)" .el .SS "debug($level, \f(CW$string\fP)" .IX Subsection "debug($level, $string)" This prints out the given string only if \f(CW$DEBUG\fR is greater than the \f(CW$level\fR specified. For example: .PP .Vb 3 \& $CGI::FormBuilder::Util::DEBUG = 1; \& debug 1, "this is printed"; \& debug 2, "but not this one"; .Ve .PP A newline is automatically included, so don't provide one of your own. .SS belch($string) .IX Subsection "belch($string)" A modified \f(CW\*(C`warn\*(C'\fR that prints out a better message with a newline added. .SS puke($string) .IX Subsection "puke($string)" A modified \f(CW\*(C`die\*(C'\fR that prints out a useful message. .SS escapeurl($string) .IX Subsection "escapeurl($string)" Returns a properly escaped string suitable for including in URL params. .SS escapehtml($string) .IX Subsection "escapehtml($string)" Returns an HTML-escaped string suitable for embedding in HTML tags. .SS escapejs($string) .IX Subsection "escapejs($string)" Returns a string suitable for including in JavaScript. Minimal processing. .ie n .SS "htmltag($name, %attr)" .el .SS "htmltag($name, \f(CW%attr\fP)" .IX Subsection "htmltag($name, %attr)" This generates an XHTML-compliant tag for the name \f(CW$name\fR based on the \&\f(CW%attr\fR specified. For example: .PP .Vb 1 \& my $table = htmltag(\*(Aqtable\*(Aq, cellpadding => 1, border => 0); .Ve .PP No routines are provided to close tags; you must manually print a closing \&\f(CW\*(C`\*(C'\fR tag. .ie n .SS "htmlattr($name, %attr)" .el .SS "htmlattr($name, \f(CW%attr\fP)" .IX Subsection "htmlattr($name, %attr)" This cleans any internal \fBFormBuilder\fR attributes from the specified tag. It is automatically called by \f(CWhtmltag()\fR. .SS toname($string) .IX Subsection "toname($string)" This is responsible for the auto-naming functionality of \fBFormBuilder\fR. Since you know Perl, it's easiest to just show what it does: .PP .Vb 3 \& $name =~ s!\e.\ew+$!!; # lose trailing ".suf" \& $name =~ s![^a\-zA\-Z0\-9.\-/]+! !g; # strip non\-alpha chars \& $name =~ s!\eb(\ew)!\eu$1!g; # convert _ to space/upper .Ve .PP This results in something like "cgi_script.pl" becoming "Cgi Script". .SS tovar($string) .IX Subsection "tovar($string)" Turns a string into a variable name. Basically just strips \f(CW\*(C`\eW\*(C'\fR, and prefixes "fb_" on the front of it. .ie n .SS "ismember($el, @array)" .el .SS "ismember($el, \f(CW@array\fP)" .IX Subsection "ismember($el, @array)" Returns true if \f(CW$el\fR is in \f(CW@array\fR .SH "USELESS FUNCTIONS" .IX Header "USELESS FUNCTIONS" These are totally useless outside of \fBFormBuilder\fR internals. .SS autodata($ref) .IX Subsection "autodata($ref)" This dereferences \f(CW$ref\fR and returns the underlying data. For example: .PP .Vb 2 \& %hash = autodata($hashref); \& @array = autodata($arrayref); .Ve .SS arghash(@_) .IX Subsection "arghash(@_)" This returns a hash of options passed into a sub: .PP .Vb 4 \& sub field { \& my $self = shift; \& my %opt = arghash(@_); \& } .Ve .PP It will return a hashref in scalar context. .SS arglist(@_) .IX Subsection "arglist(@_)" This returns a list of args passed into a sub: .PP .Vb 3 \& sub value { \& my $self = shift; \& $self\->{value} = arglist(@_); .Ve .PP It will return an arrayref in scalar context. .SS indent($num) .IX Subsection "indent($num)" A simple sub that returns 4 spaces x \f(CW$num\fR. Used to indent code. .SS optalign(\e@opt) .IX Subsection "optalign(@opt)" This returns the options specified as an array of arrayrefs, which is what \fBFormBuilder\fR expects internally. .ie n .SS "optsort($sortref, @opt)" .el .SS "optsort($sortref, \f(CW@opt\fP)" .IX Subsection "optsort($sortref, @opt)" This sorts and returns the options based on \f(CW$sortref\fR. It expects \&\f(CW@opt\fR to be in the format returned by \f(CWoptalign()\fR. The \f(CW$sortref\fR spec can be the string \f(CW\*(C`NAME\*(C'\fR, \f(CW\*(C`NUM\*(C'\fR, or a reference to a \f(CW&sub\fR which takes pairs of values to compare. .SS optval($opt) .IX Subsection "optval($opt)" This takes one of the elements of \f(CW@opt\fR and returns it split up. Useless outside of \fBFormBuilder\fR. .ie n .SS "rearrange($ref, $name)" .el .SS "rearrange($ref, \f(CW$name\fP)" .IX Subsection "rearrange($ref, $name)" Rearranges arguments designed to be per-field from the global inheritor. .SS basename .IX Subsection "basename" Returns the script name or \f(CW$0\fR hacked up to the first dir .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::FormBuilder .SH REVISION .IX Header "REVISION" \&\f(CW$Id:\fR Util.pm 100 2007\-03\-02 18:13:13Z nwiger $ .SH AUTHOR .IX Header "AUTHOR" Copyright (c) Nate Wiger . All Rights Reserved. .PP 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.