Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

cgi::formbuilder::source(3pm) [debian man page]

CGI::FormBuilder::Source(3pm)				User Contributed Perl Documentation			     CGI::FormBuilder::Source(3pm)

NAME
CGI::FormBuilder::Source - Source adapters for FormBuilder SYNOPSIS
# Define a source adapter package CGI::FormBuilder::Source::Whatever; sub new { my $self = shift; my $class = ref($self) || $self; my %opt = @_; return bless \%opt, $class; } sub parse { my $self = shift; my $file = shift || $self->{source}; # open the file and parse it, or whatever my %formopt; open(F, "<$file") || die "Can't read $file: $!"; while (<F>) { # ... do stuff to the line ... $formopt{$fb_option} = $fb_value; } # return hash of $form options return wantarray ? %formopt : \%formopt; } DESCRIPTION
This documentation describes the usage of FormBuilder sources, as well as how to write your own source adapter. An external source is invoked by using the "source" option to the top-level "new()" method: my $form = CGI::FormBuilder->new( source => 'source_file.conf' ); This example points to a filename that contains a file following the "CGI::FormBuilder::Source::File" layout. Like with the "template" option, you can also specify "source" as a reference to a hash, allowing you to use other source adapters: my $form = CGI::FormBuilder->new( fields => @fields, source => { type => 'File', source => '/path/to/source.conf', } ); The "type" option specifies the name of the source adapter. Currently accepted types are: File - CGI::FormBuilder::Source::File In addition to one of these types, you can also specify a complete package name, in which case that module will be autoloaded and its "new()" and "parse()" routines used. For example: my $form = CGI::FormBuilder->new( fields => @fields, source => { type => 'My::Source::Module', somefile => '/path/to/source.conf', } ); All other options besides "type" are passed to the constructor for that source module verbatim, so it's up to you and/or the source module on how these additional options should be handled. SEE ALSO
CGI::FormBuilder, CGI::FormBuilder::Source::File, REVISION
$Id: Source.pm 100 2007-03-02 18:13:13Z nwiger $ AUTHOR
Copyright (c) Nate Wiger <http://nateware.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. perl v5.14.2 2011-09-16 CGI::FormBuilder::Source(3pm)

Check Out this Related Man Page

CGI::FormBuilder::Util(3pm)				User Contributed Perl Documentation			       CGI::FormBuilder::Util(3pm)

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 "htmltag()" to generate HTML). USEFUL FUNCTIONS
These can be used directly and are somewhat useful. Don't tell anyone I said that, though. debug($level, $string) This prints out the given string only if $DEBUG is greater than the $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 "warn" that prints out a better message with a newline added. puke($string) A modified "die" 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. escapejs($string) Returns a string suitable for including in JavaScript. Minimal processing. htmltag($name, %attr) This generates an XHTML-compliant tag for the name $name based on the %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 "</table>" tag. htmlattr($name, %attr) This cleans any internal FormBuilder attributes from the specified tag. It is automatically called by "htmltag()". 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!(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 "W", and prefixes "fb_" on the front of it. ismember($el, @array) Returns true if $el is in @array USELESS FUNCTIONS
These are totally useless outside of FormBuilder internals. autodata($ref) This dereferences $ref and returns the underlying data. For example: %hash = autodata($hashref); @array = autodata($arrayref); arghash(@_) This returns a hash of options passed into a sub: sub field { my $self = shift; my %opt = arghash(@_); } It will return a hashref in scalar context. arglist(@_) This returns a list of args passed into a sub: sub value { my $self = shift; $self->{value} = arglist(@_); It will return an arrayref in scalar context. indent($num) A simple sub that returns 4 spaces x $num. Used to indent code. optalign(@opt) This returns the options specified as an array of arrayrefs, which is what FormBuilder expects internally. optsort($sortref, @opt) This sorts and returns the options based on $sortref. It expects @opt to be in the format returned by "optalign()". The $sortref spec can be the string "NAME", "NUM", or a reference to a &sub which takes pairs of values to compare. optval($opt) This takes one of the elements of @opt and returns it split up. Useless outside of FormBuilder. rearrange($ref, $name) Rearranges arguments designed to be per-field from the global inheritor. basename Returns the script name or $0 hacked up to the first dir SEE ALSO
CGI::FormBuilder REVISION
$Id: Util.pm 100 2007-03-02 18:13:13Z nwiger $ AUTHOR
Copyright (c) Nate Wiger <http://nateware.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. perl v5.14.2 2011-09-16 CGI::FormBuilder::Util(3pm)
Man Page