1CGI::FormBuilder::SourcUes(e3r)Contributed Perl DocumentCaGtIi:o:nFormBuilder::Source(3)
2
3
4

NAME

6       CGI::FormBuilder::Source - Source adapters for FormBuilder
7

SYNOPSIS

9           # Define a source adapter
10
11           package CGI::FormBuilder::Source::Whatever;
12
13           sub new {
14               my $self  = shift;
15               my $class = ref($self) || $self;
16               my %opt   = @_;
17               return bless \%opt, $class;
18           }
19
20           sub parse {
21               my $self = shift;
22               my $file = shift || $self->{source};
23
24               # open the file and parse it, or whatever
25               my %formopt;
26               open(F, "<$file") || die "Can't read $file: $!";
27               while (<F>) {
28                   # ... do stuff to the line ...
29                   $formopt{$fb_option} = $fb_value;
30               }
31
32               # return hash of $form options
33               return wantarray ? %formopt : \%formopt;
34           }
35

DESCRIPTION

37       This documentation describes the usage of FormBuilder sources, as well
38       as how to write your own source adapter.
39
40       An external source is invoked by using the "source" option to the top-
41       level "new()" method:
42
43           my $form = CGI::FormBuilder->new(
44                           source => 'source_file.conf'
45                      );
46
47       This example points to a filename that contains a file following the
48       "CGI::FormBuilder::Source::File" layout. Like with the "template"
49       option, you can also specify "source" as a reference to a hash,
50       allowing you to use other source adapters:
51
52           my $form = CGI::FormBuilder->new(
53                           fields => \@fields,
54                           source => {
55                               type => 'File',
56                               source => '/path/to/source.conf',
57                           }
58                      );
59
60       The "type" option specifies the name of the source adapter. Currently
61       accepted types are:
62
63           File  -  CGI::FormBuilder::Source::File
64
65       In addition to one of these types, you can also specify a complete
66       package name, in which case that module will be autoloaded and its
67       "new()" and "parse()" routines used. For example:
68
69           my $form = CGI::FormBuilder->new(
70                           fields => \@fields,
71                           source => {
72                               type => 'My::Source::Module',
73                               somefile => '/path/to/source.conf',
74                           }
75                      );
76
77       All other options besides "type" are passed to the constructor for that
78       source module verbatim, so it's up to you and/or the source module on
79       how these additional options should be handled.
80

SEE ALSO

82       CGI::FormBuilder, CGI::FormBuilder::Source::File,
83

REVISION

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

AUTHOR

88       Copyright (c) Nate Wiger <http://nateware.com>. All Rights Reserved.
89
90       This module is free software; you may copy this under the terms of the
91       GNU General Public License, or the Artistic License, copies of which
92       should have accompanied your Perl kit.
93
94
95
96perl v5.34.0                      2022-01-20       CGI::FormBuilder::Source(3)
Impressum