GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
CGI::FormBuilder::Source(3) User Contributed Perl Documentation CGI::FormBuilder::Source(3)

CGI::FormBuilder::Source - Source adapters for FormBuilder

    # 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;
    }

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.

CGI::FormBuilder, CGI::FormBuilder::Source::File,

$Id: Source.pm 100 2007-03-02 18:13:13Z nwiger $

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.

2016-08-16 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.