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