.\" -*- 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::Source 3" .TH CGI::FormBuilder::Source 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::Source \- Source adapters for FormBuilder .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& # Define a source adapter \& \& package CGI::FormBuilder::Source::Whatever; \& \& sub new { \& my $self = shift; \& my $class = ref($self) || $self; \& my %opt = @_; \& return bless \e%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\*(Aqt read $file: $!"; \& while () { \& # ... do stuff to the line ... \& $formopt{$fb_option} = $fb_value; \& } \& \& # return hash of $form options \& return wantarray ? %formopt : \e%formopt; \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This documentation describes the usage of \fBFormBuilder\fR sources, as well as how to write your own source adapter. .PP An external source is invoked by using the \f(CW\*(C`source\*(C'\fR option to the top-level \f(CWnew()\fR method: .PP .Vb 3 \& my $form = CGI::FormBuilder\->new( \& source => \*(Aqsource_file.conf\*(Aq \& ); .Ve .PP This example points to a filename that contains a file following the \f(CW\*(C`CGI::FormBuilder::Source::File\*(C'\fR layout. Like with the \f(CW\*(C`template\*(C'\fR option, you can also specify \f(CW\*(C`source\*(C'\fR as a reference to a hash, allowing you to use other source adapters: .PP .Vb 7 \& my $form = CGI::FormBuilder\->new( \& fields => \e@fields, \& source => { \& type => \*(AqFile\*(Aq, \& source => \*(Aq/path/to/source.conf\*(Aq, \& } \& ); .Ve .PP The \f(CW\*(C`type\*(C'\fR option specifies the name of the source adapter. Currently accepted types are: .PP .Vb 1 \& File \- CGI::FormBuilder::Source::File .Ve .PP 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 \f(CWnew()\fR and \f(CWparse()\fR routines used. For example: .PP .Vb 7 \& my $form = CGI::FormBuilder\->new( \& fields => \e@fields, \& source => { \& type => \*(AqMy::Source::Module\*(Aq, \& somefile => \*(Aq/path/to/source.conf\*(Aq, \& } \& ); .Ve .PP All other options besides \f(CW\*(C`type\*(C'\fR 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. .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::FormBuilder, CGI::FormBuilder::Source::File, .SH REVISION .IX Header "REVISION" \&\f(CW$Id:\fR Source.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.