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