man CGI::FormBuilder::Source () - Source adapters for FormBuilder

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 CWsource option to the top-level CWnew() method:

    my $form = CGI::FormBuilder->new(
                    source => 'source_file.conf'
               );

This example points to a filename that contains a file following the CWCGI::FormBuilder::Source::File layout. Like with the CWtemplate option, you can also specify CWsource 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 CWtype 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 CWnew() and CWparse() 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 CWtype 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,v 1.1 2005/03/11 19:39:56 nwiger Exp $

AUTHOR

Copyright (c) 2000-2005 Nathan Wiger <nate@sun.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.