CGI::Fo...:Source(3)
π NAME π
okay bestie, this is the CGI::FormBuilder::Source(3) page β manual name folded in right here like a lil name tag β and it's all about source adapters for FormBuilder. π«Ά
β¨ SYNOPSIS β¨
Here's the blueprint for defining a source adapter β code stays exactly as-is, no cap:
# 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 page spills the tea on how FormBuilder sources work and how you can write your own source adapter. π
An external source gets invoked by using the source option on the top-level new() method:
my $form = CGI::FormBuilder->new(
source => 'source_file.conf'
);
That example points at a filename containing a file that follows the CGI::FormBuilder::Source::File layout. And just like with the template option, you can also pass source as a reference to a hash, which lets you use other source adapters:
my $form = CGI::FormBuilder->new(
fields => \@fields,
source => {
type => 'File',
source => '/path/to/source.conf',
}
);
The type option tells FormBuilder the name of the source adapter. Currently accepted types are:
FileβCGI::FormBuilder::Source::File
In addition to one of those types, you can also specify a complete package name β in that case the module gets autoloaded and its new() and parse() routines are 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 that source module's constructor verbatim, so it's up to you and/or the source module how those extra options get handled. π¦
π¦ SEE ALSO π¦
The refs are exactly:
CGI::FormBuilder, CGI::FormBuilder::Source::File,
(yes, that trailing comma is canon, bestie π)
π 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.
That's the whole page, bestie! This lil icon came from perl v5.42.2, dated 2024-09-19, and the manual name is CGI::Fo...:Source(3) β terminal truncation and all. Mwah! ππ
π¦ where this page comes from
- alpine 3.24: perl-cgi-formbuilder-doc 3.20-r0 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms