1CGI::FormBuilder::Util(U3s)er Contributed Perl DocumentatCiGoIn::FormBuilder::Util(3)
2
3
4
6 CGI::FormBuilder::Util - Utility functions for FormBuilder
7
9 use CGI::FormBuilder::Util;
10
11 belch "Badness";
12 puke "Egads";
13 debug 2, "Debug message for level 2";
14
16 This module exports some common utility functions for FormBuilder.
17 These functions are intended for internal use, however I must admit
18 that, from time to time, I just import this module and use some of the
19 routines directly (like "htmltag()" to generate HTML).
20
22 These can be used directly and are somewhat useful. Don't tell anyone I
23 said that, though.
24
25 debug($level, $string)
26 This prints out the given string only if $DEBUG is greater than the
27 $level specified. For example:
28
29 $CGI::FormBuilder::Util::DEBUG = 1;
30 debug 1, "this is printed";
31 debug 2, "but not this one";
32
33 A newline is automatically included, so don't provide one of your own.
34
35 belch($string)
36 A modified "warn" that prints out a better message with a newline
37 added.
38
39 puke($string)
40 A modified "die" that prints out a useful message.
41
42 escapeurl($string)
43 Returns a properly escaped string suitable for including in URL params.
44
45 escapehtml($string)
46 Returns an HTML-escaped string suitable for embedding in HTML tags.
47
48 escapejs($string)
49 Returns a string suitable for including in JavaScript. Minimal
50 processing.
51
52 htmltag($name, %attr)
53 This generates an XHTML-compliant tag for the name $name based on the
54 %attr specified. For example:
55
56 my $table = htmltag('table', cellpadding => 1, border => 0);
57
58 No routines are provided to close tags; you must manually print a
59 closing "</table>" tag.
60
61 htmlattr($name, %attr)
62 This cleans any internal FormBuilder attributes from the specified tag.
63 It is automatically called by "htmltag()".
64
65 toname($string)
66 This is responsible for the auto-naming functionality of FormBuilder.
67 Since you know Perl, it's easiest to just show what it does:
68
69 $name =~ s!\.\w+$!!; # lose trailing ".suf"
70 $name =~ s![^a-zA-Z0-9.-/]+! !g; # strip non-alpha chars
71 $name =~ s!\b(\w)!\u$1!g; # convert _ to space/upper
72
73 This results in something like "cgi_script.pl" becoming "Cgi Script".
74
75 tovar($string)
76 Turns a string into a variable name. Basically just strips "\W", and
77 prefixes "fb_" on the front of it.
78
79 ismember($el, @array)
80 Returns true if $el is in @array
81
83 These are totally useless outside of FormBuilder internals.
84
85 autodata($ref)
86 This dereferences $ref and returns the underlying data. For example:
87
88 %hash = autodata($hashref);
89 @array = autodata($arrayref);
90
91 arghash(@_)
92 This returns a hash of options passed into a sub:
93
94 sub field {
95 my $self = shift;
96 my %opt = arghash(@_);
97 }
98
99 It will return a hashref in scalar context.
100
101 arglist(@_)
102 This returns a list of args passed into a sub:
103
104 sub value {
105 my $self = shift;
106 $self->{value} = arglist(@_);
107
108 It will return an arrayref in scalar context.
109
110 indent($num)
111 A simple sub that returns 4 spaces x $num. Used to indent code.
112
113 optalign(\@opt)
114 This returns the options specified as an array of arrayrefs, which is
115 what FormBuilder expects internally.
116
117 optsort($sortref, @opt)
118 This sorts and returns the options based on $sortref. It expects @opt
119 to be in the format returned by "optalign()". The $sortref spec can be
120 the string "NAME", "NUM", or a reference to a &sub which takes pairs of
121 values to compare.
122
123 optval($opt)
124 This takes one of the elements of @opt and returns it split up.
125 Useless outside of FormBuilder.
126
127 rearrange($ref, $name)
128 Rearranges arguments designed to be per-field from the global
129 inheritor.
130
131 basename
132 Returns the script name or $0 hacked up to the first dir
133
135 CGI::FormBuilder
136
138 $Id: Util.pm 100 2007-03-02 18:13:13Z nwiger $
139
141 Copyright (c) Nate Wiger <http://nateware.com>. All Rights Reserved.
142
143 This module is free software; you may copy this under the terms of the
144 GNU General Public License, or the Artistic License, copies of which
145 should have accompanied your Perl kit.
146
147
148
149perl v5.32.1 2021-01-26 CGI::FormBuilder::Util(3)